@@ -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 | * This is the main function for the languages area. |
@@ -150,11 +151,11 @@ discard block |
||
150 | 151 | $language_list = new xmlArray(fetch_web_data($url), true); |
151 | 152 | |
152 | 153 | // Check that the site responded and that the language exists. |
153 | - if (!$language_list->exists('languages')) |
|
154 | - $context['smf_error'] = 'no_response'; |
|
155 | - elseif (!$language_list->exists('languages/language')) |
|
156 | - $context['smf_error'] = 'no_files'; |
|
157 | - else |
|
154 | + if (!$language_list->exists('languages')) { |
|
155 | + $context['smf_error'] = 'no_response'; |
|
156 | + } elseif (!$language_list->exists('languages/language')) { |
|
157 | + $context['smf_error'] = 'no_files'; |
|
158 | + } else |
|
158 | 159 | { |
159 | 160 | $language_list = $language_list->path('languages[0]'); |
160 | 161 | $lang_files = $language_list->set('language'); |
@@ -162,8 +163,9 @@ discard block |
||
162 | 163 | foreach ($lang_files as $file) |
163 | 164 | { |
164 | 165 | // Were we searching? |
165 | - if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) |
|
166 | - continue; |
|
166 | + if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) { |
|
167 | + continue; |
|
168 | + } |
|
167 | 169 | |
168 | 170 | $smf_languages[] = array( |
169 | 171 | 'id' => $file->fetch('id'), |
@@ -174,10 +176,11 @@ discard block |
||
174 | 176 | 'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>', |
175 | 177 | ); |
176 | 178 | } |
177 | - if (empty($smf_languages)) |
|
178 | - $context['smf_error'] = 'no_files'; |
|
179 | - else |
|
180 | - return $smf_languages; |
|
179 | + if (empty($smf_languages)) { |
|
180 | + $context['smf_error'] = 'no_files'; |
|
181 | + } else { |
|
182 | + return $smf_languages; |
|
183 | + } |
|
181 | 184 | } |
182 | 185 | } |
183 | 186 | |
@@ -199,8 +202,9 @@ discard block |
||
199 | 202 | require_once($sourcedir . '/Subs-Package.php'); |
200 | 203 | |
201 | 204 | // Clearly we need to know what to request. |
202 | - if (!isset($_GET['did'])) |
|
203 | - fatal_lang_error('no_access', false); |
|
205 | + if (!isset($_GET['did'])) { |
|
206 | + fatal_lang_error('no_access', false); |
|
207 | + } |
|
204 | 208 | |
205 | 209 | // Some lovely context. |
206 | 210 | $context['download_id'] = $_GET['did']; |
@@ -220,8 +224,9 @@ discard block |
||
220 | 224 | foreach ($_POST['copy_file'] as $file) |
221 | 225 | { |
222 | 226 | // Check it's not very bad. |
223 | - if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) |
|
224 | - fatal_error($txt['languages_download_illegal_paths']); |
|
227 | + if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) { |
|
228 | + fatal_error($txt['languages_download_illegal_paths']); |
|
229 | + } |
|
225 | 230 | |
226 | 231 | $chmod_files[] = $boarddir . '/' . $file; |
227 | 232 | $install_files[] = $file; |
@@ -232,8 +237,9 @@ discard block |
||
232 | 237 | $files_left = $file_status['files']['notwritable']; |
233 | 238 | |
234 | 239 | // Something not writable? |
235 | - if (!empty($files_left)) |
|
236 | - $context['error_message'] = $txt['languages_download_not_chmod']; |
|
240 | + if (!empty($files_left)) { |
|
241 | + $context['error_message'] = $txt['languages_download_not_chmod']; |
|
242 | + } |
|
237 | 243 | // Otherwise, go go go! |
238 | 244 | elseif (!empty($install_files)) |
239 | 245 | { |
@@ -248,11 +254,13 @@ discard block |
||
248 | 254 | } |
249 | 255 | |
250 | 256 | // Open up the old china. |
251 | - if (!isset($archive_content)) |
|
252 | - $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
257 | + if (!isset($archive_content)) { |
|
258 | + $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
259 | + } |
|
253 | 260 | |
254 | - if (empty($archive_content)) |
|
255 | - fatal_error($txt['add_language_error_no_response']); |
|
261 | + if (empty($archive_content)) { |
|
262 | + fatal_error($txt['add_language_error_no_response']); |
|
263 | + } |
|
256 | 264 | |
257 | 265 | // Now for each of the files, let's do some *stuff* |
258 | 266 | $context['files'] = array( |
@@ -267,8 +275,9 @@ discard block |
||
267 | 275 | $extension = substr($filename, strrpos($filename, '.') + 1); |
268 | 276 | |
269 | 277 | // Don't do anything with files we don't understand. |
270 | - if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) |
|
271 | - continue; |
|
278 | + if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) { |
|
279 | + continue; |
|
280 | + } |
|
272 | 281 | |
273 | 282 | // Basic data. |
274 | 283 | $context_data = array( |
@@ -287,8 +296,9 @@ discard block |
||
287 | 296 | // Does the file exist, is it different and can we overwrite? |
288 | 297 | if (file_exists($boarddir . '/' . $file['filename'])) |
289 | 298 | { |
290 | - if (is_writable($boarddir . '/' . $file['filename'])) |
|
291 | - $context_data['writable'] = true; |
|
299 | + if (is_writable($boarddir . '/' . $file['filename'])) { |
|
300 | + $context_data['writable'] = true; |
|
301 | + } |
|
292 | 302 | |
293 | 303 | // Finally, do we actually think the content has changed? |
294 | 304 | if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) |
@@ -301,16 +311,17 @@ discard block |
||
301 | 311 | { |
302 | 312 | $context_data['exists'] = 'same'; |
303 | 313 | $context_data['default_copy'] = false; |
314 | + } else { |
|
315 | + $context_data['exists'] = 'different'; |
|
304 | 316 | } |
305 | - else |
|
306 | - $context_data['exists'] = 'different'; |
|
307 | 317 | } |
308 | 318 | // No overwrite? |
309 | 319 | else |
310 | 320 | { |
311 | 321 | // Can we at least stick it in the directory... |
312 | - if (is_writable($boarddir . '/' . $dirname)) |
|
313 | - $context_data['writable'] = true; |
|
322 | + if (is_writable($boarddir . '/' . $dirname)) { |
|
323 | + $context_data['writable'] = true; |
|
324 | + } |
|
314 | 325 | } |
315 | 326 | |
316 | 327 | // I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin... |
@@ -325,8 +336,9 @@ discard block |
||
325 | 336 | list ($name, $language) = explode('.', $filename); |
326 | 337 | |
327 | 338 | // Let's get the new version, I like versions, they tell me that I'm up to date. |
328 | - if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) |
|
329 | - $context_data['version'] = $match[1]; |
|
339 | + if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) { |
|
340 | + $context_data['version'] = $match[1]; |
|
341 | + } |
|
330 | 342 | |
331 | 343 | // Now does the old file exist - if so what is it's version? |
332 | 344 | if (file_exists($boarddir . '/' . $file['filename'])) |
@@ -342,34 +354,35 @@ discard block |
||
342 | 354 | $context_data['cur_version'] = $match[1]; |
343 | 355 | |
344 | 356 | // How does this compare? |
345 | - if ($context_data['cur_version'] == $context_data['version']) |
|
346 | - $context_data['version_compare'] = 'same'; |
|
347 | - elseif ($context_data['cur_version'] > $context_data['version']) |
|
348 | - $context_data['version_compare'] = 'older'; |
|
357 | + if ($context_data['cur_version'] == $context_data['version']) { |
|
358 | + $context_data['version_compare'] = 'same'; |
|
359 | + } elseif ($context_data['cur_version'] > $context_data['version']) { |
|
360 | + $context_data['version_compare'] = 'older'; |
|
361 | + } |
|
349 | 362 | |
350 | 363 | // Don't recommend copying if the version is the same. |
351 | - if ($context_data['version_compare'] != 'newer') |
|
352 | - $context_data['default_copy'] = false; |
|
364 | + if ($context_data['version_compare'] != 'newer') { |
|
365 | + $context_data['default_copy'] = false; |
|
366 | + } |
|
353 | 367 | } |
354 | 368 | } |
355 | 369 | |
356 | 370 | // Add the context data to the main set. |
357 | 371 | $context['files']['lang'][] = $context_data; |
358 | - } |
|
359 | - elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
372 | + } elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
360 | 373 | { |
361 | 374 | // Registration agreement is a primary file |
362 | 375 | $context['files']['lang'][] = $context_data; |
363 | - } |
|
364 | - else |
|
376 | + } else |
|
365 | 377 | { |
366 | 378 | // There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future |
367 | 379 | $context['files']['other'][] = $context_data; |
368 | 380 | } |
369 | 381 | |
370 | 382 | // Collect together all non-writable areas. |
371 | - if (!$context_data['writable']) |
|
372 | - $context['make_writable'][] = $context_data['destination']; |
|
383 | + if (!$context_data['writable']) { |
|
384 | + $context['make_writable'][] = $context_data['destination']; |
|
385 | + } |
|
373 | 386 | } |
374 | 387 | |
375 | 388 | // Before we go to far can we make anything writable, eh, eh? |
@@ -384,22 +397,24 @@ discard block |
||
384 | 397 | { |
385 | 398 | if ($type == 'lang') |
386 | 399 | { |
387 | - foreach ($data as $k => $file) |
|
388 | - if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
400 | + foreach ($data as $k => $file) { |
|
401 | + if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
389 | 402 | $context['files'][$type][$k]['writable'] = true; |
390 | - } |
|
391 | - else |
|
403 | + } |
|
404 | + } else |
|
392 | 405 | { |
393 | - foreach ($data as $theme => $files) |
|
394 | - foreach ($files as $k => $file) |
|
406 | + foreach ($data as $theme => $files) { |
|
407 | + foreach ($files as $k => $file) |
|
395 | 408 | if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
396 | 409 | $context['files'][$type][$theme][$k]['writable'] = true; |
410 | + } |
|
397 | 411 | } |
398 | 412 | } |
399 | 413 | |
400 | 414 | // Are we going to need more language stuff? |
401 | - if (!empty($context['still_not_writable'])) |
|
402 | - loadLanguage('Packages'); |
|
415 | + if (!empty($context['still_not_writable'])) { |
|
416 | + loadLanguage('Packages'); |
|
417 | + } |
|
403 | 418 | } |
404 | 419 | |
405 | 420 | // This is the list for the main files. |
@@ -612,12 +627,13 @@ discard block |
||
612 | 627 | highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true); |
613 | 628 | |
614 | 629 | // Display a warning if we cannot edit the default setting. |
615 | - if (!is_writable($boarddir . '/Settings.php')) |
|
616 | - $listOptions['additional_rows'][] = array( |
|
630 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
631 | + $listOptions['additional_rows'][] = array( |
|
617 | 632 | 'position' => 'after_title', |
618 | 633 | 'value' => $txt['language_settings_writable'], |
619 | 634 | 'class' => 'smalltext alert', |
620 | 635 | ); |
636 | + } |
|
621 | 637 | |
622 | 638 | require_once($sourcedir . '/Subs-List.php'); |
623 | 639 | createList($listOptions); |
@@ -659,10 +675,11 @@ discard block |
||
659 | 675 | |
660 | 676 | // Put them back. |
661 | 677 | $settings['actual_theme_dir'] = $backup_actual_theme_dir; |
662 | - if (!empty($backup_base_theme_dir)) |
|
663 | - $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
664 | - else |
|
665 | - unset($settings['base_theme_dir']); |
|
678 | + if (!empty($backup_base_theme_dir)) { |
|
679 | + $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
680 | + } else { |
|
681 | + unset($settings['base_theme_dir']); |
|
682 | + } |
|
666 | 683 | |
667 | 684 | // Get the language files and data... |
668 | 685 | foreach ($context['languages'] as $lang) |
@@ -691,13 +708,15 @@ discard block |
||
691 | 708 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
692 | 709 | { |
693 | 710 | // Default? |
694 | - if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) |
|
695 | - $row['lngfile'] = $language; |
|
711 | + if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) { |
|
712 | + $row['lngfile'] = $language; |
|
713 | + } |
|
696 | 714 | |
697 | - if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) |
|
698 | - $languages['english']['count'] += $row['num_users']; |
|
699 | - elseif (isset($languages[$row['lngfile']])) |
|
700 | - $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
715 | + if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) { |
|
716 | + $languages['english']['count'] += $row['num_users']; |
|
717 | + } elseif (isset($languages[$row['lngfile']])) { |
|
718 | + $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
719 | + } |
|
701 | 720 | } |
702 | 721 | $smcFunc['db_free_result']($request); |
703 | 722 | |
@@ -737,13 +756,15 @@ discard block |
||
737 | 756 | |
738 | 757 | call_integration_hook('integrate_language_settings', array(&$config_vars)); |
739 | 758 | |
740 | - if ($return_config) |
|
741 | - return $config_vars; |
|
759 | + if ($return_config) { |
|
760 | + return $config_vars; |
|
761 | + } |
|
742 | 762 | |
743 | 763 | // Get our languages. No cache |
744 | 764 | getLanguages(false); |
745 | - foreach ($context['languages'] as $lang) |
|
746 | - $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
765 | + foreach ($context['languages'] as $lang) { |
|
766 | + $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
767 | + } |
|
747 | 768 | |
748 | 769 | // Saving settings? |
749 | 770 | if (isset($_REQUEST['save'])) |
@@ -753,8 +774,9 @@ discard block |
||
753 | 774 | call_integration_hook('integrate_save_language_settings', array(&$config_vars)); |
754 | 775 | |
755 | 776 | saveSettings($config_vars); |
756 | - if (!$settings_not_writable && !$settings_backup_fail) |
|
757 | - $_SESSION['adm-save'] = true; |
|
777 | + if (!$settings_not_writable && !$settings_backup_fail) { |
|
778 | + $_SESSION['adm-save'] = true; |
|
779 | + } |
|
758 | 780 | redirectexit('action=admin;area=languages;sa=settings'); |
759 | 781 | } |
760 | 782 | |
@@ -763,10 +785,11 @@ discard block |
||
763 | 785 | $context['settings_title'] = $txt['language_settings']; |
764 | 786 | $context['save_disabled'] = $settings_not_writable; |
765 | 787 | |
766 | - if ($settings_not_writable) |
|
767 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
768 | - elseif ($settings_backup_fail) |
|
769 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
788 | + if ($settings_not_writable) { |
|
789 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
790 | + } elseif ($settings_backup_fail) { |
|
791 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
792 | + } |
|
770 | 793 | |
771 | 794 | // Fill the config array. |
772 | 795 | prepareServerSettingsContext($config_vars); |
@@ -813,8 +836,9 @@ discard block |
||
813 | 836 | 'theme_dir' => $settings['default_theme_dir'], |
814 | 837 | ), |
815 | 838 | ); |
816 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
817 | - $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
839 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
840 | + $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
841 | + } |
|
818 | 842 | $smcFunc['db_free_result']($request); |
819 | 843 | |
820 | 844 | // This will be where we look |
@@ -847,14 +871,16 @@ discard block |
||
847 | 871 | // Check we have themes with a path and a name - just in case - and add the path. |
848 | 872 | foreach ($themes as $id => $data) |
849 | 873 | { |
850 | - if (count($data) != 2) |
|
851 | - unset($themes[$id]); |
|
852 | - elseif (is_dir($data['theme_dir'] . '/languages')) |
|
853 | - $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
874 | + if (count($data) != 2) { |
|
875 | + unset($themes[$id]); |
|
876 | + } elseif (is_dir($data['theme_dir'] . '/languages')) { |
|
877 | + $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
878 | + } |
|
854 | 879 | |
855 | 880 | // How about image directories? |
856 | - if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) |
|
857 | - $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
881 | + if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { |
|
882 | + $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
883 | + } |
|
858 | 884 | } |
859 | 885 | |
860 | 886 | $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; |
@@ -868,15 +894,17 @@ discard block |
||
868 | 894 | while ($entry = $dir->read()) |
869 | 895 | { |
870 | 896 | // We're only after the files for this language. |
871 | - if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) |
|
872 | - continue; |
|
897 | + if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) { |
|
898 | + continue; |
|
899 | + } |
|
873 | 900 | |
874 | - if (!isset($context['possible_files'][$theme])) |
|
875 | - $context['possible_files'][$theme] = array( |
|
901 | + if (!isset($context['possible_files'][$theme])) { |
|
902 | + $context['possible_files'][$theme] = array( |
|
876 | 903 | 'id' => $theme, |
877 | 904 | 'name' => $themes[$theme]['name'], |
878 | 905 | 'files' => array(), |
879 | 906 | ); |
907 | + } |
|
880 | 908 | |
881 | 909 | $context['possible_files'][$theme]['files'][] = array( |
882 | 910 | 'id' => $matches[1], |
@@ -905,31 +933,36 @@ discard block |
||
905 | 933 | { |
906 | 934 | $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; |
907 | 935 | $result = package_create_backup('backup_lang_' . $context['lang_id']); |
908 | - if (!$result) |
|
909 | - fatal_lang_error('could_not_language_backup', false); |
|
936 | + if (!$result) { |
|
937 | + fatal_lang_error('could_not_language_backup', false); |
|
938 | + } |
|
910 | 939 | } |
911 | 940 | |
912 | 941 | // Second, loop through the array to remove the files. |
913 | 942 | foreach ($lang_dirs as $curPath) |
914 | 943 | { |
915 | - foreach ($context['possible_files'][1]['files'] as $lang) |
|
916 | - if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
944 | + foreach ($context['possible_files'][1]['files'] as $lang) { |
|
945 | + if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
917 | 946 | unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); |
947 | + } |
|
918 | 948 | |
919 | 949 | // Check for the email template. |
920 | - if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) |
|
921 | - unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
950 | + if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { |
|
951 | + unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
952 | + } |
|
922 | 953 | } |
923 | 954 | |
924 | 955 | // Third, the agreement file. |
925 | - if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) |
|
926 | - unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
956 | + if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { |
|
957 | + unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
958 | + } |
|
927 | 959 | |
928 | 960 | // Fourth, a related images folder, if it exists... |
929 | - if (!empty($images_dirs)) |
|
930 | - foreach ($images_dirs as $curPath) |
|
961 | + if (!empty($images_dirs)) { |
|
962 | + foreach ($images_dirs as $curPath) |
|
931 | 963 | if (is_dir($curPath)) |
932 | 964 | deltree($curPath); |
965 | + } |
|
933 | 966 | |
934 | 967 | // Members can no longer use this language. |
935 | 968 | $smcFunc['db_query']('', ' |
@@ -973,8 +1006,9 @@ discard block |
||
973 | 1006 | |
974 | 1007 | // Build the replacements. old => new |
975 | 1008 | $replace_array = array(); |
976 | - foreach ($primary_settings as $setting => $type) |
|
977 | - $replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';'; |
|
1009 | + foreach ($primary_settings as $setting => $type) { |
|
1010 | + $replace_array['~\$txt\[\'' . $setting . '\'\]\s*=\s*[^\r\n]+~'] = '$txt[\'' . $setting . '\'] = ' . ($type === 'bool' ? (!empty($_POST[$setting]) ? 'true' : 'false') : '\'' . ($setting = 'native_name' ? htmlentities(un_htmlspecialchars($_POST[$setting]), ENT_QUOTES, $context['character_set']) : preg_replace('~[^\w-]~i', '', $_POST[$setting])) . '\'') . ';'; |
|
1011 | + } |
|
978 | 1012 | |
979 | 1013 | $current_data = preg_replace(array_keys($replace_array), array_values($replace_array), $current_data); |
980 | 1014 | $fp = fopen($settings['default_theme_dir'] . '/languages/index.' . $context['lang_id'] . '.php', 'w+'); |
@@ -1017,30 +1051,29 @@ discard block |
||
1017 | 1051 | if (is_string($v)) |
1018 | 1052 | { |
1019 | 1053 | // Only try to save if 'edit' was specified and if the string has changed |
1020 | - if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) |
|
1021 | - $save_strings[$k] = cleanLangString($_POST['entry'][$k], false); |
|
1054 | + if ($v == 'edit' && isset($_POST['entry'][$k]) && isset($_POST['comp'][$k]) && $_POST['entry'][$k] != $_POST['comp'][$k]) { |
|
1055 | + $save_strings[$k] = cleanLangString($_POST['entry'][$k], false); |
|
1056 | + } |
|
1022 | 1057 | |
1023 | 1058 | // Record any add or remove requests. We'll decide on them later. |
1024 | - elseif ($v == 'remove') |
|
1025 | - $remove_strings[] = $k; |
|
1026 | - elseif ($v == 'add' && isset($_POST['entry'][$k])) |
|
1059 | + elseif ($v == 'remove') { |
|
1060 | + $remove_strings[] = $k; |
|
1061 | + } elseif ($v == 'add' && isset($_POST['entry'][$k])) |
|
1027 | 1062 | { |
1028 | 1063 | $add_strings[$k] = array( |
1029 | 1064 | 'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt', |
1030 | 1065 | 'string' => cleanLangString($_POST['entry'][$k], false), |
1031 | 1066 | ); |
1032 | 1067 | } |
1033 | - } |
|
1034 | - elseif (is_array($v)) |
|
1068 | + } elseif (is_array($v)) |
|
1035 | 1069 | { |
1036 | 1070 | foreach ($v as $subk => $subv) |
1037 | 1071 | { |
1038 | - if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk]) |
|
1039 | - $save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false); |
|
1040 | - |
|
1041 | - elseif ($subv == 'remove') |
|
1042 | - $remove_strings[$k][] = $subk; |
|
1043 | - elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk])) |
|
1072 | + if ($subv == 'edit' && isset($_POST['entry'][$k][$subk]) && isset($_POST['comp'][$k][$subk]) && $_POST['entry'][$k][$subk] != $_POST['comp'][$k][$subk]) { |
|
1073 | + $save_strings[$k][$subk] = cleanLangString($_POST['entry'][$k][$subk], false); |
|
1074 | + } elseif ($subv == 'remove') { |
|
1075 | + $remove_strings[$k][] = $subk; |
|
1076 | + } elseif ($subv == 'add' && isset($_POST['entry'][$k][$subk])) |
|
1044 | 1077 | { |
1045 | 1078 | $add_strings[$k][$subk] = array( |
1046 | 1079 | 'group' => isset($_POST['grp'][$k]) ? $_POST['grp'][$k] : 'txt', |
@@ -1076,8 +1109,9 @@ discard block |
||
1076 | 1109 | foreach ($allows_add_remove[$file_id]['add'] as $var_group) |
1077 | 1110 | { |
1078 | 1111 | $group = !empty($special_groups[$file_id][$var_group]) ? $special_groups[$file_id][$var_group] : $var_group; |
1079 | - if (in_array($var_group, $allows_add_remove[$file_id]['add'])) |
|
1080 | - $context['can_add_lang_entry'][$group] = true; |
|
1112 | + if (in_array($var_group, $allows_add_remove[$file_id]['add'])) { |
|
1113 | + $context['can_add_lang_entry'][$group] = true; |
|
1114 | + } |
|
1081 | 1115 | } |
1082 | 1116 | } |
1083 | 1117 | |
@@ -1115,15 +1149,17 @@ discard block |
||
1115 | 1149 | foreach ($entries as $entryKey => $entryValue) |
1116 | 1150 | { |
1117 | 1151 | // Ignore some things we set separately. |
1118 | - if (in_array($entryKey, array_keys($primary_settings))) |
|
1119 | - continue; |
|
1152 | + if (in_array($entryKey, array_keys($primary_settings))) { |
|
1153 | + continue; |
|
1154 | + } |
|
1120 | 1155 | |
1121 | 1156 | // These are arrays that need breaking out. |
1122 | 1157 | if (strpos($entryValue['entry'], 'array(') === 0 && strpos($entryValue['entry'], ')', -1) === strlen($entryValue['entry']) - 1) |
1123 | 1158 | { |
1124 | 1159 | // No, you may not use multidimensional arrays of $txt strings. Madness stalks that path. |
1125 | - if (isset($entryValue['subkey'])) |
|
1126 | - continue; |
|
1160 | + if (isset($entryValue['subkey'])) { |
|
1161 | + continue; |
|
1162 | + } |
|
1127 | 1163 | |
1128 | 1164 | // Trim off the array construct bits. |
1129 | 1165 | $entryValue['entry'] = substr($entryValue['entry'], strpos($entryValue['entry'], 'array(') + 6, -1); |
@@ -1166,8 +1202,9 @@ discard block |
||
1166 | 1202 | |
1167 | 1203 | /x' . ($context['utf8'] ? 'u' : ''), $entryValue['entry'], $matches); |
1168 | 1204 | |
1169 | - if (empty($m)) |
|
1170 | - continue; |
|
1205 | + if (empty($m)) { |
|
1206 | + continue; |
|
1207 | + } |
|
1171 | 1208 | |
1172 | 1209 | $entryValue['entry'] = $matches[0]; |
1173 | 1210 | |
@@ -1184,19 +1221,21 @@ discard block |
||
1184 | 1221 | { |
1185 | 1222 | $subKey = trim($matches[1], '\'"'); |
1186 | 1223 | |
1187 | - if (ctype_digit($subKey)) |
|
1188 | - $cur_index = $subKey; |
|
1224 | + if (ctype_digit($subKey)) { |
|
1225 | + $cur_index = $subKey; |
|
1226 | + } |
|
1189 | 1227 | |
1190 | 1228 | $subValue = trim(substr($subValue, strpos($subValue, '=>') + 2)); |
1229 | + } else { |
|
1230 | + $subKey = $cur_index++; |
|
1191 | 1231 | } |
1192 | - else |
|
1193 | - $subKey = $cur_index++; |
|
1194 | 1232 | |
1195 | 1233 | // Clean up some bits. |
1196 | - if (strpos($subValue, '\'') === 0) |
|
1197 | - $subValue = trim($subValue, '\''); |
|
1198 | - elseif (strpos($subValue, '"') === 0) |
|
1199 | - $subValue = trim($subValue, '"'); |
|
1234 | + if (strpos($subValue, '\'') === 0) { |
|
1235 | + $subValue = trim($subValue, '\''); |
|
1236 | + } elseif (strpos($subValue, '"') === 0) { |
|
1237 | + $subValue = trim($subValue, '"'); |
|
1238 | + } |
|
1200 | 1239 | |
1201 | 1240 | // Can we save? |
1202 | 1241 | if (isset($save_strings[$entryKey][$subKey])) |
@@ -1205,11 +1244,13 @@ discard block |
||
1205 | 1244 | $save_cache['enabled'] = true; |
1206 | 1245 | } |
1207 | 1246 | // Should we remove this one? |
1208 | - elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) |
|
1209 | - $save_cache['enabled'] = true; |
|
1247 | + elseif (isset($remove_strings[$entryKey]) && in_array($subKey, $remove_strings[$entryKey]) && $entryValue['can_remove']) { |
|
1248 | + $save_cache['enabled'] = true; |
|
1249 | + } |
|
1210 | 1250 | // Just keep this one as it is |
1211 | - else |
|
1212 | - $save_cache['entries'][$subKey] = $subValue; |
|
1251 | + else { |
|
1252 | + $save_cache['entries'][$subKey] = $subValue; |
|
1253 | + } |
|
1213 | 1254 | |
1214 | 1255 | $context['file_entries'][$entryValue['group']][] = array( |
1215 | 1256 | 'key' => $entryKey, |
@@ -1223,15 +1264,17 @@ discard block |
||
1223 | 1264 | // Should we add a new string to this array? |
1224 | 1265 | if (!empty($context['can_add_lang_entry'][$entryValue['type']]) && isset($add_strings[$entryKey])) |
1225 | 1266 | { |
1226 | - foreach ($add_strings[$entryKey] as $string_key => $string_val) |
|
1227 | - $save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => '')); |
|
1267 | + foreach ($add_strings[$entryKey] as $string_key => $string_val) { |
|
1268 | + $save_cache['entries'][$string_key] = strtr($string_val['string'], array('\'' => '')); |
|
1269 | + } |
|
1228 | 1270 | |
1229 | 1271 | $save_cache['enabled'] = true; |
1230 | 1272 | |
1231 | 1273 | // Make sure we don't add this again as an independent line |
1232 | 1274 | unset($add_strings[$entryKey][$string_key]); |
1233 | - if (empty($add_strings[$entryKey])) |
|
1234 | - unset($add_strings[$entryKey]); |
|
1275 | + if (empty($add_strings[$entryKey])) { |
|
1276 | + unset($add_strings[$entryKey]); |
|
1277 | + } |
|
1235 | 1278 | } |
1236 | 1279 | |
1237 | 1280 | |
@@ -1248,9 +1291,9 @@ discard block |
||
1248 | 1291 | { |
1249 | 1292 | $items[] = $k2 . ' => \'' . $v2 . '\''; |
1250 | 1293 | $cur_index = $k2; |
1294 | + } else { |
|
1295 | + $items[] = '\'' . $v2 . '\''; |
|
1251 | 1296 | } |
1252 | - else |
|
1253 | - $items[] = '\'' . $v2 . '\''; |
|
1254 | 1297 | |
1255 | 1298 | $cur_index++; |
1256 | 1299 | } |
@@ -1267,8 +1310,9 @@ discard block |
||
1267 | 1310 | // Saving? |
1268 | 1311 | if (isset($save_strings[$entryValue['key']][$entryValue['subkey']]) && $save_strings[$entryValue['key']][$entryValue['subkey']] != $entryValue['entry']) |
1269 | 1312 | { |
1270 | - if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '') |
|
1271 | - $save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\''; |
|
1313 | + if ($save_strings[$entryValue['key']][$entryValue['subkey']] == '') { |
|
1314 | + $save_strings[$entryValue['key']][$entryValue['subkey']] = '\'\''; |
|
1315 | + } |
|
1272 | 1316 | |
1273 | 1317 | // Preserve subkey as either digit or string |
1274 | 1318 | $subKey = ctype_digit($entryValue['subkey']) ? $entryValue['subkey'] : '\'' . $entryValue['subkey'] . '\''; |
@@ -1309,8 +1353,9 @@ discard block |
||
1309 | 1353 | if (isset($save_strings[$entryValue['key']]) && $save_strings[$entryValue['key']] != $entryValue['entry']) |
1310 | 1354 | { |
1311 | 1355 | // @todo Fix this properly. |
1312 | - if ($save_strings[$entryValue['key']] == '') |
|
1313 | - $save_strings[$entryValue['key']] = '\'\''; |
|
1356 | + if ($save_strings[$entryValue['key']] == '') { |
|
1357 | + $save_strings[$entryValue['key']] = '\'\''; |
|
1358 | + } |
|
1314 | 1359 | |
1315 | 1360 | // Set the new value. |
1316 | 1361 | $entryValue['entry'] = $save_strings[$entryValue['key']]; |
@@ -1353,8 +1398,9 @@ discard block |
||
1353 | 1398 | { |
1354 | 1399 | $type = isset($special_types[$string_val['group']]) ? $special_types[$string_val['group']] : $string_val['group']; |
1355 | 1400 | |
1356 | - if (empty($context['can_add_lang_entry'][$type])) |
|
1357 | - continue; |
|
1401 | + if (empty($context['can_add_lang_entry'][$type])) { |
|
1402 | + continue; |
|
1403 | + } |
|
1358 | 1404 | |
1359 | 1405 | $final_saves[$string_key] = array( |
1360 | 1406 | 'find' => "\s*\?".'>$', |
@@ -1369,8 +1415,9 @@ discard block |
||
1369 | 1415 | { |
1370 | 1416 | $type = isset($special_types[$substring_val['group']]) ? $special_types[$substring_val['group']] : $substring_val['group']; |
1371 | 1417 | |
1372 | - if (empty($context['can_add_lang_entry'][$type])) |
|
1373 | - continue; |
|
1418 | + if (empty($context['can_add_lang_entry'][$type])) { |
|
1419 | + continue; |
|
1420 | + } |
|
1374 | 1421 | |
1375 | 1422 | $subKey = ctype_digit(trim($substring_key, '\'')) ? trim($substring_key, '\'') : '\'' . $substring_key . '\''; |
1376 | 1423 | |
@@ -1393,10 +1440,11 @@ discard block |
||
1393 | 1440 | |
1394 | 1441 | foreach ($final_saves as $save) |
1395 | 1442 | { |
1396 | - if (!empty($save['is_regex'])) |
|
1397 | - $file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents); |
|
1398 | - else |
|
1399 | - $file_contents = str_replace($save['find'], $save['replace'], $file_contents); |
|
1443 | + if (!empty($save['is_regex'])) { |
|
1444 | + $file_contents = preg_replace('~' . $save['find'] . '~' . ($context['utf8'] ? 'u' : ''), $save['replace'], $file_contents); |
|
1445 | + } else { |
|
1446 | + $file_contents = str_replace($save['find'], $save['replace'], $file_contents); |
|
1447 | + } |
|
1400 | 1448 | } |
1401 | 1449 | |
1402 | 1450 | // Save the actual changes. |
@@ -1414,8 +1462,9 @@ discard block |
||
1414 | 1462 | // Make sure the Add button has a place to show up. |
1415 | 1463 | foreach ($context['can_add_lang_entry'] as $group => $value) |
1416 | 1464 | { |
1417 | - if (!isset($context['file_entries'][$group])) |
|
1418 | - $context['file_entries'][$group] = array(); |
|
1465 | + if (!isset($context['file_entries'][$group])) { |
|
1466 | + $context['file_entries'][$group] = array(); |
|
1467 | + } |
|
1419 | 1468 | } |
1420 | 1469 | |
1421 | 1470 | addInlineJavaScript(' |
@@ -1507,8 +1556,9 @@ discard block |
||
1507 | 1556 | } |
1508 | 1557 | |
1509 | 1558 | // If we saved, redirect. |
1510 | - if ($madeSave) |
|
1511 | - redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : '')); |
|
1559 | + if ($madeSave) { |
|
1560 | + redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id'] . (!empty($file_id) ? ';entries;tfid=' . $theme_id . rawurlencode('+') . $file_id : '')); |
|
1561 | + } |
|
1512 | 1562 | |
1513 | 1563 | createToken('admin-mlang'); |
1514 | 1564 | } |
@@ -1540,8 +1590,9 @@ discard block |
||
1540 | 1590 | // Toggle the escape. |
1541 | 1591 | $is_escape = !$is_escape; |
1542 | 1592 | // If we're now escaped don't add this string. |
1543 | - if ($is_escape) |
|
1544 | - continue; |
|
1593 | + if ($is_escape) { |
|
1594 | + continue; |
|
1595 | + } |
|
1545 | 1596 | } |
1546 | 1597 | // Special case - parsed string with line break etc? |
1547 | 1598 | elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape) |
@@ -1558,11 +1609,13 @@ discard block |
||
1558 | 1609 | if ($in_string != 2 && ($in_string != 1 || !$is_escape)) |
1559 | 1610 | { |
1560 | 1611 | // Is it the end of a single quote string? |
1561 | - if ($in_string == 1) |
|
1562 | - $in_string = 0; |
|
1612 | + if ($in_string == 1) { |
|
1613 | + $in_string = 0; |
|
1614 | + } |
|
1563 | 1615 | // Otherwise it's the start! |
1564 | - else |
|
1565 | - $in_string = 1; |
|
1616 | + else { |
|
1617 | + $in_string = 1; |
|
1618 | + } |
|
1566 | 1619 | |
1567 | 1620 | // Don't actually include this character! |
1568 | 1621 | continue; |
@@ -1575,19 +1628,22 @@ discard block |
||
1575 | 1628 | if ($in_string != 1 && ($in_string != 2 || !$is_escape)) |
1576 | 1629 | { |
1577 | 1630 | // Is it the end of a double quote string? |
1578 | - if ($in_string == 2) |
|
1579 | - $in_string = 0; |
|
1631 | + if ($in_string == 2) { |
|
1632 | + $in_string = 0; |
|
1633 | + } |
|
1580 | 1634 | // Otherwise it's the start! |
1581 | - else |
|
1582 | - $in_string = 2; |
|
1635 | + else { |
|
1636 | + $in_string = 2; |
|
1637 | + } |
|
1583 | 1638 | |
1584 | 1639 | // Don't actually include this character! |
1585 | 1640 | continue; |
1586 | 1641 | } |
1587 | 1642 | } |
1588 | 1643 | // A join/space outside of a string is simply removed. |
1589 | - elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) |
|
1590 | - continue; |
|
1644 | + elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) { |
|
1645 | + continue; |
|
1646 | + } |
|
1591 | 1647 | // Start of a variable? |
1592 | 1648 | elseif ($in_string == 0 && $string{$i} == '$') |
1593 | 1649 | { |
@@ -1621,8 +1677,7 @@ discard block |
||
1621 | 1677 | |
1622 | 1678 | // Unhtml then rehtml the whole thing! |
1623 | 1679 | $new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string)); |
1624 | - } |
|
1625 | - else |
|
1680 | + } else |
|
1626 | 1681 | { |
1627 | 1682 | // Keep track of what we're doing... |
1628 | 1683 | $in_string = 0; |
@@ -1651,10 +1706,11 @@ discard block |
||
1651 | 1706 | preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches); |
1652 | 1707 | if (!empty($matches[1])) |
1653 | 1708 | { |
1654 | - if ($in_string == 1) |
|
1655 | - $new_string .= '\' . '; |
|
1656 | - elseif ($new_string) |
|
1657 | - $new_string .= ' . '; |
|
1709 | + if ($in_string == 1) { |
|
1710 | + $new_string .= '\' . '; |
|
1711 | + } elseif ($new_string) { |
|
1712 | + $new_string .= ' . '; |
|
1713 | + } |
|
1658 | 1714 | |
1659 | 1715 | $new_string .= $matches[1]; |
1660 | 1716 | $i += strlen($matches[1]) + 3; |
@@ -1667,8 +1723,9 @@ discard block |
||
1667 | 1723 | elseif ($string{$i} == '<') |
1668 | 1724 | { |
1669 | 1725 | // Probably HTML? |
1670 | - if ($string{$i + 1} != ' ') |
|
1671 | - $in_html = true; |
|
1726 | + if ($string{$i + 1} != ' ') { |
|
1727 | + $in_html = true; |
|
1728 | + } |
|
1672 | 1729 | // Assume we need an entity... |
1673 | 1730 | else |
1674 | 1731 | { |
@@ -1680,8 +1737,9 @@ discard block |
||
1680 | 1737 | elseif ($string{$i} == '>') |
1681 | 1738 | { |
1682 | 1739 | // Will it be HTML? |
1683 | - if ($in_html) |
|
1684 | - $in_html = false; |
|
1740 | + if ($in_html) { |
|
1741 | + $in_html = false; |
|
1742 | + } |
|
1685 | 1743 | // Otherwise we need an entity... |
1686 | 1744 | else |
1687 | 1745 | { |
@@ -1690,8 +1748,9 @@ discard block |
||
1690 | 1748 | } |
1691 | 1749 | } |
1692 | 1750 | // Is it a slash? If so escape it... |
1693 | - if ($string{$i} == '\\') |
|
1694 | - $new_string .= '\\'; |
|
1751 | + if ($string{$i} == '\\') { |
|
1752 | + $new_string .= '\\'; |
|
1753 | + } |
|
1695 | 1754 | // The infamous double quote? |
1696 | 1755 | elseif ($string{$i} == '"') |
1697 | 1756 | { |
@@ -1714,10 +1773,11 @@ discard block |
||
1714 | 1773 | } |
1715 | 1774 | |
1716 | 1775 | // If we ended as a string then close it off. |
1717 | - if ($in_string == 1) |
|
1718 | - $new_string .= '\''; |
|
1719 | - elseif ($in_string == 2) |
|
1720 | - $new_string .= '"'; |
|
1776 | + if ($in_string == 1) { |
|
1777 | + $new_string .= '\''; |
|
1778 | + } elseif ($in_string == 2) { |
|
1779 | + $new_string .= '"'; |
|
1780 | + } |
|
1721 | 1781 | } |
1722 | 1782 | |
1723 | 1783 | return $new_string; |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * As of SMF 2.1, this is unused. But it is available if any mod wants to use it. |
@@ -30,8 +31,9 @@ discard block |
||
30 | 31 | { |
31 | 32 | global $modSettings; |
32 | 33 | |
33 | - if (!$compat_mode) |
|
34 | - return $text; |
|
34 | + if (!$compat_mode) { |
|
35 | + return $text; |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // Turn line breaks back into br's. |
37 | 39 | $text = strtr($text, array("\r" => '', "\n" => '<br>')); |
@@ -48,8 +50,9 @@ discard block |
||
48 | 50 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
49 | 51 | { |
50 | 52 | // Value of 2 means we're inside the tag. |
51 | - if ($i % 4 == 2) |
|
52 | - $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
53 | + if ($i % 4 == 2) { |
|
54 | + $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | // Put our humpty dumpty message back together again. |
55 | 58 | $text = implode('', $parts); |
@@ -104,8 +107,9 @@ discard block |
||
104 | 107 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
105 | 108 | |
106 | 109 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
107 | - if (isBrowser('webkit')) |
|
108 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
110 | + if (isBrowser('webkit')) { |
|
111 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
112 | + } |
|
109 | 113 | |
110 | 114 | // If there's a trailing break get rid of it - Firefox tends to add one. |
111 | 115 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -120,8 +124,9 @@ discard block |
||
120 | 124 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
121 | 125 | { |
122 | 126 | // Value of 2 means we're inside the tag. |
123 | - if ($i % 4 == 2) |
|
124 | - $parts[$i] = strip_tags($parts[$i]); |
|
127 | + if ($i % 4 == 2) { |
|
128 | + $parts[$i] = strip_tags($parts[$i]); |
|
129 | + } |
|
125 | 130 | } |
126 | 131 | |
127 | 132 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -147,18 +152,19 @@ discard block |
||
147 | 152 | { |
148 | 153 | $found = array_search($file, $smileysto); |
149 | 154 | // Note the weirdness here is to stop double spaces between smileys. |
150 | - if ($found) |
|
151 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
152 | - else |
|
153 | - $matches[1][$k] = ''; |
|
155 | + if ($found) { |
|
156 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
157 | + } else { |
|
158 | + $matches[1][$k] = ''; |
|
159 | + } |
|
154 | 160 | } |
155 | - } |
|
156 | - else |
|
161 | + } else |
|
157 | 162 | { |
158 | 163 | // Load all the smileys. |
159 | 164 | $names = array(); |
160 | - foreach ($matches[1] as $file) |
|
161 | - $names[] = $file; |
|
165 | + foreach ($matches[1] as $file) { |
|
166 | + $names[] = $file; |
|
167 | + } |
|
162 | 168 | $names = array_unique($names); |
163 | 169 | |
164 | 170 | if (!empty($names)) |
@@ -172,13 +178,15 @@ discard block |
||
172 | 178 | ) |
173 | 179 | ); |
174 | 180 | $mappings = array(); |
175 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
176 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
181 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
182 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
183 | + } |
|
177 | 184 | $smcFunc['db_free_result']($request); |
178 | 185 | |
179 | - foreach ($matches[1] as $k => $file) |
|
180 | - if (isset($mappings[$file])) |
|
186 | + foreach ($matches[1] as $k => $file) { |
|
187 | + if (isset($mappings[$file])) |
|
181 | 188 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
189 | + } |
|
182 | 190 | } |
183 | 191 | } |
184 | 192 | |
@@ -190,8 +198,9 @@ discard block |
||
190 | 198 | } |
191 | 199 | |
192 | 200 | // Only try to buy more time if the client didn't quit. |
193 | - if (connection_aborted() && $context['server']['is_apache']) |
|
194 | - @apache_reset_timeout(); |
|
201 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
202 | + @apache_reset_timeout(); |
|
203 | + } |
|
195 | 204 | |
196 | 205 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
197 | 206 | $replacement = ''; |
@@ -202,9 +211,9 @@ discard block |
||
202 | 211 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
203 | 212 | { |
204 | 213 | // If it's being closed instantly, we can't deal with it...yet. |
205 | - if ($matches[5] === '/') |
|
206 | - continue; |
|
207 | - else |
|
214 | + if ($matches[5] === '/') { |
|
215 | + continue; |
|
216 | + } else |
|
208 | 217 | { |
209 | 218 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
210 | 219 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -220,8 +229,9 @@ discard block |
||
220 | 229 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
221 | 230 | |
222 | 231 | // Something like 'font-weight: bold' is expected here. |
223 | - if (strpos($clean_type_value_pair, ':') === false) |
|
224 | - continue; |
|
232 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
233 | + continue; |
|
234 | + } |
|
225 | 235 | |
226 | 236 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
227 | 237 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -243,8 +253,7 @@ discard block |
||
243 | 253 | { |
244 | 254 | $curCloseTags .= '[/u]'; |
245 | 255 | $replacement .= '[u]'; |
246 | - } |
|
247 | - elseif ($style_value == 'line-through') |
|
256 | + } elseif ($style_value == 'line-through') |
|
248 | 257 | { |
249 | 258 | $curCloseTags .= '[/s]'; |
250 | 259 | $replacement .= '[s]'; |
@@ -256,13 +265,11 @@ discard block |
||
256 | 265 | { |
257 | 266 | $curCloseTags .= '[/left]'; |
258 | 267 | $replacement .= '[left]'; |
259 | - } |
|
260 | - elseif ($style_value == 'center') |
|
268 | + } elseif ($style_value == 'center') |
|
261 | 269 | { |
262 | 270 | $curCloseTags .= '[/center]'; |
263 | 271 | $replacement .= '[center]'; |
264 | - } |
|
265 | - elseif ($style_value == 'right') |
|
272 | + } elseif ($style_value == 'right') |
|
266 | 273 | { |
267 | 274 | $curCloseTags .= '[/right]'; |
268 | 275 | $replacement .= '[right]'; |
@@ -284,8 +291,9 @@ discard block |
||
284 | 291 | |
285 | 292 | case 'font-size': |
286 | 293 | // Sometimes people put decimals where decimals should not be. |
287 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
288 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
294 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
295 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
296 | + } |
|
289 | 297 | |
290 | 298 | $curCloseTags .= '[/size]'; |
291 | 299 | $replacement .= '[size=' . $style_value . ']'; |
@@ -293,8 +301,9 @@ discard block |
||
293 | 301 | |
294 | 302 | case 'font-family': |
295 | 303 | // Only get the first freaking font if there's a list! |
296 | - if (strpos($style_value, ',') !== false) |
|
297 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
304 | + if (strpos($style_value, ',') !== false) { |
|
305 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
306 | + } |
|
298 | 307 | |
299 | 308 | $curCloseTags .= '[/font]'; |
300 | 309 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -303,13 +312,15 @@ discard block |
||
303 | 312 | // This is a hack for images with dimensions embedded. |
304 | 313 | case 'width': |
305 | 314 | case 'height': |
306 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
307 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
315 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
316 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
317 | + } |
|
308 | 318 | break; |
309 | 319 | |
310 | 320 | case 'list-style-type': |
311 | - if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) |
|
312 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
321 | + if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { |
|
322 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
323 | + } |
|
313 | 324 | break; |
314 | 325 | } |
315 | 326 | } |
@@ -322,18 +333,17 @@ discard block |
||
322 | 333 | } |
323 | 334 | |
324 | 335 | // If there's something that still needs closing, push it to the stack. |
325 | - if (!empty($curCloseTags)) |
|
326 | - array_push($stack, array( |
|
336 | + if (!empty($curCloseTags)) { |
|
337 | + array_push($stack, array( |
|
327 | 338 | 'element' => strtolower($curElement), |
328 | 339 | 'closeTags' => $curCloseTags |
329 | 340 | ) |
330 | 341 | ); |
331 | - elseif (!empty($extra_attr)) |
|
332 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
342 | + } elseif (!empty($extra_attr)) { |
|
343 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
344 | + } |
|
333 | 345 | } |
334 | - } |
|
335 | - |
|
336 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
346 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
337 | 347 | { |
338 | 348 | // Is this the element that we've been waiting for to be closed? |
339 | 349 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -343,28 +353,32 @@ discard block |
||
343 | 353 | } |
344 | 354 | |
345 | 355 | // Must've been something else. |
346 | - else |
|
347 | - $replacement .= $part; |
|
356 | + else { |
|
357 | + $replacement .= $part; |
|
358 | + } |
|
348 | 359 | } |
349 | 360 | // In all other cases, just add the part to the replacement. |
350 | - else |
|
351 | - $replacement .= $part; |
|
361 | + else { |
|
362 | + $replacement .= $part; |
|
363 | + } |
|
352 | 364 | } |
353 | 365 | |
354 | 366 | // Now put back the replacement in the text. |
355 | 367 | $text = $replacement; |
356 | 368 | |
357 | 369 | // We are not finished yet, request more time. |
358 | - if (connection_aborted() && $context['server']['is_apache']) |
|
359 | - @apache_reset_timeout(); |
|
370 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
371 | + @apache_reset_timeout(); |
|
372 | + } |
|
360 | 373 | |
361 | 374 | // Let's pull out any legacy alignments. |
362 | 375 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
363 | 376 | { |
364 | 377 | // Find the position in the text of this tag over again. |
365 | 378 | $start_pos = strpos($text, $matches[0]); |
366 | - if ($start_pos === false) |
|
367 | - break; |
|
379 | + if ($start_pos === false) { |
|
380 | + break; |
|
381 | + } |
|
368 | 382 | |
369 | 383 | // End tag? |
370 | 384 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -378,8 +392,7 @@ discard block |
||
378 | 392 | |
379 | 393 | // Put the tags back into the body. |
380 | 394 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
381 | - } |
|
382 | - else |
|
395 | + } else |
|
383 | 396 | { |
384 | 397 | // Just get rid of this evil tag. |
385 | 398 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -392,8 +405,9 @@ discard block |
||
392 | 405 | // Find the position of this again. |
393 | 406 | $start_pos = strpos($text, $matches[0]); |
394 | 407 | $end_pos = false; |
395 | - if ($start_pos === false) |
|
396 | - break; |
|
408 | + if ($start_pos === false) { |
|
409 | + break; |
|
410 | + } |
|
397 | 411 | |
398 | 412 | // This must have an end tag - and we must find the right one. |
399 | 413 | $lower_text = strtolower($text); |
@@ -426,8 +440,9 @@ discard block |
||
426 | 440 | break; |
427 | 441 | } |
428 | 442 | } |
429 | - if ($end_pos === false) |
|
430 | - break; |
|
443 | + if ($end_pos === false) { |
|
444 | + break; |
|
445 | + } |
|
431 | 446 | |
432 | 447 | // Now work out what the attributes are. |
433 | 448 | $attribs = fetchTagAttributes($matches[1]); |
@@ -441,11 +456,11 @@ discard block |
||
441 | 456 | $v = (int) trim($v); |
442 | 457 | $v = empty($v) ? 1 : $v; |
443 | 458 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
459 | + } elseif ($s == 'face') { |
|
460 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
461 | + } elseif ($s == 'color') { |
|
462 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
444 | 463 | } |
445 | - elseif ($s == 'face') |
|
446 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
447 | - elseif ($s == 'color') |
|
448 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
449 | 464 | } |
450 | 465 | |
451 | 466 | // As before add in our tags. |
@@ -453,8 +468,9 @@ discard block |
||
453 | 468 | foreach ($tags as $tag) |
454 | 469 | { |
455 | 470 | $before .= $tag[0]; |
456 | - if (isset($tag[1])) |
|
457 | - $after = $tag[1] . $after; |
|
471 | + if (isset($tag[1])) { |
|
472 | + $after = $tag[1] . $after; |
|
473 | + } |
|
458 | 474 | } |
459 | 475 | |
460 | 476 | // Remove the tag so it's never checked again. |
@@ -465,8 +481,9 @@ discard block |
||
465 | 481 | } |
466 | 482 | |
467 | 483 | // Almost there, just a little more time. |
468 | - if (connection_aborted() && $context['server']['is_apache']) |
|
469 | - @apache_reset_timeout(); |
|
484 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
485 | + @apache_reset_timeout(); |
|
486 | + } |
|
470 | 487 | |
471 | 488 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
472 | 489 | { |
@@ -522,12 +539,13 @@ discard block |
||
522 | 539 | { |
523 | 540 | $inList = true; |
524 | 541 | |
525 | - if ($tag === 'ol') |
|
526 | - $listType = 'decimal'; |
|
527 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
528 | - $listType = $listTypeMapping[$match[1]]; |
|
529 | - else |
|
530 | - $listType = null; |
|
542 | + if ($tag === 'ol') { |
|
543 | + $listType = 'decimal'; |
|
544 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
545 | + $listType = $listTypeMapping[$match[1]]; |
|
546 | + } else { |
|
547 | + $listType = null; |
|
548 | + } |
|
531 | 549 | |
532 | 550 | $listDepth++; |
533 | 551 | |
@@ -591,9 +609,7 @@ discard block |
||
591 | 609 | $parts[$i + 1] = ''; |
592 | 610 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
593 | 611 | $parts[$i + 3] = ''; |
594 | - } |
|
595 | - |
|
596 | - else |
|
612 | + } else |
|
597 | 613 | { |
598 | 614 | // We're in a list item. |
599 | 615 | if ($listDepth > 0) |
@@ -630,9 +646,7 @@ discard block |
||
630 | 646 | $parts[$i + 1] = ''; |
631 | 647 | $parts[$i + 2] = ''; |
632 | 648 | $parts[$i + 3] = ''; |
633 | - } |
|
634 | - |
|
635 | - else |
|
649 | + } else |
|
636 | 650 | { |
637 | 651 | // Remove the trailing breaks from the list item. |
638 | 652 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -670,8 +684,9 @@ discard block |
||
670 | 684 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
671 | 685 | } |
672 | 686 | |
673 | - for ($i = $listDepth; $i > 0; $i--) |
|
674 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
687 | + for ($i = $listDepth; $i > 0; $i--) { |
|
688 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
689 | + } |
|
675 | 690 | } |
676 | 691 | |
677 | 692 | // I love my own image... |
@@ -679,8 +694,9 @@ discard block |
||
679 | 694 | { |
680 | 695 | // Find the position of the image. |
681 | 696 | $start_pos = strpos($text, $matches[0]); |
682 | - if ($start_pos === false) |
|
683 | - break; |
|
697 | + if ($start_pos === false) { |
|
698 | + break; |
|
699 | + } |
|
684 | 700 | $end_pos = $start_pos + strlen($matches[0]); |
685 | 701 | |
686 | 702 | $params = ''; |
@@ -689,12 +705,13 @@ discard block |
||
689 | 705 | $attrs = fetchTagAttributes($matches[1]); |
690 | 706 | foreach ($attrs as $attrib => $value) |
691 | 707 | { |
692 | - if (in_array($attrib, array('width', 'height'))) |
|
693 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
694 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
695 | - $params .= ' alt=' . trim($value); |
|
696 | - elseif ($attrib == 'src') |
|
697 | - $src = trim($value); |
|
708 | + if (in_array($attrib, array('width', 'height'))) { |
|
709 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
710 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
711 | + $params .= ' alt=' . trim($value); |
|
712 | + } elseif ($attrib == 'src') { |
|
713 | + $src = trim($value); |
|
714 | + } |
|
698 | 715 | } |
699 | 716 | |
700 | 717 | $tag = ''; |
@@ -705,10 +722,11 @@ discard block |
||
705 | 722 | { |
706 | 723 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
707 | 724 | |
708 | - if (substr($src, 0, 1) === '/') |
|
709 | - $src = $baseURL . $src; |
|
710 | - else |
|
711 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
725 | + if (substr($src, 0, 1) === '/') { |
|
726 | + $src = $baseURL . $src; |
|
727 | + } else { |
|
728 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
729 | + } |
|
712 | 730 | } |
713 | 731 | |
714 | 732 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -886,20 +904,23 @@ discard block |
||
886 | 904 | }, |
887 | 905 | ); |
888 | 906 | |
889 | - foreach ($tags as $tag => $replace) |
|
890 | - $text = preg_replace_callback($tag, $replace, $text); |
|
907 | + foreach ($tags as $tag => $replace) { |
|
908 | + $text = preg_replace_callback($tag, $replace, $text); |
|
909 | + } |
|
891 | 910 | |
892 | 911 | // Please give us just a little more time. |
893 | - if (connection_aborted() && $context['server']['is_apache']) |
|
894 | - @apache_reset_timeout(); |
|
912 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
913 | + @apache_reset_timeout(); |
|
914 | + } |
|
895 | 915 | |
896 | 916 | // What about URL's - the pain in the ass of the tag world. |
897 | 917 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
898 | 918 | { |
899 | 919 | // Find the position of the URL. |
900 | 920 | $start_pos = strpos($text, $matches[0]); |
901 | - if ($start_pos === false) |
|
902 | - break; |
|
921 | + if ($start_pos === false) { |
|
922 | + break; |
|
923 | + } |
|
903 | 924 | $end_pos = $start_pos + strlen($matches[0]); |
904 | 925 | |
905 | 926 | $tag_type = 'url'; |
@@ -913,8 +934,9 @@ discard block |
||
913 | 934 | $href = trim($value); |
914 | 935 | |
915 | 936 | // Are we dealing with an FTP link? |
916 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
917 | - $tag_type = 'ftp'; |
|
937 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
938 | + $tag_type = 'ftp'; |
|
939 | + } |
|
918 | 940 | |
919 | 941 | // Or is this a link to an email address? |
920 | 942 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -928,28 +950,31 @@ discard block |
||
928 | 950 | { |
929 | 951 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
930 | 952 | |
931 | - if (substr($href, 0, 1) === '/') |
|
932 | - $href = $baseURL . $href; |
|
933 | - else |
|
934 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
953 | + if (substr($href, 0, 1) === '/') { |
|
954 | + $href = $baseURL . $href; |
|
955 | + } else { |
|
956 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
957 | + } |
|
935 | 958 | } |
936 | 959 | } |
937 | 960 | |
938 | 961 | // External URL? |
939 | 962 | if ($attrib == 'target' && $tag_type == 'url') |
940 | 963 | { |
941 | - if (trim($value) == '_blank') |
|
942 | - $tag_type == 'iurl'; |
|
964 | + if (trim($value) == '_blank') { |
|
965 | + $tag_type == 'iurl'; |
|
966 | + } |
|
943 | 967 | } |
944 | 968 | } |
945 | 969 | |
946 | 970 | $tag = ''; |
947 | 971 | if ($href != '') |
948 | 972 | { |
949 | - if ($matches[2] == $href) |
|
950 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
951 | - else |
|
952 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
973 | + if ($matches[2] == $href) { |
|
974 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
975 | + } else { |
|
976 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
977 | + } |
|
953 | 978 | } |
954 | 979 | |
955 | 980 | // Replace the tag |
@@ -985,17 +1010,18 @@ discard block |
||
985 | 1010 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
986 | 1011 | if ($text[$i] == '=') |
987 | 1012 | { |
988 | - if ($tag_state == 0) |
|
989 | - $tag_state = 1; |
|
990 | - elseif ($tag_state == 2) |
|
991 | - $value .= '='; |
|
1013 | + if ($tag_state == 0) { |
|
1014 | + $tag_state = 1; |
|
1015 | + } elseif ($tag_state == 2) { |
|
1016 | + $value .= '='; |
|
1017 | + } |
|
992 | 1018 | } |
993 | 1019 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
994 | 1020 | elseif ($text[$i] == ' ') |
995 | 1021 | { |
996 | - if ($tag_state == 2) |
|
997 | - $value .= ' '; |
|
998 | - elseif ($tag_state == 1) |
|
1022 | + if ($tag_state == 2) { |
|
1023 | + $value .= ' '; |
|
1024 | + } elseif ($tag_state == 1) |
|
999 | 1025 | { |
1000 | 1026 | $attribs[$key] = $value; |
1001 | 1027 | $key = $value = ''; |
@@ -1006,24 +1032,27 @@ discard block |
||
1006 | 1032 | elseif ($text[$i] == '"') |
1007 | 1033 | { |
1008 | 1034 | // Must be either going into or out of a string. |
1009 | - if ($tag_state == 1) |
|
1010 | - $tag_state = 2; |
|
1011 | - else |
|
1012 | - $tag_state = 1; |
|
1035 | + if ($tag_state == 1) { |
|
1036 | + $tag_state = 2; |
|
1037 | + } else { |
|
1038 | + $tag_state = 1; |
|
1039 | + } |
|
1013 | 1040 | } |
1014 | 1041 | // Otherwise it's fine. |
1015 | 1042 | else |
1016 | 1043 | { |
1017 | - if ($tag_state == 0) |
|
1018 | - $key .= $text[$i]; |
|
1019 | - else |
|
1020 | - $value .= $text[$i]; |
|
1044 | + if ($tag_state == 0) { |
|
1045 | + $key .= $text[$i]; |
|
1046 | + } else { |
|
1047 | + $value .= $text[$i]; |
|
1048 | + } |
|
1021 | 1049 | } |
1022 | 1050 | } |
1023 | 1051 | |
1024 | 1052 | // Anything left? |
1025 | - if ($key != '' && $value != '') |
|
1026 | - $attribs[$key] = $value; |
|
1053 | + if ($key != '' && $value != '') { |
|
1054 | + $attribs[$key] = $value; |
|
1055 | + } |
|
1027 | 1056 | |
1028 | 1057 | return $attribs; |
1029 | 1058 | } |
@@ -1039,8 +1068,9 @@ discard block |
||
1039 | 1068 | global $modSettings; |
1040 | 1069 | |
1041 | 1070 | // Don't care about the texts that are too short. |
1042 | - if (strlen($text) < 3) |
|
1043 | - return $text; |
|
1071 | + if (strlen($text) < 3) { |
|
1072 | + return $text; |
|
1073 | + } |
|
1044 | 1074 | |
1045 | 1075 | // A list of tags that's disabled by the admin. |
1046 | 1076 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
@@ -1051,10 +1081,12 @@ discard block |
||
1051 | 1081 | $self_closing_tags = array(); |
1052 | 1082 | foreach ($all_tags as $tag) |
1053 | 1083 | { |
1054 | - if (!isset($disabled[$tag['tag']])) |
|
1055 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
1056 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
1057 | - $self_closing_tags[] = $tag['tag']; |
|
1084 | + if (!isset($disabled[$tag['tag']])) { |
|
1085 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
1086 | + } |
|
1087 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
1088 | + $self_closing_tags[] = $tag['tag']; |
|
1089 | + } |
|
1058 | 1090 | } |
1059 | 1091 | |
1060 | 1092 | // Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid! |
@@ -1081,16 +1113,19 @@ discard block |
||
1081 | 1113 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
1082 | 1114 | |
1083 | 1115 | // We're closing the exact same tag that we opened. |
1084 | - if ($isClosingTag && $insideTag === $tagName) |
|
1085 | - $insideTag = null; |
|
1116 | + if ($isClosingTag && $insideTag === $tagName) { |
|
1117 | + $insideTag = null; |
|
1118 | + } |
|
1086 | 1119 | |
1087 | 1120 | // We're opening a tag and we're not yet inside one either |
1088 | - elseif (!$isClosingTag && $insideTag === null) |
|
1089 | - $insideTag = $tagName; |
|
1121 | + elseif (!$isClosingTag && $insideTag === null) { |
|
1122 | + $insideTag = $tagName; |
|
1123 | + } |
|
1090 | 1124 | |
1091 | 1125 | // In all other cases, this tag must be invalid |
1092 | - else |
|
1093 | - unset($matches[$i]); |
|
1126 | + else { |
|
1127 | + unset($matches[$i]); |
|
1128 | + } |
|
1094 | 1129 | } |
1095 | 1130 | |
1096 | 1131 | // The next one is gonna be the other one. |
@@ -1098,8 +1133,9 @@ discard block |
||
1098 | 1133 | } |
1099 | 1134 | |
1100 | 1135 | // We're still inside a tag and had no chance for closure? |
1101 | - if ($insideTag !== null) |
|
1102 | - $matches[] = '[/' . $insideTag . ']'; |
|
1136 | + if ($insideTag !== null) { |
|
1137 | + $matches[] = '[/' . $insideTag . ']'; |
|
1138 | + } |
|
1103 | 1139 | |
1104 | 1140 | // And a complete text string again. |
1105 | 1141 | $text = implode('', $matches); |
@@ -1108,8 +1144,9 @@ discard block |
||
1108 | 1144 | // Quickly remove any tags which are back to back. |
1109 | 1145 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
1110 | 1146 | $lastlen = 0; |
1111 | - while (strlen($text) !== $lastlen) |
|
1112 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1147 | + while (strlen($text) !== $lastlen) { |
|
1148 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1149 | + } |
|
1113 | 1150 | |
1114 | 1151 | // Need to sort the tags by name length. |
1115 | 1152 | uksort($valid_tags, function ($a, $b) { |
@@ -1148,8 +1185,9 @@ discard block |
||
1148 | 1185 | $isCompetingTag = in_array($tag, $competing_tags); |
1149 | 1186 | |
1150 | 1187 | // Check if this might be one of those cleaned out tags. |
1151 | - if ($tag === '') |
|
1152 | - continue; |
|
1188 | + if ($tag === '') { |
|
1189 | + continue; |
|
1190 | + } |
|
1153 | 1191 | |
1154 | 1192 | // Special case: inside [code] blocks any code is left untouched. |
1155 | 1193 | elseif ($tag === 'code') |
@@ -1160,8 +1198,9 @@ discard block |
||
1160 | 1198 | $inCode = false; |
1161 | 1199 | |
1162 | 1200 | // Reopen tags that were closed before the code block. |
1163 | - if (!empty($inlineElements)) |
|
1164 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1201 | + if (!empty($inlineElements)) { |
|
1202 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1203 | + } |
|
1165 | 1204 | } |
1166 | 1205 | |
1167 | 1206 | // We're outside a coding and nobbc block and opening it. |
@@ -1190,8 +1229,9 @@ discard block |
||
1190 | 1229 | $inNoBbc = false; |
1191 | 1230 | |
1192 | 1231 | // Some inline elements might've been closed that need reopening. |
1193 | - if (!empty($inlineElements)) |
|
1194 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1232 | + if (!empty($inlineElements)) { |
|
1233 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1234 | + } |
|
1195 | 1235 | } |
1196 | 1236 | |
1197 | 1237 | // We're outside a nobbc and coding block and opening it. |
@@ -1211,8 +1251,9 @@ discard block |
||
1211 | 1251 | } |
1212 | 1252 | |
1213 | 1253 | // So, we're inside one of the special blocks: ignore any tag. |
1214 | - elseif ($inCode || $inNoBbc) |
|
1215 | - continue; |
|
1254 | + elseif ($inCode || $inNoBbc) { |
|
1255 | + continue; |
|
1256 | + } |
|
1216 | 1257 | |
1217 | 1258 | // We're dealing with an opening tag. |
1218 | 1259 | if ($isOpeningTag) |
@@ -1253,8 +1294,9 @@ discard block |
||
1253 | 1294 | if ($parts[$j + 3] === $tag) |
1254 | 1295 | { |
1255 | 1296 | // If it's an opening tag, increase the level. |
1256 | - if ($parts[$j + 2] === '') |
|
1257 | - $curLevel++; |
|
1297 | + if ($parts[$j + 2] === '') { |
|
1298 | + $curLevel++; |
|
1299 | + } |
|
1258 | 1300 | |
1259 | 1301 | // A closing tag, decrease the level. |
1260 | 1302 | else |
@@ -1277,13 +1319,15 @@ discard block |
||
1277 | 1319 | { |
1278 | 1320 | if ($isCompetingTag) |
1279 | 1321 | { |
1280 | - if (!isset($competingElements[$tag])) |
|
1281 | - $competingElements[$tag] = array(); |
|
1322 | + if (!isset($competingElements[$tag])) { |
|
1323 | + $competingElements[$tag] = array(); |
|
1324 | + } |
|
1282 | 1325 | |
1283 | 1326 | $competingElements[$tag][] = $parts[$i + 4]; |
1284 | 1327 | |
1285 | - if (count($competingElements[$tag]) > 1) |
|
1286 | - $parts[$i] .= '[/' . $tag . ']'; |
|
1328 | + if (count($competingElements[$tag]) > 1) { |
|
1329 | + $parts[$i] .= '[/' . $tag . ']'; |
|
1330 | + } |
|
1287 | 1331 | } |
1288 | 1332 | |
1289 | 1333 | $inlineElements[$elementContent] = $tag; |
@@ -1303,15 +1347,17 @@ discard block |
||
1303 | 1347 | $addClosingTags = array(); |
1304 | 1348 | while ($element = array_pop($blockElements)) |
1305 | 1349 | { |
1306 | - if ($element === $tag) |
|
1307 | - break; |
|
1350 | + if ($element === $tag) { |
|
1351 | + break; |
|
1352 | + } |
|
1308 | 1353 | |
1309 | 1354 | // Still a block tag was open not equal to this tag. |
1310 | 1355 | $addClosingTags[] = $element['type']; |
1311 | 1356 | } |
1312 | 1357 | |
1313 | - if (!empty($addClosingTags)) |
|
1314 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
1358 | + if (!empty($addClosingTags)) { |
|
1359 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
1360 | + } |
|
1315 | 1361 | |
1316 | 1362 | // Apparently the closing tag was not found on the stack. |
1317 | 1363 | if (!is_string($element) || $element !== $tag) |
@@ -1321,8 +1367,7 @@ discard block |
||
1321 | 1367 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
1322 | 1368 | continue; |
1323 | 1369 | } |
1324 | - } |
|
1325 | - else |
|
1370 | + } else |
|
1326 | 1371 | { |
1327 | 1372 | // Get rid of this closing tag! |
1328 | 1373 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1351,53 +1396,62 @@ discard block |
||
1351 | 1396 | unset($inlineElements[$tagContentToBeClosed]); |
1352 | 1397 | |
1353 | 1398 | // Was this the tag we were looking for? |
1354 | - if ($tagToBeClosed === $tag) |
|
1355 | - break; |
|
1399 | + if ($tagToBeClosed === $tag) { |
|
1400 | + break; |
|
1401 | + } |
|
1356 | 1402 | |
1357 | 1403 | // Nope, close it and look further! |
1358 | - else |
|
1359 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
1404 | + else { |
|
1405 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
1406 | + } |
|
1360 | 1407 | } |
1361 | 1408 | |
1362 | 1409 | if ($isCompetingTag && !empty($competingElements[$tag])) |
1363 | 1410 | { |
1364 | 1411 | array_pop($competingElements[$tag]); |
1365 | 1412 | |
1366 | - if (count($competingElements[$tag]) > 0) |
|
1367 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
1413 | + if (count($competingElements[$tag]) > 0) { |
|
1414 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
1415 | + } |
|
1368 | 1416 | } |
1369 | 1417 | } |
1370 | 1418 | |
1371 | 1419 | // Unexpected closing tag, ex-ter-mi-nate. |
1372 | - else |
|
1373 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
1420 | + else { |
|
1421 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
1422 | + } |
|
1374 | 1423 | } |
1375 | 1424 | } |
1376 | 1425 | } |
1377 | 1426 | |
1378 | 1427 | // Close the code tags. |
1379 | - if ($inCode) |
|
1380 | - $parts[$i] .= '[/code]'; |
|
1428 | + if ($inCode) { |
|
1429 | + $parts[$i] .= '[/code]'; |
|
1430 | + } |
|
1381 | 1431 | |
1382 | 1432 | // The same for nobbc tags. |
1383 | - elseif ($inNoBbc) |
|
1384 | - $parts[$i] .= '[/nobbc]'; |
|
1433 | + elseif ($inNoBbc) { |
|
1434 | + $parts[$i] .= '[/nobbc]'; |
|
1435 | + } |
|
1385 | 1436 | |
1386 | 1437 | // Still inline tags left unclosed? Close them now, better late than never. |
1387 | - elseif (!empty($inlineElements)) |
|
1388 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
1438 | + elseif (!empty($inlineElements)) { |
|
1439 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
1440 | + } |
|
1389 | 1441 | |
1390 | 1442 | // Now close the block elements. |
1391 | - if (!empty($blockElements)) |
|
1392 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
1443 | + if (!empty($blockElements)) { |
|
1444 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
1445 | + } |
|
1393 | 1446 | |
1394 | 1447 | $text = implode('', $parts); |
1395 | 1448 | } |
1396 | 1449 | |
1397 | 1450 | // Final clean up of back to back tags. |
1398 | 1451 | $lastlen = 0; |
1399 | - while (strlen($text) !== $lastlen) |
|
1400 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1452 | + while (strlen($text) !== $lastlen) { |
|
1453 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1454 | + } |
|
1401 | 1455 | |
1402 | 1456 | return $text; |
1403 | 1457 | } |
@@ -1414,22 +1468,25 @@ discard block |
||
1414 | 1468 | $context['template_layers'] = array(); |
1415 | 1469 | // Lets make sure we aren't going to output anything nasty. |
1416 | 1470 | @ob_end_clean(); |
1417 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
1418 | - @ob_start('ob_gzhandler'); |
|
1419 | - else |
|
1420 | - @ob_start(); |
|
1471 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
1472 | + @ob_start('ob_gzhandler'); |
|
1473 | + } else { |
|
1474 | + @ob_start(); |
|
1475 | + } |
|
1421 | 1476 | |
1422 | 1477 | // If we don't have any locale better avoid broken js |
1423 | - if (empty($txt['lang_locale'])) |
|
1424 | - die(); |
|
1478 | + if (empty($txt['lang_locale'])) { |
|
1479 | + die(); |
|
1480 | + } |
|
1425 | 1481 | |
1426 | 1482 | $file_data = '(function ($) { |
1427 | 1483 | \'use strict\'; |
1428 | 1484 | |
1429 | 1485 | $.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {'; |
1430 | - foreach ($editortxt as $key => $val) |
|
1431 | - $file_data .= ' |
|
1486 | + foreach ($editortxt as $key => $val) { |
|
1487 | + $file_data .= ' |
|
1432 | 1488 | ' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ','; |
1489 | + } |
|
1433 | 1490 | |
1434 | 1491 | $file_data .= ' |
1435 | 1492 | dateFormat: "day.month.year" |
@@ -1497,8 +1554,9 @@ discard block |
||
1497 | 1554 | ) |
1498 | 1555 | ); |
1499 | 1556 | $icon_data = array(); |
1500 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1501 | - $icon_data[] = $row; |
|
1557 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1558 | + $icon_data[] = $row; |
|
1559 | + } |
|
1502 | 1560 | $smcFunc['db_free_result']($request); |
1503 | 1561 | |
1504 | 1562 | $icons = array(); |
@@ -1513,9 +1571,9 @@ discard block |
||
1513 | 1571 | } |
1514 | 1572 | |
1515 | 1573 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
1574 | + } else { |
|
1575 | + $icons = $temp; |
|
1516 | 1576 | } |
1517 | - else |
|
1518 | - $icons = $temp; |
|
1519 | 1577 | } |
1520 | 1578 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
1521 | 1579 | |
@@ -1544,8 +1602,9 @@ discard block |
||
1544 | 1602 | { |
1545 | 1603 | // Some general stuff. |
1546 | 1604 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
1547 | - if (!empty($context['drafts_autosave'])) |
|
1548 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
1605 | + if (!empty($context['drafts_autosave'])) { |
|
1606 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
1607 | + } |
|
1549 | 1608 | |
1550 | 1609 | // This really has some WYSIWYG stuff. |
1551 | 1610 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1562,8 +1621,9 @@ discard block |
||
1562 | 1621 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
1563 | 1622 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
1564 | 1623 | // editor language file |
1565 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
1566 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
1624 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
1625 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
1626 | + } |
|
1567 | 1627 | |
1568 | 1628 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))]; |
1569 | 1629 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1572,11 +1632,12 @@ discard block |
||
1572 | 1632 | loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck'); |
1573 | 1633 | |
1574 | 1634 | // Some hidden information is needed in order to make the spell checking work. |
1575 | - if (!isset($_REQUEST['xml'])) |
|
1576 | - $context['insert_after_template'] .= ' |
|
1635 | + if (!isset($_REQUEST['xml'])) { |
|
1636 | + $context['insert_after_template'] .= ' |
|
1577 | 1637 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
1578 | 1638 | <input type="hidden" name="spellstring" value=""> |
1579 | 1639 | </form>'; |
1640 | + } |
|
1580 | 1641 | } |
1581 | 1642 | } |
1582 | 1643 | |
@@ -1768,8 +1829,9 @@ discard block |
||
1768 | 1829 | |
1769 | 1830 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
1770 | 1831 | $disabled_tags = array(); |
1771 | - if (!empty($modSettings['disabledBBC'])) |
|
1772 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
1832 | + if (!empty($modSettings['disabledBBC'])) { |
|
1833 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
1834 | + } |
|
1773 | 1835 | |
1774 | 1836 | foreach ($disabled_tags as $tag) |
1775 | 1837 | { |
@@ -1781,9 +1843,10 @@ discard block |
||
1781 | 1843 | $context['disabled_tags']['orderedlist'] = true; |
1782 | 1844 | } |
1783 | 1845 | |
1784 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
1785 | - if ($tag === $thisTag) |
|
1846 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
1847 | + if ($tag === $thisTag) |
|
1786 | 1848 | $context['disabled_tags'][$tagNameBBC] = true; |
1849 | + } |
|
1787 | 1850 | |
1788 | 1851 | $context['disabled_tags'][$tag] = true; |
1789 | 1852 | } |
@@ -1794,8 +1857,9 @@ discard block |
||
1794 | 1857 | |
1795 | 1858 | foreach ($context['bbc_tags'] as $row => $tagRow) |
1796 | 1859 | { |
1797 | - if (!isset($context['bbc_toolbar'][$row])) |
|
1798 | - $context['bbc_toolbar'][$row] = array(); |
|
1860 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
1861 | + $context['bbc_toolbar'][$row] = array(); |
|
1862 | + } |
|
1799 | 1863 | |
1800 | 1864 | $tagsRow = array(); |
1801 | 1865 | |
@@ -1831,20 +1895,21 @@ discard block |
||
1831 | 1895 | |
1832 | 1896 | $context['bbcodes_handlers'] .= ' |
1833 | 1897 | });'; |
1834 | - } |
|
1835 | - else |
|
1898 | + } else |
|
1836 | 1899 | { |
1837 | 1900 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
1838 | 1901 | $tagsRow = array(); |
1839 | 1902 | } |
1840 | 1903 | } |
1841 | 1904 | |
1842 | - if (!empty($tagsRow)) |
|
1843 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
1905 | + if (!empty($tagsRow)) { |
|
1906 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
1907 | + } |
|
1844 | 1908 | } |
1845 | 1909 | |
1846 | - if (!empty($bbcodes_styles)) |
|
1847 | - addInlineCss($bbcodes_styles); |
|
1910 | + if (!empty($bbcodes_styles)) { |
|
1911 | + addInlineCss($bbcodes_styles); |
|
1912 | + } |
|
1848 | 1913 | } |
1849 | 1914 | |
1850 | 1915 | // Initialize smiley array... if not loaded before. |
@@ -1856,8 +1921,8 @@ discard block |
||
1856 | 1921 | ); |
1857 | 1922 | |
1858 | 1923 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
1859 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
1860 | - $context['smileys']['postform'][] = array( |
|
1924 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
1925 | + $context['smileys']['postform'][] = array( |
|
1861 | 1926 | 'smileys' => array( |
1862 | 1927 | array( |
1863 | 1928 | 'code' => ':)', |
@@ -1943,7 +2008,7 @@ discard block |
||
1943 | 2008 | ), |
1944 | 2009 | 'isLast' => true, |
1945 | 2010 | ); |
1946 | - elseif ($user_info['smiley_set'] != 'none') |
|
2011 | + } elseif ($user_info['smiley_set'] != 'none') |
|
1947 | 2012 | { |
1948 | 2013 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
1949 | 2014 | { |
@@ -1966,29 +2031,32 @@ discard block |
||
1966 | 2031 | |
1967 | 2032 | foreach ($context['smileys'] as $section => $smileyRows) |
1968 | 2033 | { |
1969 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
1970 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
2034 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
2035 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
2036 | + } |
|
1971 | 2037 | |
1972 | - if (!empty($smileyRows)) |
|
1973 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
2038 | + if (!empty($smileyRows)) { |
|
2039 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
2040 | + } |
|
1974 | 2041 | } |
1975 | 2042 | |
1976 | 2043 | cache_put_data('posting_smileys', $context['smileys'], 480); |
2044 | + } else { |
|
2045 | + $context['smileys'] = $temp; |
|
1977 | 2046 | } |
1978 | - else |
|
1979 | - $context['smileys'] = $temp; |
|
1980 | 2047 | } |
1981 | 2048 | |
1982 | 2049 | // Set proper extensions; do this post caching so cache doesn't become extension-specific |
1983 | 2050 | array_walk_recursive($context['smileys'], function (&$filename, $key) |
1984 | 2051 | { |
1985 | 2052 | global $context, $user_info, $modSettings; |
1986 | - if ($key == 'filename') |
|
1987 | - // Need to use the default if user selection is disabled |
|
2053 | + if ($key == 'filename') { |
|
2054 | + // Need to use the default if user selection is disabled |
|
1988 | 2055 | if (empty($modSettings['smiley_sets_enable'])) |
1989 | 2056 | $filename .= $context['user']['smiley_set_default_ext']; |
1990 | - else |
|
1991 | - $filename .= $user_info['smiley_set_ext']; |
|
2057 | + } else { |
|
2058 | + $filename .= $user_info['smiley_set_ext']; |
|
2059 | + } |
|
1992 | 2060 | |
1993 | 2061 | } |
1994 | 2062 | ); |
@@ -2006,12 +2074,15 @@ discard block |
||
2006 | 2074 | 'plugins' => '', |
2007 | 2075 | 'bbcodeTrim' => true, |
2008 | 2076 | ); |
2009 | - if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) |
|
2010 | - $sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale']; |
|
2011 | - if (!empty($context['right_to_left'])) |
|
2012 | - $sce_options['rtl'] = true; |
|
2013 | - if ($editorOptions['id'] != 'quickReply') |
|
2014 | - $sce_options['autofocus'] = true; |
|
2077 | + if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) { |
|
2078 | + $sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale']; |
|
2079 | + } |
|
2080 | + if (!empty($context['right_to_left'])) { |
|
2081 | + $sce_options['rtl'] = true; |
|
2082 | + } |
|
2083 | + if ($editorOptions['id'] != 'quickReply') { |
|
2084 | + $sce_options['autofocus'] = true; |
|
2085 | + } |
|
2015 | 2086 | |
2016 | 2087 | $sce_options['emoticons'] = array(); |
2017 | 2088 | $sce_options['emoticonsDescriptions'] = array(); |
@@ -2028,10 +2099,11 @@ discard block |
||
2028 | 2099 | $countLocations--; |
2029 | 2100 | |
2030 | 2101 | unset($smiley_location); |
2031 | - if ($location == 'postform') |
|
2032 | - $smiley_location = &$sce_options['emoticons']['dropdown']; |
|
2033 | - elseif ($location == 'popup') |
|
2034 | - $smiley_location = &$sce_options['emoticons']['popup']; |
|
2102 | + if ($location == 'postform') { |
|
2103 | + $smiley_location = &$sce_options['emoticons']['dropdown']; |
|
2104 | + } elseif ($location == 'popup') { |
|
2105 | + $smiley_location = &$sce_options['emoticons']['popup']; |
|
2106 | + } |
|
2035 | 2107 | |
2036 | 2108 | $numRows = count($smileyRows); |
2037 | 2109 | |
@@ -2045,8 +2117,9 @@ discard block |
||
2045 | 2117 | $sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description']; |
2046 | 2118 | } |
2047 | 2119 | |
2048 | - if (empty($smileyRow['isLast']) && $numRows != 1) |
|
2049 | - $smiley_location['-' . $emptyPlaceholder++] = ''; |
|
2120 | + if (empty($smileyRow['isLast']) && $numRows != 1) { |
|
2121 | + $smiley_location['-' . $emptyPlaceholder++] = ''; |
|
2122 | + } |
|
2050 | 2123 | } |
2051 | 2124 | } |
2052 | 2125 | } |
@@ -2061,8 +2134,9 @@ discard block |
||
2061 | 2134 | |
2062 | 2135 | $count_tags--; |
2063 | 2136 | |
2064 | - if (!empty($count_tags)) |
|
2065 | - $sce_options['toolbar'] .= '||'; |
|
2137 | + if (!empty($count_tags)) { |
|
2138 | + $sce_options['toolbar'] .= '||'; |
|
2139 | + } |
|
2066 | 2140 | } |
2067 | 2141 | } |
2068 | 2142 | |
@@ -2090,8 +2164,9 @@ discard block |
||
2090 | 2164 | loadTemplate('GenericControls'); |
2091 | 2165 | |
2092 | 2166 | // Some javascript ma'am? |
2093 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
2094 | - loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha'); |
|
2167 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
2168 | + loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha'); |
|
2169 | + } |
|
2095 | 2170 | |
2096 | 2171 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
2097 | 2172 | |
@@ -2104,8 +2179,8 @@ discard block |
||
2104 | 2179 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
2105 | 2180 | |
2106 | 2181 | // Log this into our collection. |
2107 | - if ($isNew) |
|
2108 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
2182 | + if ($isNew) { |
|
2183 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
2109 | 2184 | 'id' => $verificationOptions['id'], |
2110 | 2185 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
2111 | 2186 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2116,13 +2191,15 @@ discard block |
||
2116 | 2191 | 'questions' => array(), |
2117 | 2192 | 'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']), |
2118 | 2193 | ); |
2194 | + } |
|
2119 | 2195 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
2120 | 2196 | |
2121 | 2197 | // Is there actually going to be anything? |
2122 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) |
|
2123 | - return false; |
|
2124 | - elseif (!$isNew && !$do_test) |
|
2125 | - return true; |
|
2198 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) { |
|
2199 | + return false; |
|
2200 | + } elseif (!$isNew && !$do_test) { |
|
2201 | + return true; |
|
2202 | + } |
|
2126 | 2203 | |
2127 | 2204 | // Sanitize reCAPTCHA fields? |
2128 | 2205 | if ($thisVerification['can_recaptcha']) |
@@ -2135,11 +2212,12 @@ discard block |
||
2135 | 2212 | } |
2136 | 2213 | |
2137 | 2214 | // Add javascript for the object. |
2138 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
2139 | - $context['insert_after_template'] .= ' |
|
2215 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
2216 | + $context['insert_after_template'] .= ' |
|
2140 | 2217 | <script> |
2141 | 2218 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
2142 | 2219 | </script>'; |
2220 | + } |
|
2143 | 2221 | |
2144 | 2222 | // If we want questions do we have a cache of all the IDs? |
2145 | 2223 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2162,8 +2240,9 @@ discard block |
||
2162 | 2240 | unset ($row['id_question']); |
2163 | 2241 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
2164 | 2242 | $row['answers'] = $smcFunc['json_decode']($row['answers'], true); |
2165 | - foreach ($row['answers'] as $k => $v) |
|
2166 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
2243 | + foreach ($row['answers'] as $k => $v) { |
|
2244 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
2245 | + } |
|
2167 | 2246 | |
2168 | 2247 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
2169 | 2248 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2174,35 +2253,42 @@ discard block |
||
2174 | 2253 | } |
2175 | 2254 | } |
2176 | 2255 | |
2177 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
2178 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
2256 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
2257 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
2258 | + } |
|
2179 | 2259 | |
2180 | 2260 | // Do we need to refresh the verification? |
2181 | - if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) |
|
2182 | - $force_refresh = true; |
|
2183 | - else |
|
2184 | - $force_refresh = false; |
|
2261 | + if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) { |
|
2262 | + $force_refresh = true; |
|
2263 | + } else { |
|
2264 | + $force_refresh = false; |
|
2265 | + } |
|
2185 | 2266 | |
2186 | 2267 | // This can also force a fresh, although unlikely. |
2187 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
2188 | - $force_refresh = true; |
|
2268 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
2269 | + $force_refresh = true; |
|
2270 | + } |
|
2189 | 2271 | |
2190 | 2272 | $verification_errors = array(); |
2191 | 2273 | // Start with any testing. |
2192 | 2274 | if ($do_test) |
2193 | 2275 | { |
2194 | 2276 | // This cannot happen! |
2195 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
2196 | - fatal_lang_error('no_access', false); |
|
2277 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
2278 | + fatal_lang_error('no_access', false); |
|
2279 | + } |
|
2197 | 2280 | // ... nor this! |
2198 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
2199 | - fatal_lang_error('no_access', false); |
|
2281 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
2282 | + fatal_lang_error('no_access', false); |
|
2283 | + } |
|
2200 | 2284 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
2201 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
2202 | - fatal_lang_error('no_access', false); |
|
2285 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
2286 | + fatal_lang_error('no_access', false); |
|
2287 | + } |
|
2203 | 2288 | // While we're here, did the user do something bad? |
2204 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
2205 | - $verification_errors[] = 'wrong_verification_answer'; |
|
2289 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
2290 | + $verification_errors[] = 'wrong_verification_answer'; |
|
2291 | + } |
|
2206 | 2292 | |
2207 | 2293 | if ($thisVerification['can_recaptcha']) |
2208 | 2294 | { |
@@ -2213,22 +2299,25 @@ discard block |
||
2213 | 2299 | { |
2214 | 2300 | $resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']); |
2215 | 2301 | |
2216 | - if (!$resp->isSuccess()) |
|
2217 | - $verification_errors[] = 'wrong_verification_code'; |
|
2302 | + if (!$resp->isSuccess()) { |
|
2303 | + $verification_errors[] = 'wrong_verification_code'; |
|
2304 | + } |
|
2305 | + } else { |
|
2306 | + $verification_errors[] = 'wrong_verification_code'; |
|
2218 | 2307 | } |
2219 | - else |
|
2220 | - $verification_errors[] = 'wrong_verification_code'; |
|
2221 | 2308 | } |
2222 | - if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) |
|
2223 | - $verification_errors[] = 'wrong_verification_code'; |
|
2309 | + if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) { |
|
2310 | + $verification_errors[] = 'wrong_verification_code'; |
|
2311 | + } |
|
2224 | 2312 | if ($thisVerification['number_questions']) |
2225 | 2313 | { |
2226 | 2314 | $incorrectQuestions = array(); |
2227 | 2315 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
2228 | 2316 | { |
2229 | 2317 | // We don't have this question any more, thus no answers. |
2230 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
2231 | - continue; |
|
2318 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
2319 | + continue; |
|
2320 | + } |
|
2232 | 2321 | // This is quite complex. We have our question but it might have multiple answers. |
2233 | 2322 | // First, did they actually answer this question? |
2234 | 2323 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2240,24 +2329,28 @@ discard block |
||
2240 | 2329 | else |
2241 | 2330 | { |
2242 | 2331 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
2243 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
2244 | - $incorrectQuestions[] = $q; |
|
2332 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
2333 | + $incorrectQuestions[] = $q; |
|
2334 | + } |
|
2245 | 2335 | } |
2246 | 2336 | } |
2247 | 2337 | |
2248 | - if (!empty($incorrectQuestions)) |
|
2249 | - $verification_errors[] = 'wrong_verification_answer'; |
|
2338 | + if (!empty($incorrectQuestions)) { |
|
2339 | + $verification_errors[] = 'wrong_verification_answer'; |
|
2340 | + } |
|
2250 | 2341 | } |
2251 | 2342 | } |
2252 | 2343 | |
2253 | 2344 | // Any errors means we refresh potentially. |
2254 | 2345 | if (!empty($verification_errors)) |
2255 | 2346 | { |
2256 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
2257 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
2347 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
2348 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
2349 | + } |
|
2258 | 2350 | // Too many errors? |
2259 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
2260 | - $force_refresh = true; |
|
2351 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
2352 | + $force_refresh = true; |
|
2353 | + } |
|
2261 | 2354 | |
2262 | 2355 | // Keep a track of these. |
2263 | 2356 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2290,8 +2383,9 @@ discard block |
||
2290 | 2383 | // Are we overriding the range? |
2291 | 2384 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
2292 | 2385 | |
2293 | - for ($i = 0; $i < 6; $i++) |
|
2294 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
2386 | + for ($i = 0; $i < 6; $i++) { |
|
2387 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
2388 | + } |
|
2295 | 2389 | } |
2296 | 2390 | |
2297 | 2391 | // Getting some new questions? |
@@ -2299,8 +2393,9 @@ discard block |
||
2299 | 2393 | { |
2300 | 2394 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
2301 | 2395 | $possible_langs = array(); |
2302 | - if (isset($_SESSION['language'])) |
|
2303 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
2396 | + if (isset($_SESSION['language'])) { |
|
2397 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
2398 | + } |
|
2304 | 2399 | if (!empty($user_info['language'])); |
2305 | 2400 | $possible_langs[] = $user_info['language']; |
2306 | 2401 | $possible_langs[] = $language; |
@@ -2319,8 +2414,7 @@ discard block |
||
2319 | 2414 | } |
2320 | 2415 | } |
2321 | 2416 | } |
2322 | - } |
|
2323 | - else |
|
2417 | + } else |
|
2324 | 2418 | { |
2325 | 2419 | // Same questions as before. |
2326 | 2420 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2330,8 +2424,9 @@ discard block |
||
2330 | 2424 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
2331 | 2425 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
2332 | 2426 | { |
2333 | - if (!isset($context['html_headers'])) |
|
2334 | - $context['html_headers'] = ''; |
|
2427 | + if (!isset($context['html_headers'])) { |
|
2428 | + $context['html_headers'] = ''; |
|
2429 | + } |
|
2335 | 2430 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
2336 | 2431 | } |
2337 | 2432 | |
@@ -2357,11 +2452,13 @@ discard block |
||
2357 | 2452 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
2358 | 2453 | |
2359 | 2454 | // Return errors if we have them. |
2360 | - if (!empty($verification_errors)) |
|
2361 | - return $verification_errors; |
|
2455 | + if (!empty($verification_errors)) { |
|
2456 | + return $verification_errors; |
|
2457 | + } |
|
2362 | 2458 | // If we had a test that one, make a note. |
2363 | - elseif ($do_test) |
|
2364 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
2459 | + elseif ($do_test) { |
|
2460 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
2461 | + } |
|
2365 | 2462 | |
2366 | 2463 | // Say that everything went well chaps. |
2367 | 2464 | return true; |
@@ -2386,8 +2483,9 @@ discard block |
||
2386 | 2483 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
2387 | 2484 | |
2388 | 2485 | // If we're just checking the callback function is registered return true or false. |
2389 | - if ($checkRegistered != null) |
|
2390 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
2486 | + if ($checkRegistered != null) { |
|
2487 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
2488 | + } |
|
2391 | 2489 | |
2392 | 2490 | checkSession('get'); |
2393 | 2491 | loadTemplate('Xml'); |
@@ -2538,24 +2636,27 @@ discard block |
||
2538 | 2636 | foreach ($possible_versions as $ver) |
2539 | 2637 | { |
2540 | 2638 | $ver = trim($ver); |
2541 | - if (strpos($ver, 'SMF') === 0) |
|
2542 | - $versions[] = $ver; |
|
2639 | + if (strpos($ver, 'SMF') === 0) { |
|
2640 | + $versions[] = $ver; |
|
2641 | + } |
|
2543 | 2642 | } |
2544 | 2643 | } |
2545 | 2644 | $smcFunc['db_free_result']($request); |
2546 | 2645 | |
2547 | 2646 | // Just in case we don't have ANYthing. |
2548 | - if (empty($versions)) |
|
2549 | - $versions = array('SMF 2.0'); |
|
2647 | + if (empty($versions)) { |
|
2648 | + $versions = array('SMF 2.0'); |
|
2649 | + } |
|
2550 | 2650 | |
2551 | - foreach ($versions as $id => $version) |
|
2552 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
2651 | + foreach ($versions as $id => $version) { |
|
2652 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
2553 | 2653 | $xml_data['items']['children'][] = array( |
2554 | 2654 | 'attributes' => array( |
2555 | 2655 | 'id' => $id, |
2556 | 2656 | ), |
2557 | 2657 | 'value' => $version, |
2558 | 2658 | ); |
2659 | + } |
|
2559 | 2660 | |
2560 | 2661 | return $xml_data; |
2561 | 2662 | } |
@@ -75,8 +75,9 @@ discard block |
||
75 | 75 | $upcontext['inactive_timeout'] = 10; |
76 | 76 | |
77 | 77 | // The helper is crucial. Include it first thing. |
78 | -if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
|
78 | +if (!file_exists($upgrade_path . '/upgrade-helper.php')) { |
|
79 | 79 | die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
80 | +} |
|
80 | 81 | |
81 | 82 | require_once($upgrade_path . '/upgrade-helper.php'); |
82 | 83 | |
@@ -107,11 +108,14 @@ discard block |
||
107 | 108 | ini_set('default_socket_timeout', 900); |
108 | 109 | } |
109 | 110 | // Clean the upgrade path if this is from the client. |
110 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
111 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
111 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
112 | + for ($i = 1; |
|
113 | +} |
|
114 | +$i < $_SERVER['argc']; $i++) |
|
112 | 115 | { |
113 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
114 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
116 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
117 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
118 | + } |
|
115 | 119 | } |
116 | 120 | |
117 | 121 | // Are we from the client? |
@@ -119,16 +123,17 @@ discard block |
||
119 | 123 | { |
120 | 124 | $command_line = true; |
121 | 125 | $disable_security = true; |
122 | -} |
|
123 | -else |
|
126 | +} else { |
|
124 | 127 | $command_line = false; |
128 | +} |
|
125 | 129 | |
126 | 130 | // Load this now just because we can. |
127 | 131 | require_once($upgrade_path . '/Settings.php'); |
128 | 132 | |
129 | 133 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
130 | -if (isset($language)) |
|
134 | +if (isset($language)) { |
|
131 | 135 | $language = str_ireplace('-utf8', '', $language); |
136 | +} |
|
132 | 137 | |
133 | 138 | // Are we logged in? |
134 | 139 | if (isset($upgradeData)) |
@@ -136,10 +141,12 @@ discard block |
||
136 | 141 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
137 | 142 | |
138 | 143 | // Check for sensible values. |
139 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
140 | - $upcontext['user']['started'] = time(); |
|
141 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
142 | - $upcontext['user']['updated'] = 0; |
|
144 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
145 | + $upcontext['user']['started'] = time(); |
|
146 | + } |
|
147 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
148 | + $upcontext['user']['updated'] = 0; |
|
149 | + } |
|
143 | 150 | |
144 | 151 | $upcontext['started'] = $upcontext['user']['started']; |
145 | 152 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -204,8 +211,9 @@ discard block |
||
204 | 211 | 'db_error_skip' => true, |
205 | 212 | ) |
206 | 213 | ); |
207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
208 | - $modSettings[$row['variable']] = $row['value']; |
|
214 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
215 | + $modSettings[$row['variable']] = $row['value']; |
|
216 | + } |
|
209 | 217 | $smcFunc['db_free_result']($request); |
210 | 218 | } |
211 | 219 | |
@@ -215,14 +223,17 @@ discard block |
||
215 | 223 | $modSettings['theme_url'] = 'Themes/default'; |
216 | 224 | $modSettings['images_url'] = 'Themes/default/images'; |
217 | 225 | } |
218 | -if (!isset($settings['default_theme_url'])) |
|
226 | +if (!isset($settings['default_theme_url'])) { |
|
219 | 227 | $settings['default_theme_url'] = $modSettings['theme_url']; |
220 | -if (!isset($settings['default_theme_dir'])) |
|
228 | +} |
|
229 | +if (!isset($settings['default_theme_dir'])) { |
|
221 | 230 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
231 | +} |
|
222 | 232 | |
223 | 233 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
224 | -if (httpsOn()) |
|
234 | +if (httpsOn()) { |
|
225 | 235 | $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
236 | +} |
|
226 | 237 | |
227 | 238 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
228 | 239 | // Default title... |
@@ -240,13 +251,15 @@ discard block |
||
240 | 251 | $support_js = $upcontext['upgrade_status']['js']; |
241 | 252 | |
242 | 253 | // Only set this if the upgrader status says so. |
243 | - if (empty($is_debug)) |
|
244 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
254 | + if (empty($is_debug)) { |
|
255 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
256 | + } |
|
245 | 257 | |
246 | 258 | // Load the language. |
247 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
248 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
249 | -} |
|
259 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
260 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
261 | + } |
|
262 | + } |
|
250 | 263 | // Set the defaults. |
251 | 264 | else |
252 | 265 | { |
@@ -264,15 +277,18 @@ discard block |
||
264 | 277 | } |
265 | 278 | |
266 | 279 | // If this isn't the first stage see whether they are logging in and resuming. |
267 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
280 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
268 | 281 | checkLogin(); |
282 | +} |
|
269 | 283 | |
270 | -if ($command_line) |
|
284 | +if ($command_line) { |
|
271 | 285 | cmdStep0(); |
286 | +} |
|
272 | 287 | |
273 | 288 | // Don't error if we're using xml. |
274 | -if (isset($_GET['xml'])) |
|
289 | +if (isset($_GET['xml'])) { |
|
275 | 290 | $upcontext['return_error'] = true; |
291 | +} |
|
276 | 292 | |
277 | 293 | // Loop through all the steps doing each one as required. |
278 | 294 | $upcontext['overall_percent'] = 0; |
@@ -293,9 +309,9 @@ discard block |
||
293 | 309 | } |
294 | 310 | |
295 | 311 | // Call the step and if it returns false that means pause! |
296 | - if (function_exists($step[2]) && $step[2]() === false) |
|
297 | - break; |
|
298 | - elseif (function_exists($step[2])) { |
|
312 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
313 | + break; |
|
314 | + } elseif (function_exists($step[2])) { |
|
299 | 315 | //Start each new step with this unset, so the 'normal' template is called first |
300 | 316 | unset($_GET['xml']); |
301 | 317 | //Clear out warnings at the start of each step |
@@ -341,17 +357,18 @@ discard block |
||
341 | 357 | // This should not happen my dear... HELP ME DEVELOPERS!! |
342 | 358 | if (!empty($command_line)) |
343 | 359 | { |
344 | - if (function_exists('debug_print_backtrace')) |
|
345 | - debug_print_backtrace(); |
|
360 | + if (function_exists('debug_print_backtrace')) { |
|
361 | + debug_print_backtrace(); |
|
362 | + } |
|
346 | 363 | |
347 | 364 | echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; |
348 | 365 | flush(); |
349 | 366 | die(); |
350 | 367 | } |
351 | 368 | |
352 | - if (!isset($_GET['xml'])) |
|
353 | - template_upgrade_above(); |
|
354 | - else |
|
369 | + if (!isset($_GET['xml'])) { |
|
370 | + template_upgrade_above(); |
|
371 | + } else |
|
355 | 372 | { |
356 | 373 | header('content-type: text/xml; charset=UTF-8'); |
357 | 374 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -373,25 +390,29 @@ discard block |
||
373 | 390 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
374 | 391 | |
375 | 392 | // Custom stuff to pass back? |
376 | - if (!empty($upcontext['query_string'])) |
|
377 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
393 | + if (!empty($upcontext['query_string'])) { |
|
394 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
395 | + } |
|
378 | 396 | |
379 | 397 | // Call the appropriate subtemplate |
380 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
381 | - call_user_func('template_' . $upcontext['sub_template']); |
|
382 | - else |
|
383 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
398 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
399 | + call_user_func('template_' . $upcontext['sub_template']); |
|
400 | + } else { |
|
401 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
402 | + } |
|
384 | 403 | } |
385 | 404 | |
386 | 405 | // Was there an error? |
387 | - if (!empty($upcontext['forced_error_message'])) |
|
388 | - echo $upcontext['forced_error_message']; |
|
406 | + if (!empty($upcontext['forced_error_message'])) { |
|
407 | + echo $upcontext['forced_error_message']; |
|
408 | + } |
|
389 | 409 | |
390 | 410 | // Show the footer. |
391 | - if (!isset($_GET['xml'])) |
|
392 | - template_upgrade_below(); |
|
393 | - else |
|
394 | - template_xml_below(); |
|
411 | + if (!isset($_GET['xml'])) { |
|
412 | + template_upgrade_below(); |
|
413 | + } else { |
|
414 | + template_xml_below(); |
|
415 | + } |
|
395 | 416 | } |
396 | 417 | |
397 | 418 | // Show the upgrade time for CLI when we are completely done, if in debug mode. |
@@ -403,12 +424,13 @@ discard block |
||
403 | 424 | $seconds = intval($active % 60); |
404 | 425 | |
405 | 426 | $totalTime = ''; |
406 | - if ($hours > 0) |
|
407 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
408 | - elseif ($minutes > 0) |
|
409 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
410 | - elseif ($seconds > 0) |
|
411 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
427 | + if ($hours > 0) { |
|
428 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
429 | + } elseif ($minutes > 0) { |
|
430 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
431 | + } elseif ($seconds > 0) { |
|
432 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
433 | + } |
|
412 | 434 | } |
413 | 435 | |
414 | 436 | // Bang - gone! |
@@ -429,8 +451,9 @@ discard block |
||
429 | 451 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
430 | 452 | while ($entry = $dir->read()) |
431 | 453 | { |
432 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
433 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
454 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
455 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
456 | + } |
|
434 | 457 | } |
435 | 458 | $dir->close(); |
436 | 459 | } |
@@ -474,10 +497,11 @@ discard block |
||
474 | 497 | } |
475 | 498 | |
476 | 499 | // Override the language file? |
477 | - if (isset($_GET['lang_file'])) |
|
478 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
479 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
480 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
500 | + if (isset($_GET['lang_file'])) { |
|
501 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
502 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
503 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
504 | + } |
|
481 | 505 | |
482 | 506 | // Make sure it exists, if it doesn't reset it. |
483 | 507 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -486,12 +510,14 @@ discard block |
||
486 | 510 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
487 | 511 | |
488 | 512 | // If we have english and some other language, use the other language. We Americans hate english :P. |
489 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
490 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
513 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
514 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
515 | + } |
|
491 | 516 | |
492 | 517 | // For backup we load the english at first -> second language overwrite the english one |
493 | - if (count($incontext['detected_languages']) > 1) |
|
494 | - require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
518 | + if (count($incontext['detected_languages']) > 1) { |
|
519 | + require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
520 | + } |
|
495 | 521 | } |
496 | 522 | |
497 | 523 | // And now include the actual language file itself. |
@@ -499,11 +525,12 @@ discard block |
||
499 | 525 | |
500 | 526 | // Which language did we load? Assume that he likes his language. |
501 | 527 | preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches); |
502 | - if (empty($matches[1])) |
|
503 | - $matches = [ |
|
528 | + if (empty($matches[1])) { |
|
529 | + $matches = [ |
|
504 | 530 | 0 => 'nothing', |
505 | 531 | 1 => 'english', |
506 | 532 | ]; |
533 | + } |
|
507 | 534 | $user_info['language'] = $matches[1]; |
508 | 535 | } |
509 | 536 | |
@@ -513,8 +540,9 @@ discard block |
||
513 | 540 | global $upgradeurl, $upcontext, $command_line; |
514 | 541 | |
515 | 542 | // Command line users can't be redirected. |
516 | - if ($command_line) |
|
517 | - upgradeExit(true); |
|
543 | + if ($command_line) { |
|
544 | + upgradeExit(true); |
|
545 | + } |
|
518 | 546 | |
519 | 547 | // Are we providing the core info? |
520 | 548 | if ($addForm) |
@@ -540,12 +568,14 @@ discard block |
||
540 | 568 | define('SMF', 1); |
541 | 569 | |
542 | 570 | // Start the session. |
543 | - if (@ini_get('session.save_handler') == 'user') |
|
544 | - @ini_set('session.save_handler', 'files'); |
|
571 | + if (@ini_get('session.save_handler') == 'user') { |
|
572 | + @ini_set('session.save_handler', 'files'); |
|
573 | + } |
|
545 | 574 | @session_start(); |
546 | 575 | |
547 | - if (empty($smcFunc)) |
|
548 | - $smcFunc = array(); |
|
576 | + if (empty($smcFunc)) { |
|
577 | + $smcFunc = array(); |
|
578 | + } |
|
549 | 579 | |
550 | 580 | // We need this for authentication and some upgrade code |
551 | 581 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -576,30 +606,34 @@ discard block |
||
576 | 606 | { |
577 | 607 | $options = array('non_fatal' => true); |
578 | 608 | // Add in the port if needed |
579 | - if (!empty($db_port)) |
|
580 | - $options['port'] = $db_port; |
|
609 | + if (!empty($db_port)) { |
|
610 | + $options['port'] = $db_port; |
|
611 | + } |
|
581 | 612 | |
582 | - if (!empty($db_mb4)) |
|
583 | - $options['db_mb4'] = $db_mb4; |
|
613 | + if (!empty($db_mb4)) { |
|
614 | + $options['db_mb4'] = $db_mb4; |
|
615 | + } |
|
584 | 616 | |
585 | 617 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
586 | - } |
|
587 | - else |
|
588 | - // If we've returned here, ping/reconnect to be safe |
|
618 | + } else { |
|
619 | + // If we've returned here, ping/reconnect to be safe |
|
589 | 620 | $smcFunc['db_ping']($db_connection); |
621 | + } |
|
590 | 622 | |
591 | 623 | // Oh dear god!! |
592 | - if ($db_connection === null) |
|
593 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
624 | + if ($db_connection === null) { |
|
625 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
626 | + } |
|
594 | 627 | |
595 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
596 | - $smcFunc['db_query']('', ' |
|
628 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
629 | + $smcFunc['db_query']('', ' |
|
597 | 630 | SET NAMES {string:db_character_set}', |
598 | 631 | array( |
599 | 632 | 'db_error_skip' => true, |
600 | 633 | 'db_character_set' => $db_character_set, |
601 | 634 | ) |
602 | 635 | ); |
636 | + } |
|
603 | 637 | |
604 | 638 | // Load the modSettings data... |
605 | 639 | $request = $smcFunc['db_query']('', ' |
@@ -610,11 +644,11 @@ discard block |
||
610 | 644 | ) |
611 | 645 | ); |
612 | 646 | $modSettings = array(); |
613 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
614 | - $modSettings[$row['variable']] = $row['value']; |
|
647 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
648 | + $modSettings[$row['variable']] = $row['value']; |
|
649 | + } |
|
615 | 650 | $smcFunc['db_free_result']($request); |
616 | - } |
|
617 | - else |
|
651 | + } else |
|
618 | 652 | { |
619 | 653 | return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); |
620 | 654 | } |
@@ -628,9 +662,10 @@ discard block |
||
628 | 662 | cleanRequest(); |
629 | 663 | } |
630 | 664 | |
631 | - if (!isset($_GET['substep'])) |
|
632 | - $_GET['substep'] = 0; |
|
633 | -} |
|
665 | + if (!isset($_GET['substep'])) { |
|
666 | + $_GET['substep'] = 0; |
|
667 | + } |
|
668 | + } |
|
634 | 669 | |
635 | 670 | function initialize_inputs() |
636 | 671 | { |
@@ -660,8 +695,9 @@ discard block |
||
660 | 695 | $dh = opendir(dirname(__FILE__)); |
661 | 696 | while ($file = readdir($dh)) |
662 | 697 | { |
663 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
664 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
698 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
699 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
700 | + } |
|
665 | 701 | } |
666 | 702 | closedir($dh); |
667 | 703 | |
@@ -690,8 +726,9 @@ discard block |
||
690 | 726 | $temp = 'upgrade_php?step'; |
691 | 727 | while (strlen($temp) > 4) |
692 | 728 | { |
693 | - if (isset($_GET[$temp])) |
|
694 | - unset($_GET[$temp]); |
|
729 | + if (isset($_GET[$temp])) { |
|
730 | + unset($_GET[$temp]); |
|
731 | + } |
|
695 | 732 | $temp = substr($temp, 1); |
696 | 733 | } |
697 | 734 | |
@@ -718,32 +755,39 @@ discard block |
||
718 | 755 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
719 | 756 | |
720 | 757 | // Need legacy scripts? |
721 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
722 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
723 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
724 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
725 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
726 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
758 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
759 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
760 | + } |
|
761 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
762 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
763 | + } |
|
764 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
765 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
766 | + } |
|
727 | 767 | |
728 | 768 | // We don't need "-utf8" files anymore... |
729 | 769 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
730 | 770 | |
731 | 771 | // This needs to exist! |
732 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
733 | - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
734 | - else |
|
735 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
772 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
773 | + return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
774 | + } else { |
|
775 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
776 | + } |
|
736 | 777 | |
737 | - if (!$check) |
|
738 | - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
778 | + if (!$check) { |
|
779 | + // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
739 | 780 | return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); |
781 | + } |
|
740 | 782 | |
741 | 783 | // Do they meet the install requirements? |
742 | - if (!php_version_check()) |
|
743 | - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
784 | + if (!php_version_check()) { |
|
785 | + return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
786 | + } |
|
744 | 787 | |
745 | - if (!db_version_check()) |
|
746 | - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
788 | + if (!db_version_check()) { |
|
789 | + return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
790 | + } |
|
747 | 791 | |
748 | 792 | // Do some checks to make sure they have proper privileges |
749 | 793 | db_extend('packages'); |
@@ -758,14 +802,16 @@ discard block |
||
758 | 802 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
759 | 803 | |
760 | 804 | // Sorry... we need CREATE, ALTER and DROP |
761 | - if (!$create || !$alter || !$drop) |
|
762 | - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
805 | + if (!$create || !$alter || !$drop) { |
|
806 | + return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
807 | + } |
|
763 | 808 | |
764 | 809 | // Do a quick version spot check. |
765 | 810 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
766 | 811 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
767 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
768 | - return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
812 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
813 | + return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
814 | + } |
|
769 | 815 | |
770 | 816 | // What absolutely needs to be writable? |
771 | 817 | $writable_files = array( |
@@ -774,12 +820,13 @@ discard block |
||
774 | 820 | ); |
775 | 821 | |
776 | 822 | // Only check for minified writable files if we have it enabled or not set. |
777 | - if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) |
|
778 | - $writable_files += array( |
|
823 | + if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) { |
|
824 | + $writable_files += array( |
|
779 | 825 | $modSettings['theme_dir'] . '/css/minified.css', |
780 | 826 | $modSettings['theme_dir'] . '/scripts/minified.js', |
781 | 827 | $modSettings['theme_dir'] . '/scripts/minified_deferred.js', |
782 | 828 | ); |
829 | + } |
|
783 | 830 | |
784 | 831 | // Do we need to add this setting? |
785 | 832 | $need_settings_update = empty($modSettings['custom_avatar_dir']); |
@@ -791,12 +838,13 @@ discard block |
||
791 | 838 | quickFileWritable($custom_av_dir); |
792 | 839 | |
793 | 840 | // Are we good now? |
794 | - if (!is_writable($custom_av_dir)) |
|
795 | - return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
796 | - elseif ($need_settings_update) |
|
841 | + if (!is_writable($custom_av_dir)) { |
|
842 | + return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
843 | + } elseif ($need_settings_update) |
|
797 | 844 | { |
798 | - if (!function_exists('cache_put_data')) |
|
799 | - require_once($sourcedir . '/Load.php'); |
|
845 | + if (!function_exists('cache_put_data')) { |
|
846 | + require_once($sourcedir . '/Load.php'); |
|
847 | + } |
|
800 | 848 | |
801 | 849 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
802 | 850 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
@@ -806,29 +854,34 @@ discard block |
||
806 | 854 | |
807 | 855 | // Check the cache directory. |
808 | 856 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
809 | - if (!file_exists($cachedir_temp)) |
|
810 | - @mkdir($cachedir_temp); |
|
857 | + if (!file_exists($cachedir_temp)) { |
|
858 | + @mkdir($cachedir_temp); |
|
859 | + } |
|
811 | 860 | |
812 | - if (!file_exists($cachedir_temp)) |
|
813 | - return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
861 | + if (!file_exists($cachedir_temp)) { |
|
862 | + return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
863 | + } |
|
814 | 864 | |
815 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
816 | - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
817 | - elseif (!isset($_GET['skiplang'])) |
|
865 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
866 | + return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
867 | + } elseif (!isset($_GET['skiplang'])) |
|
818 | 868 | { |
819 | 869 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
820 | 870 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
821 | 871 | |
822 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
823 | - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
872 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
873 | + return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
874 | + } |
|
824 | 875 | } |
825 | 876 | |
826 | - if (!makeFilesWritable($writable_files)) |
|
827 | - return false; |
|
877 | + if (!makeFilesWritable($writable_files)) { |
|
878 | + return false; |
|
879 | + } |
|
828 | 880 | |
829 | 881 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
830 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
831 | - return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
882 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
883 | + return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
884 | + } |
|
832 | 885 | |
833 | 886 | // Upgrade the agreement. |
834 | 887 | elseif (isset($modSettings['agreement'])) |
@@ -839,8 +892,8 @@ discard block |
||
839 | 892 | } |
840 | 893 | |
841 | 894 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
842 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
843 | - $upcontext['warning'] = ' |
|
895 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
896 | + $upcontext['warning'] = ' |
|
844 | 897 | '. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br> |
845 | 898 | <ul> |
846 | 899 | <li>'. $txt['upgrade_boarddir'] .' ' . $boarddir . '</li> |
@@ -848,19 +901,23 @@ discard block |
||
848 | 901 | <li>'. $txt['upgrade_cachedir'] .' ' . $cachedir_temp . '</li> |
849 | 902 | </ul> |
850 | 903 | '. $txt['upgrade_incorrect_settings'] .''; |
904 | + } |
|
851 | 905 | |
852 | 906 | // Confirm mbstring is loaded... |
853 | - if (!extension_loaded('mbstring')) |
|
854 | - return throw_error($txt['install_no_mbstring']); |
|
907 | + if (!extension_loaded('mbstring')) { |
|
908 | + return throw_error($txt['install_no_mbstring']); |
|
909 | + } |
|
855 | 910 | |
856 | 911 | // Check for https stream support. |
857 | 912 | $supported_streams = stream_get_wrappers(); |
858 | - if (!in_array('https', $supported_streams)) |
|
859 | - $upcontext['custom_warning'] = $txt['install_no_https']; |
|
913 | + if (!in_array('https', $supported_streams)) { |
|
914 | + $upcontext['custom_warning'] = $txt['install_no_https']; |
|
915 | + } |
|
860 | 916 | |
861 | 917 | // Either we're logged in or we're going to present the login. |
862 | - if (checkLogin()) |
|
863 | - return true; |
|
918 | + if (checkLogin()) { |
|
919 | + return true; |
|
920 | + } |
|
864 | 921 | |
865 | 922 | $upcontext += createToken('login'); |
866 | 923 | |
@@ -874,15 +931,17 @@ discard block |
||
874 | 931 | global $smcFunc, $db_type, $support_js; |
875 | 932 | |
876 | 933 | // Don't bother if the security is disabled. |
877 | - if ($disable_security) |
|
878 | - return true; |
|
934 | + if ($disable_security) { |
|
935 | + return true; |
|
936 | + } |
|
879 | 937 | |
880 | 938 | // Are we trying to login? |
881 | 939 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
882 | 940 | { |
883 | 941 | // If we've disabled security pick a suitable name! |
884 | - if (empty($_POST['user'])) |
|
885 | - $_POST['user'] = 'Administrator'; |
|
942 | + if (empty($_POST['user'])) { |
|
943 | + $_POST['user'] = 'Administrator'; |
|
944 | + } |
|
886 | 945 | |
887 | 946 | // Before 2.0 these column names were different! |
888 | 947 | $oldDB = false; |
@@ -897,16 +956,17 @@ discard block |
||
897 | 956 | 'db_error_skip' => true, |
898 | 957 | ) |
899 | 958 | ); |
900 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
901 | - $oldDB = true; |
|
959 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
960 | + $oldDB = true; |
|
961 | + } |
|
902 | 962 | $smcFunc['db_free_result']($request); |
903 | 963 | } |
904 | 964 | |
905 | 965 | // Get what we believe to be their details. |
906 | 966 | if (!$disable_security) |
907 | 967 | { |
908 | - if ($oldDB) |
|
909 | - $request = $smcFunc['db_query']('', ' |
|
968 | + if ($oldDB) { |
|
969 | + $request = $smcFunc['db_query']('', ' |
|
910 | 970 | SELECT id_member, memberName AS member_name, passwd, id_group, |
911 | 971 | additionalGroups AS additional_groups, lngfile |
912 | 972 | FROM {db_prefix}members |
@@ -916,8 +976,8 @@ discard block |
||
916 | 976 | 'db_error_skip' => true, |
917 | 977 | ) |
918 | 978 | ); |
919 | - else |
|
920 | - $request = $smcFunc['db_query']('', ' |
|
979 | + } else { |
|
980 | + $request = $smcFunc['db_query']('', ' |
|
921 | 981 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
922 | 982 | FROM {db_prefix}members |
923 | 983 | WHERE member_name = {string:member_name}', |
@@ -926,6 +986,7 @@ discard block |
||
926 | 986 | 'db_error_skip' => true, |
927 | 987 | ) |
928 | 988 | ); |
989 | + } |
|
929 | 990 | if ($smcFunc['db_num_rows']($request) != 0) |
930 | 991 | { |
931 | 992 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -933,16 +994,17 @@ discard block |
||
933 | 994 | $groups = explode(',', $addGroups); |
934 | 995 | $groups[] = $id_group; |
935 | 996 | |
936 | - foreach ($groups as $k => $v) |
|
937 | - $groups[$k] = (int) $v; |
|
997 | + foreach ($groups as $k => $v) { |
|
998 | + $groups[$k] = (int) $v; |
|
999 | + } |
|
938 | 1000 | |
939 | 1001 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
940 | 1002 | |
941 | 1003 | // We don't use "-utf8" anymore... |
942 | 1004 | $user_language = str_ireplace('-utf8', '', $user_language); |
1005 | + } else { |
|
1006 | + $upcontext['username_incorrect'] = true; |
|
943 | 1007 | } |
944 | - else |
|
945 | - $upcontext['username_incorrect'] = true; |
|
946 | 1008 | |
947 | 1009 | $smcFunc['db_free_result']($request); |
948 | 1010 | } |
@@ -953,13 +1015,14 @@ discard block |
||
953 | 1015 | { |
954 | 1016 | $upcontext['upgrade_status']['js'] = 1; |
955 | 1017 | $support_js = 1; |
1018 | + } else { |
|
1019 | + $support_js = 0; |
|
956 | 1020 | } |
957 | - else |
|
958 | - $support_js = 0; |
|
959 | 1021 | |
960 | 1022 | // Note down the version we are coming from. |
961 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
962 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
1023 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
1024 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
1025 | + } |
|
963 | 1026 | |
964 | 1027 | // Didn't get anywhere? |
965 | 1028 | if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect'])) |
@@ -993,15 +1056,15 @@ discard block |
||
993 | 1056 | 'db_error_skip' => true, |
994 | 1057 | ) |
995 | 1058 | ); |
996 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
997 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
1059 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1060 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
1061 | + } |
|
998 | 1062 | $smcFunc['db_free_result']($request); |
999 | 1063 | } |
1000 | 1064 | |
1001 | 1065 | $upcontext['user']['id'] = $id_member; |
1002 | 1066 | $upcontext['user']['name'] = $name; |
1003 | - } |
|
1004 | - else |
|
1067 | + } else |
|
1005 | 1068 | { |
1006 | 1069 | $upcontext['user']['id'] = 1; |
1007 | 1070 | $upcontext['user']['name'] = 'Administrator'; |
@@ -1017,11 +1080,11 @@ discard block |
||
1017 | 1080 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
1018 | 1081 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
1019 | 1082 | |
1020 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
1021 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1022 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
1023 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1024 | - else |
|
1083 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
1084 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1085 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
1086 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
1087 | + } else |
|
1025 | 1088 | { |
1026 | 1089 | // Set this as the new language. |
1027 | 1090 | $upcontext['language'] = $user_language; |
@@ -1068,8 +1131,9 @@ discard block |
||
1068 | 1131 | $upcontext['migrateSettingsNeeded'] = detectSettingsFileMigrationNeeded() ? 1 : 0; |
1069 | 1132 | |
1070 | 1133 | // If we've not submitted then we're done. |
1071 | - if (empty($_POST['upcont'])) |
|
1072 | - return false; |
|
1134 | + if (empty($_POST['upcont'])) { |
|
1135 | + return false; |
|
1136 | + } |
|
1073 | 1137 | |
1074 | 1138 | // Firstly, if they're enabling SM stat collection just do it. |
1075 | 1139 | if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) |
@@ -1089,16 +1153,17 @@ discard block |
||
1089 | 1153 | fwrite($fp, $out); |
1090 | 1154 | |
1091 | 1155 | $return_data = ''; |
1092 | - while (!feof($fp)) |
|
1093 | - $return_data .= fgets($fp, 128); |
|
1156 | + while (!feof($fp)) { |
|
1157 | + $return_data .= fgets($fp, 128); |
|
1158 | + } |
|
1094 | 1159 | |
1095 | 1160 | fclose($fp); |
1096 | 1161 | |
1097 | 1162 | // Get the unique site ID. |
1098 | 1163 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1099 | 1164 | |
1100 | - if (!empty($ID[1])) |
|
1101 | - $smcFunc['db_insert']('replace', |
|
1165 | + if (!empty($ID[1])) { |
|
1166 | + $smcFunc['db_insert']('replace', |
|
1102 | 1167 | $db_prefix . 'settings', |
1103 | 1168 | array('variable' => 'string', 'value' => 'string'), |
1104 | 1169 | array( |
@@ -1107,9 +1172,9 @@ discard block |
||
1107 | 1172 | ), |
1108 | 1173 | array('variable') |
1109 | 1174 | ); |
1175 | + } |
|
1110 | 1176 | } |
1111 | - } |
|
1112 | - else |
|
1177 | + } else |
|
1113 | 1178 | { |
1114 | 1179 | $smcFunc['db_insert']('replace', |
1115 | 1180 | $db_prefix . 'settings', |
@@ -1120,8 +1185,8 @@ discard block |
||
1120 | 1185 | } |
1121 | 1186 | } |
1122 | 1187 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
1123 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
1124 | - $smcFunc['db_query']('', ' |
|
1188 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
1189 | + $smcFunc['db_query']('', ' |
|
1125 | 1190 | DELETE FROM {db_prefix}settings |
1126 | 1191 | WHERE variable = {string:enable_sm_stats}', |
1127 | 1192 | array( |
@@ -1129,6 +1194,7 @@ discard block |
||
1129 | 1194 | 'db_error_skip' => true, |
1130 | 1195 | ) |
1131 | 1196 | ); |
1197 | + } |
|
1132 | 1198 | |
1133 | 1199 | // Deleting old karma stuff? |
1134 | 1200 | if (!empty($_POST['delete_karma'])) |
@@ -1143,20 +1209,22 @@ discard block |
||
1143 | 1209 | ); |
1144 | 1210 | |
1145 | 1211 | // Cleaning up old karma member settings. |
1146 | - if ($upcontext['karma_installed']['good']) |
|
1147 | - $smcFunc['db_query']('', ' |
|
1212 | + if ($upcontext['karma_installed']['good']) { |
|
1213 | + $smcFunc['db_query']('', ' |
|
1148 | 1214 | ALTER TABLE {db_prefix}members |
1149 | 1215 | DROP karma_good', |
1150 | 1216 | array() |
1151 | 1217 | ); |
1218 | + } |
|
1152 | 1219 | |
1153 | 1220 | // Does karma bad was enable? |
1154 | - if ($upcontext['karma_installed']['bad']) |
|
1155 | - $smcFunc['db_query']('', ' |
|
1221 | + if ($upcontext['karma_installed']['bad']) { |
|
1222 | + $smcFunc['db_query']('', ' |
|
1156 | 1223 | ALTER TABLE {db_prefix}members |
1157 | 1224 | DROP karma_bad', |
1158 | 1225 | array() |
1159 | 1226 | ); |
1227 | + } |
|
1160 | 1228 | |
1161 | 1229 | // Cleaning up old karma permissions. |
1162 | 1230 | $smcFunc['db_query']('', ' |
@@ -1174,32 +1242,37 @@ discard block |
||
1174 | 1242 | } |
1175 | 1243 | |
1176 | 1244 | // Emptying the error log? |
1177 | - if (!empty($_POST['empty_error'])) |
|
1178 | - $smcFunc['db_query']('truncate_table', ' |
|
1245 | + if (!empty($_POST['empty_error'])) { |
|
1246 | + $smcFunc['db_query']('truncate_table', ' |
|
1179 | 1247 | TRUNCATE {db_prefix}log_errors', |
1180 | 1248 | array( |
1181 | 1249 | ) |
1182 | 1250 | ); |
1251 | + } |
|
1183 | 1252 | |
1184 | 1253 | $changes = array(); |
1185 | 1254 | |
1186 | 1255 | // Add proxy settings. |
1187 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
1188 | - $changes += array( |
|
1256 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
1257 | + $changes += array( |
|
1189 | 1258 | 'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'', |
1190 | 1259 | 'image_proxy_maxsize' => 5190, |
1191 | 1260 | 'image_proxy_enabled' => 0, |
1192 | 1261 | ); |
1262 | + } |
|
1193 | 1263 | |
1194 | 1264 | // If $boardurl reflects https, set force_ssl |
1195 | - if (!function_exists('cache_put_data')) |
|
1196 | - require_once($sourcedir . '/Load.php'); |
|
1197 | - if (stripos($boardurl, 'https://') !== false) |
|
1198 | - updateSettings(array('force_ssl' => '1')); |
|
1265 | + if (!function_exists('cache_put_data')) { |
|
1266 | + require_once($sourcedir . '/Load.php'); |
|
1267 | + } |
|
1268 | + if (stripos($boardurl, 'https://') !== false) { |
|
1269 | + updateSettings(array('force_ssl' => '1')); |
|
1270 | + } |
|
1199 | 1271 | |
1200 | 1272 | // If we're overriding the language follow it through. |
1201 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
1202 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1273 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
1274 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
1275 | + } |
|
1203 | 1276 | |
1204 | 1277 | if (!empty($_POST['maint'])) |
1205 | 1278 | { |
@@ -1211,26 +1284,29 @@ discard block |
||
1211 | 1284 | { |
1212 | 1285 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
1213 | 1286 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
1214 | - } |
|
1215 | - else |
|
1287 | + } else |
|
1216 | 1288 | { |
1217 | 1289 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
1218 | 1290 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
1219 | 1291 | } |
1220 | 1292 | } |
1221 | 1293 | |
1222 | - if ($command_line) |
|
1223 | - echo ' * Updating Settings.php...'; |
|
1294 | + if ($command_line) { |
|
1295 | + echo ' * Updating Settings.php...'; |
|
1296 | + } |
|
1224 | 1297 | |
1225 | 1298 | // Fix some old paths. |
1226 | - if (substr($boarddir, 0, 1) == '.') |
|
1227 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1299 | + if (substr($boarddir, 0, 1) == '.') { |
|
1300 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
1301 | + } |
|
1228 | 1302 | |
1229 | - if (substr($sourcedir, 0, 1) == '.') |
|
1230 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1303 | + if (substr($sourcedir, 0, 1) == '.') { |
|
1304 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
1305 | + } |
|
1231 | 1306 | |
1232 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
1233 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1307 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
1308 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
1309 | + } |
|
1234 | 1310 | |
1235 | 1311 | // If they have a "host:port" setup for the host, split that into separate values |
1236 | 1312 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1241,32 +1317,36 @@ discard block |
||
1241 | 1317 | $changes['db_server'] = '\'' . $db_server . '\''; |
1242 | 1318 | |
1243 | 1319 | // Only set this if we're not using the default port |
1244 | - if ($db_port != ini_get('mysqli.default_port')) |
|
1245 | - $changes['db_port'] = (int) $db_port; |
|
1246 | - } |
|
1247 | - elseif (!empty($db_port)) |
|
1320 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
1321 | + $changes['db_port'] = (int) $db_port; |
|
1322 | + } |
|
1323 | + } elseif (!empty($db_port)) |
|
1248 | 1324 | { |
1249 | 1325 | // If db_port is set and is the same as the default, set it to '' |
1250 | 1326 | if ($db_type == 'mysql') |
1251 | 1327 | { |
1252 | - if ($db_port == ini_get('mysqli.default_port')) |
|
1253 | - $changes['db_port'] = '\'\''; |
|
1254 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
1255 | - $changes['db_port'] = '\'\''; |
|
1328 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
1329 | + $changes['db_port'] = '\'\''; |
|
1330 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
1331 | + $changes['db_port'] = '\'\''; |
|
1332 | + } |
|
1256 | 1333 | } |
1257 | 1334 | } |
1258 | 1335 | |
1259 | 1336 | // Maybe we haven't had this option yet? |
1260 | - if (empty($packagesdir)) |
|
1261 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1337 | + if (empty($packagesdir)) { |
|
1338 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
1339 | + } |
|
1262 | 1340 | |
1263 | 1341 | // Add support for $tasksdir var. |
1264 | - if (empty($tasksdir)) |
|
1265 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1342 | + if (empty($tasksdir)) { |
|
1343 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
1344 | + } |
|
1266 | 1345 | |
1267 | 1346 | // Make sure we fix the language as well. |
1268 | - if (stristr($language, '-utf8')) |
|
1269 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
1347 | + if (stristr($language, '-utf8')) { |
|
1348 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
1349 | + } |
|
1270 | 1350 | |
1271 | 1351 | // @todo Maybe change the cookie name if going to 1.1, too? |
1272 | 1352 | |
@@ -1277,8 +1357,7 @@ discard block |
||
1277 | 1357 | $changes['upgradeData'] = '"' . base64_encode(json_encode($upcontext['user'])) . '"'; |
1278 | 1358 | |
1279 | 1359 | migrateSettingsFile($changes); |
1280 | - } |
|
1281 | - else |
|
1360 | + } else |
|
1282 | 1361 | { |
1283 | 1362 | // Update Settings.php with the new settings. |
1284 | 1363 | require_once($sourcedir . '/Subs-Admin.php'); |
@@ -1288,8 +1367,9 @@ discard block |
||
1288 | 1367 | move_db_last_error_to_cachedir(); |
1289 | 1368 | } |
1290 | 1369 | |
1291 | - if ($command_line) |
|
1292 | - echo ' Successful.' . "\n"; |
|
1370 | + if ($command_line) { |
|
1371 | + echo ' Successful.' . "\n"; |
|
1372 | + } |
|
1293 | 1373 | |
1294 | 1374 | // Are we doing debug? |
1295 | 1375 | if (isset($_POST['debug'])) |
@@ -1299,8 +1379,9 @@ discard block |
||
1299 | 1379 | } |
1300 | 1380 | |
1301 | 1381 | // If we're not backing up then jump one. |
1302 | - if (empty($_POST['backup'])) |
|
1303 | - $upcontext['current_step']++; |
|
1382 | + if (empty($_POST['backup'])) { |
|
1383 | + $upcontext['current_step']++; |
|
1384 | + } |
|
1304 | 1385 | |
1305 | 1386 | // If we've got here then let's proceed to the next step! |
1306 | 1387 | return true; |
@@ -1315,8 +1396,9 @@ discard block |
||
1315 | 1396 | $upcontext['page_title'] = $txt['backup_database']; |
1316 | 1397 | |
1317 | 1398 | // Done it already - js wise? |
1318 | - if (!empty($_POST['backup_done'])) |
|
1319 | - return true; |
|
1399 | + if (!empty($_POST['backup_done'])) { |
|
1400 | + return true; |
|
1401 | + } |
|
1320 | 1402 | |
1321 | 1403 | // Some useful stuff here. |
1322 | 1404 | db_extend(); |
@@ -1330,9 +1412,10 @@ discard block |
||
1330 | 1412 | $tables = $smcFunc['db_list_tables']($db, $filter); |
1331 | 1413 | |
1332 | 1414 | $table_names = array(); |
1333 | - foreach ($tables as $table) |
|
1334 | - if (substr($table, 0, 7) !== 'backup_') |
|
1415 | + foreach ($tables as $table) { |
|
1416 | + if (substr($table, 0, 7) !== 'backup_') |
|
1335 | 1417 | $table_names[] = $table; |
1418 | + } |
|
1336 | 1419 | |
1337 | 1420 | $upcontext['table_count'] = count($table_names); |
1338 | 1421 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1342,12 +1425,14 @@ discard block |
||
1342 | 1425 | $file_steps = $upcontext['table_count']; |
1343 | 1426 | |
1344 | 1427 | // What ones have we already done? |
1345 | - foreach ($table_names as $id => $table) |
|
1346 | - if ($id < $_GET['substep']) |
|
1428 | + foreach ($table_names as $id => $table) { |
|
1429 | + if ($id < $_GET['substep']) |
|
1347 | 1430 | $upcontext['previous_tables'][] = $table; |
1431 | + } |
|
1348 | 1432 | |
1349 | - if ($command_line) |
|
1350 | - echo 'Backing Up Tables.'; |
|
1433 | + if ($command_line) { |
|
1434 | + echo 'Backing Up Tables.'; |
|
1435 | + } |
|
1351 | 1436 | |
1352 | 1437 | // If we don't support javascript we backup here. |
1353 | 1438 | if (!$support_js || isset($_GET['xml'])) |
@@ -1366,8 +1451,9 @@ discard block |
||
1366 | 1451 | backupTable($table_names[$substep]); |
1367 | 1452 | |
1368 | 1453 | // If this is XML to keep it nice for the user do one table at a time anyway! |
1369 | - if (isset($_GET['xml'])) |
|
1370 | - return upgradeExit(); |
|
1454 | + if (isset($_GET['xml'])) { |
|
1455 | + return upgradeExit(); |
|
1456 | + } |
|
1371 | 1457 | } |
1372 | 1458 | |
1373 | 1459 | if ($command_line) |
@@ -1400,9 +1486,10 @@ discard block |
||
1400 | 1486 | |
1401 | 1487 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
1402 | 1488 | |
1403 | - if ($command_line) |
|
1404 | - echo ' done.'; |
|
1405 | -} |
|
1489 | + if ($command_line) { |
|
1490 | + echo ' done.'; |
|
1491 | + } |
|
1492 | + } |
|
1406 | 1493 | |
1407 | 1494 | // Step 2: Everything. |
1408 | 1495 | function DatabaseChanges() |
@@ -1411,8 +1498,9 @@ discard block |
||
1411 | 1498 | global $upcontext, $support_js, $db_type; |
1412 | 1499 | |
1413 | 1500 | // Have we just completed this? |
1414 | - if (!empty($_POST['database_done'])) |
|
1415 | - return true; |
|
1501 | + if (!empty($_POST['database_done'])) { |
|
1502 | + return true; |
|
1503 | + } |
|
1416 | 1504 | |
1417 | 1505 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
1418 | 1506 | $upcontext['page_title'] = $txt['database_changes']; |
@@ -1427,15 +1515,16 @@ discard block |
||
1427 | 1515 | ); |
1428 | 1516 | |
1429 | 1517 | // How many files are there in total? |
1430 | - if (isset($_GET['filecount'])) |
|
1431 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1432 | - else |
|
1518 | + if (isset($_GET['filecount'])) { |
|
1519 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
1520 | + } else |
|
1433 | 1521 | { |
1434 | 1522 | $upcontext['file_count'] = 0; |
1435 | 1523 | foreach ($files as $file) |
1436 | 1524 | { |
1437 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
1438 | - $upcontext['file_count']++; |
|
1525 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
1526 | + $upcontext['file_count']++; |
|
1527 | + } |
|
1439 | 1528 | } |
1440 | 1529 | } |
1441 | 1530 | |
@@ -1445,9 +1534,9 @@ discard block |
||
1445 | 1534 | $upcontext['cur_file_num'] = 0; |
1446 | 1535 | foreach ($files as $file) |
1447 | 1536 | { |
1448 | - if ($did_not_do) |
|
1449 | - $did_not_do--; |
|
1450 | - else |
|
1537 | + if ($did_not_do) { |
|
1538 | + $did_not_do--; |
|
1539 | + } else |
|
1451 | 1540 | { |
1452 | 1541 | $upcontext['cur_file_num']++; |
1453 | 1542 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1474,12 +1563,13 @@ discard block |
||
1474 | 1563 | // Flag to move on to the next. |
1475 | 1564 | $upcontext['completed_step'] = true; |
1476 | 1565 | // Did we complete the whole file? |
1477 | - if ($nextFile) |
|
1478 | - $upcontext['current_debug_item_num'] = -1; |
|
1566 | + if ($nextFile) { |
|
1567 | + $upcontext['current_debug_item_num'] = -1; |
|
1568 | + } |
|
1479 | 1569 | return upgradeExit(); |
1570 | + } elseif ($support_js) { |
|
1571 | + break; |
|
1480 | 1572 | } |
1481 | - elseif ($support_js) |
|
1482 | - break; |
|
1483 | 1573 | } |
1484 | 1574 | // Set the progress bar to be right as if we had - even if we hadn't... |
1485 | 1575 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1505,8 +1595,9 @@ discard block |
||
1505 | 1595 | global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings; |
1506 | 1596 | |
1507 | 1597 | // Now it's nice to have some of the basic SMF source files. |
1508 | - if (!isset($_GET['ssi']) && !$command_line) |
|
1509 | - redirectLocation('&ssi=1'); |
|
1598 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
1599 | + redirectLocation('&ssi=1'); |
|
1600 | + } |
|
1510 | 1601 | |
1511 | 1602 | $upcontext['sub_template'] = 'upgrade_complete'; |
1512 | 1603 | $upcontext['page_title'] = $txt['upgrade_complete']; |
@@ -1522,14 +1613,16 @@ discard block |
||
1522 | 1613 | // Are we in maintenance mode? |
1523 | 1614 | if (isset($upcontext['user']['main'])) |
1524 | 1615 | { |
1525 | - if ($command_line) |
|
1526 | - echo ' * '; |
|
1616 | + if ($command_line) { |
|
1617 | + echo ' * '; |
|
1618 | + } |
|
1527 | 1619 | $upcontext['removed_maintenance'] = true; |
1528 | 1620 | $changes['maintenance'] = $upcontext['user']['main']; |
1529 | 1621 | } |
1530 | 1622 | // Otherwise if somehow we are in 2 let's go to 1. |
1531 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
1532 | - $changes['maintenance'] = 1; |
|
1623 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
1624 | + $changes['maintenance'] = 1; |
|
1625 | + } |
|
1533 | 1626 | |
1534 | 1627 | // Wipe this out... |
1535 | 1628 | $upcontext['user'] = array(); |
@@ -1544,21 +1637,23 @@ discard block |
||
1544 | 1637 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
1545 | 1638 | |
1546 | 1639 | // Now is the perfect time to fetch the SM files. |
1547 | - if ($command_line) |
|
1548 | - cli_scheduled_fetchSMfiles(); |
|
1549 | - else |
|
1640 | + if ($command_line) { |
|
1641 | + cli_scheduled_fetchSMfiles(); |
|
1642 | + } else |
|
1550 | 1643 | { |
1551 | 1644 | require_once($sourcedir . '/ScheduledTasks.php'); |
1552 | 1645 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
1553 | 1646 | scheduled_fetchSMfiles(); // Now go get those files! |
1554 | 1647 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
1555 | - if (httpsOn()) |
|
1556 | - $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
1648 | + if (httpsOn()) { |
|
1649 | + $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
1650 | + } |
|
1557 | 1651 | } |
1558 | 1652 | |
1559 | 1653 | // Log what we've done. |
1560 | - if (empty($user_info['id'])) |
|
1561 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1654 | + if (empty($user_info['id'])) { |
|
1655 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
1656 | + } |
|
1562 | 1657 | |
1563 | 1658 | // Log the action manually, so CLI still works. |
1564 | 1659 | $smcFunc['db_insert']('', |
@@ -1577,8 +1672,9 @@ discard block |
||
1577 | 1672 | |
1578 | 1673 | // Save the current database version. |
1579 | 1674 | $server_version = $smcFunc['db_server_info'](); |
1580 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1581 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1675 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1676 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1677 | + } |
|
1582 | 1678 | |
1583 | 1679 | if ($command_line) |
1584 | 1680 | { |
@@ -1590,8 +1686,9 @@ discard block |
||
1590 | 1686 | |
1591 | 1687 | // Make sure it says we're done. |
1592 | 1688 | $upcontext['overall_percent'] = 100; |
1593 | - if (isset($upcontext['step_progress'])) |
|
1594 | - unset($upcontext['step_progress']); |
|
1689 | + if (isset($upcontext['step_progress'])) { |
|
1690 | + unset($upcontext['step_progress']); |
|
1691 | + } |
|
1595 | 1692 | |
1596 | 1693 | $_GET['substep'] = 0; |
1597 | 1694 | return false; |
@@ -1602,8 +1699,9 @@ discard block |
||
1602 | 1699 | { |
1603 | 1700 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
1604 | 1701 | |
1605 | - if (empty($modSettings['time_format'])) |
|
1606 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1702 | + if (empty($modSettings['time_format'])) { |
|
1703 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
1704 | + } |
|
1607 | 1705 | |
1608 | 1706 | // What files do we want to get |
1609 | 1707 | $request = $smcFunc['db_query']('', ' |
@@ -1637,8 +1735,9 @@ discard block |
||
1637 | 1735 | $file_data = fetch_web_data($url); |
1638 | 1736 | |
1639 | 1737 | // If we got an error - give up - the site might be down. |
1640 | - if ($file_data === false) |
|
1641 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
1738 | + if ($file_data === false) { |
|
1739 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
1740 | + } |
|
1642 | 1741 | |
1643 | 1742 | // Save the file to the database. |
1644 | 1743 | $smcFunc['db_query']('substring', ' |
@@ -1680,8 +1779,9 @@ discard block |
||
1680 | 1779 | $themeData = array(); |
1681 | 1780 | foreach ($values as $variable => $value) |
1682 | 1781 | { |
1683 | - if (!isset($value) || $value === null) |
|
1684 | - $value = 0; |
|
1782 | + if (!isset($value) || $value === null) { |
|
1783 | + $value = 0; |
|
1784 | + } |
|
1685 | 1785 | |
1686 | 1786 | $themeData[] = array(0, 1, $variable, $value); |
1687 | 1787 | } |
@@ -1710,8 +1810,9 @@ discard block |
||
1710 | 1810 | |
1711 | 1811 | foreach ($values as $variable => $value) |
1712 | 1812 | { |
1713 | - if (empty($modSettings[$value[0]])) |
|
1714 | - continue; |
|
1813 | + if (empty($modSettings[$value[0]])) { |
|
1814 | + continue; |
|
1815 | + } |
|
1715 | 1816 | |
1716 | 1817 | $smcFunc['db_query']('', ' |
1717 | 1818 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1797,19 +1898,21 @@ discard block |
||
1797 | 1898 | set_error_handler( |
1798 | 1899 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
1799 | 1900 | { |
1800 | - if ($support_js) |
|
1801 | - return true; |
|
1802 | - else |
|
1803 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
1901 | + if ($support_js) { |
|
1902 | + return true; |
|
1903 | + } else { |
|
1904 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
1905 | + } |
|
1804 | 1906 | } |
1805 | 1907 | ); |
1806 | 1908 | |
1807 | 1909 | // If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8 |
1808 | 1910 | // Note it is expected to be in the format: ENGINE=MyISAM{$db_collation}; |
1809 | - if ($db_type == 'mysql') |
|
1810 | - $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
1811 | - else |
|
1812 | - $db_collation = ''; |
|
1911 | + if ($db_type == 'mysql') { |
|
1912 | + $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
1913 | + } else { |
|
1914 | + $db_collation = ''; |
|
1915 | + } |
|
1813 | 1916 | |
1814 | 1917 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
1815 | 1918 | |
@@ -1821,8 +1924,9 @@ discard block |
||
1821 | 1924 | $last_step = ''; |
1822 | 1925 | |
1823 | 1926 | // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php |
1824 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
1825 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
1927 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
1928 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
1929 | + } |
|
1826 | 1930 | |
1827 | 1931 | // Count the total number of steps within this file - for progress. |
1828 | 1932 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1842,15 +1946,18 @@ discard block |
||
1842 | 1946 | $do_current = $substep >= $_GET['substep']; |
1843 | 1947 | |
1844 | 1948 | // Get rid of any comments in the beginning of the line... |
1845 | - if (substr(trim($line), 0, 2) === '/*') |
|
1846 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
1949 | + if (substr(trim($line), 0, 2) === '/*') { |
|
1950 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
1951 | + } |
|
1847 | 1952 | |
1848 | 1953 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
1849 | - if ($is_debug && !$support_js && $command_line) |
|
1850 | - flush(); |
|
1954 | + if ($is_debug && !$support_js && $command_line) { |
|
1955 | + flush(); |
|
1956 | + } |
|
1851 | 1957 | |
1852 | - if (trim($line) === '') |
|
1853 | - continue; |
|
1958 | + if (trim($line) === '') { |
|
1959 | + continue; |
|
1960 | + } |
|
1854 | 1961 | |
1855 | 1962 | if (trim(substr($line, 0, 3)) === '---') |
1856 | 1963 | { |
@@ -1860,8 +1967,9 @@ discard block |
||
1860 | 1967 | if (trim($current_data) != '' && $type !== '}') |
1861 | 1968 | { |
1862 | 1969 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
1863 | - if ($command_line) |
|
1864 | - echo $upcontext['error_message']; |
|
1970 | + if ($command_line) { |
|
1971 | + echo $upcontext['error_message']; |
|
1972 | + } |
|
1865 | 1973 | } |
1866 | 1974 | |
1867 | 1975 | if ($type == ' ') |
@@ -1879,17 +1987,18 @@ discard block |
||
1879 | 1987 | if ($do_current) |
1880 | 1988 | { |
1881 | 1989 | $upcontext['actioned_items'][] = $last_step; |
1882 | - if ($command_line) |
|
1883 | - echo ' * '; |
|
1990 | + if ($command_line) { |
|
1991 | + echo ' * '; |
|
1992 | + } |
|
1884 | 1993 | } |
1885 | - } |
|
1886 | - elseif ($type == '#') |
|
1994 | + } elseif ($type == '#') |
|
1887 | 1995 | { |
1888 | 1996 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
1889 | 1997 | |
1890 | 1998 | $upcontext['current_debug_item_num']++; |
1891 | - if (trim($line) != '---#') |
|
1892 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
1999 | + if (trim($line) != '---#') { |
|
2000 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2001 | + } |
|
1893 | 2002 | |
1894 | 2003 | // Have we already done something? |
1895 | 2004 | if (isset($_GET['xml']) && $done_something) |
@@ -1900,34 +2009,36 @@ discard block |
||
1900 | 2009 | |
1901 | 2010 | if ($do_current) |
1902 | 2011 | { |
1903 | - if (trim($line) == '---#' && $command_line) |
|
1904 | - echo ' done.', $endl; |
|
1905 | - elseif ($command_line) |
|
1906 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
1907 | - elseif (trim($line) != '---#') |
|
2012 | + if (trim($line) == '---#' && $command_line) { |
|
2013 | + echo ' done.', $endl; |
|
2014 | + } elseif ($command_line) { |
|
2015 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
2016 | + } elseif (trim($line) != '---#') |
|
1908 | 2017 | { |
1909 | - if ($is_debug) |
|
1910 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2018 | + if ($is_debug) { |
|
2019 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
2020 | + } |
|
1911 | 2021 | } |
1912 | 2022 | } |
1913 | 2023 | |
1914 | 2024 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
1915 | 2025 | { |
1916 | - if ($command_line) |
|
1917 | - echo ' * '; |
|
1918 | - else |
|
1919 | - $upcontext['actioned_items'][] = $last_step; |
|
2026 | + if ($command_line) { |
|
2027 | + echo ' * '; |
|
2028 | + } else { |
|
2029 | + $upcontext['actioned_items'][] = $last_step; |
|
2030 | + } |
|
1920 | 2031 | } |
1921 | 2032 | |
1922 | 2033 | // Small step - only if we're actually doing stuff. |
1923 | - if ($do_current) |
|
1924 | - nextSubstep(++$substep); |
|
1925 | - else |
|
1926 | - $substep++; |
|
1927 | - } |
|
1928 | - elseif ($type == '{') |
|
1929 | - $current_type = 'code'; |
|
1930 | - elseif ($type == '}') |
|
2034 | + if ($do_current) { |
|
2035 | + nextSubstep(++$substep); |
|
2036 | + } else { |
|
2037 | + $substep++; |
|
2038 | + } |
|
2039 | + } elseif ($type == '{') { |
|
2040 | + $current_type = 'code'; |
|
2041 | + } elseif ($type == '}') |
|
1931 | 2042 | { |
1932 | 2043 | $current_type = 'sql'; |
1933 | 2044 | |
@@ -1940,8 +2051,9 @@ discard block |
||
1940 | 2051 | if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false) |
1941 | 2052 | { |
1942 | 2053 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
1943 | - if ($command_line) |
|
1944 | - echo $upcontext['error_message']; |
|
2054 | + if ($command_line) { |
|
2055 | + echo $upcontext['error_message']; |
|
2056 | + } |
|
1945 | 2057 | } |
1946 | 2058 | |
1947 | 2059 | // Done with code! |
@@ -2029,8 +2141,9 @@ discard block |
||
2029 | 2141 | $db_unbuffered = false; |
2030 | 2142 | |
2031 | 2143 | // Failure?! |
2032 | - if ($result !== false) |
|
2033 | - return $result; |
|
2144 | + if ($result !== false) { |
|
2145 | + return $result; |
|
2146 | + } |
|
2034 | 2147 | |
2035 | 2148 | $db_error_message = $smcFunc['db_error']($db_connection); |
2036 | 2149 | // If MySQL we do something more clever. |
@@ -2058,54 +2171,61 @@ discard block |
||
2058 | 2171 | { |
2059 | 2172 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
2060 | 2173 | $result = mysqli_query($db_connection, $string); |
2061 | - if ($result !== false) |
|
2062 | - return $result; |
|
2174 | + if ($result !== false) { |
|
2175 | + return $result; |
|
2176 | + } |
|
2063 | 2177 | } |
2064 | - } |
|
2065 | - elseif ($mysqli_errno == 2013) |
|
2178 | + } elseif ($mysqli_errno == 2013) |
|
2066 | 2179 | { |
2067 | 2180 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
2068 | 2181 | mysqli_select_db($db_connection, $db_name); |
2069 | 2182 | if ($db_connection) |
2070 | 2183 | { |
2071 | 2184 | $result = mysqli_query($db_connection, $string); |
2072 | - if ($result !== false) |
|
2073 | - return $result; |
|
2185 | + if ($result !== false) { |
|
2186 | + return $result; |
|
2187 | + } |
|
2074 | 2188 | } |
2075 | 2189 | } |
2076 | 2190 | // Duplicate column name... should be okay ;). |
2077 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
2078 | - return false; |
|
2191 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
2192 | + return false; |
|
2193 | + } |
|
2079 | 2194 | // Duplicate insert... make sure it's the proper type of query ;). |
2080 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
2081 | - return false; |
|
2195 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
2196 | + return false; |
|
2197 | + } |
|
2082 | 2198 | // Creating an index on a non-existent column. |
2083 | - elseif ($mysqli_errno == 1072) |
|
2084 | - return false; |
|
2085 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
2086 | - return false; |
|
2199 | + elseif ($mysqli_errno == 1072) { |
|
2200 | + return false; |
|
2201 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
2202 | + return false; |
|
2203 | + } |
|
2087 | 2204 | } |
2088 | 2205 | // If a table already exists don't go potty. |
2089 | 2206 | else |
2090 | 2207 | { |
2091 | 2208 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
2092 | 2209 | { |
2093 | - if (strpos($db_error_message, 'exist') !== false) |
|
2094 | - return true; |
|
2095 | - } |
|
2096 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2210 | + if (strpos($db_error_message, 'exist') !== false) { |
|
2211 | + return true; |
|
2212 | + } |
|
2213 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
2097 | 2214 | { |
2098 | - if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) |
|
2099 | - return true; |
|
2215 | + if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) { |
|
2216 | + return true; |
|
2217 | + } |
|
2100 | 2218 | } |
2101 | 2219 | } |
2102 | 2220 | |
2103 | 2221 | // Get the query string so we pass everything. |
2104 | 2222 | $query_string = ''; |
2105 | - foreach ($_GET as $k => $v) |
|
2106 | - $query_string .= ';' . $k . '=' . $v; |
|
2107 | - if (strlen($query_string) != 0) |
|
2108 | - $query_string = '?' . substr($query_string, 1); |
|
2223 | + foreach ($_GET as $k => $v) { |
|
2224 | + $query_string .= ';' . $k . '=' . $v; |
|
2225 | + } |
|
2226 | + if (strlen($query_string) != 0) { |
|
2227 | + $query_string = '?' . substr($query_string, 1); |
|
2228 | + } |
|
2109 | 2229 | |
2110 | 2230 | if ($command_line) |
2111 | 2231 | { |
@@ -2160,16 +2280,18 @@ discard block |
||
2160 | 2280 | { |
2161 | 2281 | $found |= 1; |
2162 | 2282 | // Do some checks on the data if we have it set. |
2163 | - if (isset($change['col_type'])) |
|
2164 | - $found &= $change['col_type'] === $column['type']; |
|
2165 | - if (isset($change['null_allowed'])) |
|
2166 | - $found &= $column['null'] == $change['null_allowed']; |
|
2167 | - if (isset($change['default'])) |
|
2168 | - $found &= $change['default'] === $column['default']; |
|
2283 | + if (isset($change['col_type'])) { |
|
2284 | + $found &= $change['col_type'] === $column['type']; |
|
2285 | + } |
|
2286 | + if (isset($change['null_allowed'])) { |
|
2287 | + $found &= $column['null'] == $change['null_allowed']; |
|
2288 | + } |
|
2289 | + if (isset($change['default'])) { |
|
2290 | + $found &= $change['default'] === $column['default']; |
|
2291 | + } |
|
2169 | 2292 | } |
2170 | 2293 | } |
2171 | - } |
|
2172 | - elseif ($change['type'] === 'index') |
|
2294 | + } elseif ($change['type'] === 'index') |
|
2173 | 2295 | { |
2174 | 2296 | $request = upgrade_query(' |
2175 | 2297 | SHOW INDEX |
@@ -2178,9 +2300,10 @@ discard block |
||
2178 | 2300 | { |
2179 | 2301 | $cur_index = array(); |
2180 | 2302 | |
2181 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2182 | - if ($row['Key_name'] === $change['name']) |
|
2303 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2304 | + if ($row['Key_name'] === $change['name']) |
|
2183 | 2305 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
2306 | + } |
|
2184 | 2307 | |
2185 | 2308 | ksort($cur_index, SORT_NUMERIC); |
2186 | 2309 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2190,14 +2313,17 @@ discard block |
||
2190 | 2313 | } |
2191 | 2314 | |
2192 | 2315 | // If we're trying to add and it's added, we're done. |
2193 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
2194 | - return true; |
|
2316 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
2317 | + return true; |
|
2318 | + } |
|
2195 | 2319 | // Otherwise if we're removing and it wasn't found we're also done. |
2196 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
2197 | - return true; |
|
2320 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
2321 | + return true; |
|
2322 | + } |
|
2198 | 2323 | // Otherwise is it just a test? |
2199 | - elseif ($is_test) |
|
2200 | - return false; |
|
2324 | + elseif ($is_test) { |
|
2325 | + return false; |
|
2326 | + } |
|
2201 | 2327 | |
2202 | 2328 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
2203 | 2329 | $running = false; |
@@ -2208,8 +2334,9 @@ discard block |
||
2208 | 2334 | SHOW FULL PROCESSLIST'); |
2209 | 2335 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2210 | 2336 | { |
2211 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
2212 | - $found = true; |
|
2337 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
2338 | + $found = true; |
|
2339 | + } |
|
2213 | 2340 | } |
2214 | 2341 | |
2215 | 2342 | // Can't find it? Then we need to run it fools! |
@@ -2221,8 +2348,9 @@ discard block |
||
2221 | 2348 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
2222 | 2349 | ' . $change['text'], true) !== false; |
2223 | 2350 | |
2224 | - if (!$success) |
|
2225 | - return false; |
|
2351 | + if (!$success) { |
|
2352 | + return false; |
|
2353 | + } |
|
2226 | 2354 | |
2227 | 2355 | // Return |
2228 | 2356 | $running = true; |
@@ -2264,8 +2392,9 @@ discard block |
||
2264 | 2392 | 'db_error_skip' => true, |
2265 | 2393 | ) |
2266 | 2394 | ); |
2267 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2268 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2395 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2396 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
2397 | + } |
|
2269 | 2398 | $table_row = $smcFunc['db_fetch_assoc']($request); |
2270 | 2399 | $smcFunc['db_free_result']($request); |
2271 | 2400 | |
@@ -2287,18 +2416,19 @@ discard block |
||
2287 | 2416 | ) |
2288 | 2417 | ); |
2289 | 2418 | // No results? Just forget it all together. |
2290 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
2291 | - unset($table_row['Collation']); |
|
2292 | - else |
|
2293 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2419 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
2420 | + unset($table_row['Collation']); |
|
2421 | + } else { |
|
2422 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
2423 | + } |
|
2294 | 2424 | $smcFunc['db_free_result']($request); |
2295 | 2425 | } |
2296 | 2426 | |
2297 | 2427 | if ($column_fix) |
2298 | 2428 | { |
2299 | 2429 | // Make sure there are no NULL's left. |
2300 | - if ($null_fix) |
|
2301 | - $smcFunc['db_query']('', ' |
|
2430 | + if ($null_fix) { |
|
2431 | + $smcFunc['db_query']('', ' |
|
2302 | 2432 | UPDATE {db_prefix}' . $change['table'] . ' |
2303 | 2433 | SET ' . $change['column'] . ' = {string:default} |
2304 | 2434 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2307,6 +2437,7 @@ discard block |
||
2307 | 2437 | 'db_error_skip' => true, |
2308 | 2438 | ) |
2309 | 2439 | ); |
2440 | + } |
|
2310 | 2441 | |
2311 | 2442 | // Do the actual alteration. |
2312 | 2443 | $smcFunc['db_query']('', ' |
@@ -2335,8 +2466,9 @@ discard block |
||
2335 | 2466 | } |
2336 | 2467 | |
2337 | 2468 | // Not a column we need to check on? |
2338 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
2339 | - return; |
|
2469 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
2470 | + return; |
|
2471 | + } |
|
2340 | 2472 | |
2341 | 2473 | // Break it up you (six|seven). |
2342 | 2474 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2355,13 +2487,13 @@ discard block |
||
2355 | 2487 | 'new_name' => $temp[2], |
2356 | 2488 | )); |
2357 | 2489 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2358 | - if ($smcFunc['db_num_rows'] != 1) |
|
2359 | - return; |
|
2490 | + if ($smcFunc['db_num_rows'] != 1) { |
|
2491 | + return; |
|
2492 | + } |
|
2360 | 2493 | |
2361 | 2494 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
2362 | 2495 | $smcFunc['db_free_result']($request); |
2363 | - } |
|
2364 | - else |
|
2496 | + } else |
|
2365 | 2497 | { |
2366 | 2498 | // Do this the old fashion, sure method way. |
2367 | 2499 | $request = $smcFunc['db_query']('', ' |
@@ -2372,21 +2504,24 @@ discard block |
||
2372 | 2504 | )); |
2373 | 2505 | // Mayday! |
2374 | 2506 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
2375 | - if ($smcFunc['db_num_rows'] == 0) |
|
2376 | - return; |
|
2507 | + if ($smcFunc['db_num_rows'] == 0) { |
|
2508 | + return; |
|
2509 | + } |
|
2377 | 2510 | |
2378 | 2511 | // Oh where, oh where has my little field gone. Oh where can it be... |
2379 | - while ($row = $smcFunc['db_query']($request)) |
|
2380 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2512 | + while ($row = $smcFunc['db_query']($request)) { |
|
2513 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
2381 | 2514 | { |
2382 | 2515 | $current_type = $row['Type']; |
2516 | + } |
|
2383 | 2517 | break; |
2384 | 2518 | } |
2385 | 2519 | } |
2386 | 2520 | |
2387 | 2521 | // If this doesn't match, the column may of been altered for a reason. |
2388 | - if (trim($current_type) != trim($temp[3])) |
|
2389 | - $temp[3] = $current_type; |
|
2522 | + if (trim($current_type) != trim($temp[3])) { |
|
2523 | + $temp[3] = $current_type; |
|
2524 | + } |
|
2390 | 2525 | |
2391 | 2526 | // Piece this back together. |
2392 | 2527 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2398,8 +2533,9 @@ discard block |
||
2398 | 2533 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
2399 | 2534 | global $step_progress, $is_debug, $upcontext; |
2400 | 2535 | |
2401 | - if ($_GET['substep'] < $substep) |
|
2402 | - $_GET['substep'] = $substep; |
|
2536 | + if ($_GET['substep'] < $substep) { |
|
2537 | + $_GET['substep'] = $substep; |
|
2538 | + } |
|
2403 | 2539 | |
2404 | 2540 | if ($command_line) |
2405 | 2541 | { |
@@ -2412,29 +2548,33 @@ discard block |
||
2412 | 2548 | } |
2413 | 2549 | |
2414 | 2550 | @set_time_limit(300); |
2415 | - if (function_exists('apache_reset_timeout')) |
|
2416 | - @apache_reset_timeout(); |
|
2551 | + if (function_exists('apache_reset_timeout')) { |
|
2552 | + @apache_reset_timeout(); |
|
2553 | + } |
|
2417 | 2554 | |
2418 | - if (time() - $start_time <= $timeLimitThreshold) |
|
2419 | - return; |
|
2555 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
2556 | + return; |
|
2557 | + } |
|
2420 | 2558 | |
2421 | 2559 | // Do we have some custom step progress stuff? |
2422 | 2560 | if (!empty($step_progress)) |
2423 | 2561 | { |
2424 | 2562 | $upcontext['substep_progress'] = 0; |
2425 | 2563 | $upcontext['substep_progress_name'] = $step_progress['name']; |
2426 | - if ($step_progress['current'] > $step_progress['total']) |
|
2427 | - $upcontext['substep_progress'] = 99.9; |
|
2428 | - else |
|
2429 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
2564 | + if ($step_progress['current'] > $step_progress['total']) { |
|
2565 | + $upcontext['substep_progress'] = 99.9; |
|
2566 | + } else { |
|
2567 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
2568 | + } |
|
2430 | 2569 | |
2431 | 2570 | // Make it nicely rounded. |
2432 | 2571 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
2433 | 2572 | } |
2434 | 2573 | |
2435 | 2574 | // If this is XML we just exit right away! |
2436 | - if (isset($_GET['xml'])) |
|
2437 | - return upgradeExit(); |
|
2575 | + if (isset($_GET['xml'])) { |
|
2576 | + return upgradeExit(); |
|
2577 | + } |
|
2438 | 2578 | |
2439 | 2579 | // We're going to pause after this! |
2440 | 2580 | $upcontext['pause'] = true; |
@@ -2442,13 +2582,15 @@ discard block |
||
2442 | 2582 | $upcontext['query_string'] = ''; |
2443 | 2583 | foreach ($_GET as $k => $v) |
2444 | 2584 | { |
2445 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
2446 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
2585 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
2586 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
2587 | + } |
|
2447 | 2588 | } |
2448 | 2589 | |
2449 | 2590 | // Custom warning? |
2450 | - if (!empty($custom_warning)) |
|
2451 | - $upcontext['custom_warning'] = $custom_warning; |
|
2591 | + if (!empty($custom_warning)) { |
|
2592 | + $upcontext['custom_warning'] = $custom_warning; |
|
2593 | + } |
|
2452 | 2594 | |
2453 | 2595 | upgradeExit(); |
2454 | 2596 | } |
@@ -2463,25 +2605,26 @@ discard block |
||
2463 | 2605 | ob_implicit_flush(true); |
2464 | 2606 | @set_time_limit(600); |
2465 | 2607 | |
2466 | - if (!isset($_SERVER['argv'])) |
|
2467 | - $_SERVER['argv'] = array(); |
|
2608 | + if (!isset($_SERVER['argv'])) { |
|
2609 | + $_SERVER['argv'] = array(); |
|
2610 | + } |
|
2468 | 2611 | $_GET['maint'] = 1; |
2469 | 2612 | |
2470 | 2613 | foreach ($_SERVER['argv'] as $i => $arg) |
2471 | 2614 | { |
2472 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
2473 | - $_GET['lang'] = $match[1]; |
|
2474 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
2475 | - continue; |
|
2476 | - elseif ($arg == '--no-maintenance') |
|
2477 | - $_GET['maint'] = 0; |
|
2478 | - elseif ($arg == '--debug') |
|
2479 | - $is_debug = true; |
|
2480 | - elseif ($arg == '--backup') |
|
2481 | - $_POST['backup'] = 1; |
|
2482 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
2483 | - $_GET['conv'] = 1; |
|
2484 | - elseif ($i != 0) |
|
2615 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
2616 | + $_GET['lang'] = $match[1]; |
|
2617 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
2618 | + continue; |
|
2619 | + } elseif ($arg == '--no-maintenance') { |
|
2620 | + $_GET['maint'] = 0; |
|
2621 | + } elseif ($arg == '--debug') { |
|
2622 | + $is_debug = true; |
|
2623 | + } elseif ($arg == '--backup') { |
|
2624 | + $_POST['backup'] = 1; |
|
2625 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
2626 | + $_GET['conv'] = 1; |
|
2627 | + } elseif ($i != 0) |
|
2485 | 2628 | { |
2486 | 2629 | echo 'SMF Command-line Upgrader |
2487 | 2630 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2495,10 +2638,12 @@ discard block |
||
2495 | 2638 | } |
2496 | 2639 | } |
2497 | 2640 | |
2498 | - if (!php_version_check()) |
|
2499 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
2500 | - if (!db_version_check()) |
|
2501 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
2641 | + if (!php_version_check()) { |
|
2642 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
2643 | + } |
|
2644 | + if (!db_version_check()) { |
|
2645 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
2646 | + } |
|
2502 | 2647 | |
2503 | 2648 | // Do some checks to make sure they have proper privileges |
2504 | 2649 | db_extend('packages'); |
@@ -2513,34 +2658,39 @@ discard block |
||
2513 | 2658 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
2514 | 2659 | |
2515 | 2660 | // Sorry... we need CREATE, ALTER and DROP |
2516 | - if (!$create || !$alter || !$drop) |
|
2517 | - print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
2661 | + if (!$create || !$alter || !$drop) { |
|
2662 | + print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
2663 | + } |
|
2518 | 2664 | |
2519 | 2665 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
2520 | 2666 | && @file_exists($sourcedir . '/QueryString.php') |
2521 | 2667 | && @file_exists($sourcedir . '/ManageBoards.php'); |
2522 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
2523 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
2668 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
2669 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
2670 | + } |
|
2524 | 2671 | |
2525 | 2672 | // Do a quick version spot check. |
2526 | 2673 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
2527 | 2674 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
2528 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
2529 | - print_error('Error: Some files have not yet been updated properly.'); |
|
2675 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
2676 | + print_error('Error: Some files have not yet been updated properly.'); |
|
2677 | + } |
|
2530 | 2678 | |
2531 | 2679 | // Make sure Settings.php is writable. |
2532 | 2680 | quickFileWritable($boarddir . '/Settings.php'); |
2533 | - if (!is_writable($boarddir . '/Settings.php')) |
|
2534 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
2681 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
2682 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
2683 | + } |
|
2535 | 2684 | |
2536 | 2685 | // Make sure Settings_bak.php is writable. |
2537 | 2686 | quickFileWritable($boarddir . '/Settings_bak.php'); |
2538 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
2539 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
2687 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
2688 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
2689 | + } |
|
2540 | 2690 | |
2541 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
2542 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
2543 | - elseif (isset($modSettings['agreement'])) |
|
2691 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
2692 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
2693 | + } elseif (isset($modSettings['agreement'])) |
|
2544 | 2694 | { |
2545 | 2695 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
2546 | 2696 | fwrite($fp, $modSettings['agreement']); |
@@ -2550,36 +2700,42 @@ discard block |
||
2550 | 2700 | // Make sure Themes is writable. |
2551 | 2701 | quickFileWritable($modSettings['theme_dir']); |
2552 | 2702 | |
2553 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
2554 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
2703 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
2704 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
2705 | + } |
|
2555 | 2706 | |
2556 | 2707 | // Make sure cache directory exists and is writable! |
2557 | 2708 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
2558 | - if (!file_exists($cachedir_temp)) |
|
2559 | - @mkdir($cachedir_temp); |
|
2709 | + if (!file_exists($cachedir_temp)) { |
|
2710 | + @mkdir($cachedir_temp); |
|
2711 | + } |
|
2560 | 2712 | |
2561 | 2713 | // Make sure the cache temp dir is writable. |
2562 | 2714 | quickFileWritable($cachedir_temp); |
2563 | 2715 | |
2564 | - if (!is_writable($cachedir_temp)) |
|
2565 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
2716 | + if (!is_writable($cachedir_temp)) { |
|
2717 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
2718 | + } |
|
2566 | 2719 | |
2567 | 2720 | // Make sure db_last_error.php is writable. |
2568 | 2721 | quickFileWritable($cachedir_temp . '/db_last_error.php'); |
2569 | - if (!is_writable($cachedir_temp . '/db_last_error.php')) |
|
2570 | - print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
2722 | + if (!is_writable($cachedir_temp . '/db_last_error.php')) { |
|
2723 | + print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
2724 | + } |
|
2571 | 2725 | |
2572 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
2573 | - print_error('Error: Unable to find language files!', true); |
|
2574 | - else |
|
2726 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
2727 | + print_error('Error: Unable to find language files!', true); |
|
2728 | + } else |
|
2575 | 2729 | { |
2576 | 2730 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
2577 | 2731 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
2578 | 2732 | |
2579 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
2580 | - print_error('Error: Language files out of date.', true); |
|
2581 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
2582 | - print_error('Error: Install language is missing for selected language.', true); |
|
2733 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
2734 | + print_error('Error: Language files out of date.', true); |
|
2735 | + } |
|
2736 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
2737 | + print_error('Error: Install language is missing for selected language.', true); |
|
2738 | + } |
|
2583 | 2739 | |
2584 | 2740 | // Otherwise include it! |
2585 | 2741 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2599,8 +2755,9 @@ discard block |
||
2599 | 2755 | global $db_prefix, $db_type, $command_line, $support_js, $txt; |
2600 | 2756 | |
2601 | 2757 | // Done it already? |
2602 | - if (!empty($_POST['utf8_done'])) |
|
2603 | - return true; |
|
2758 | + if (!empty($_POST['utf8_done'])) { |
|
2759 | + return true; |
|
2760 | + } |
|
2604 | 2761 | |
2605 | 2762 | // First make sure they aren't already on UTF-8 before we go anywhere... |
2606 | 2763 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2613,8 +2770,7 @@ discard block |
||
2613 | 2770 | ); |
2614 | 2771 | |
2615 | 2772 | return true; |
2616 | - } |
|
2617 | - else |
|
2773 | + } else |
|
2618 | 2774 | { |
2619 | 2775 | $upcontext['page_title'] = $txt['converting_utf8']; |
2620 | 2776 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2658,8 +2814,9 @@ discard block |
||
2658 | 2814 | ) |
2659 | 2815 | ); |
2660 | 2816 | $db_charsets = array(); |
2661 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2662 | - $db_charsets[] = $row['Charset']; |
|
2817 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2818 | + $db_charsets[] = $row['Charset']; |
|
2819 | + } |
|
2663 | 2820 | |
2664 | 2821 | $smcFunc['db_free_result']($request); |
2665 | 2822 | |
@@ -2695,13 +2852,15 @@ discard block |
||
2695 | 2852 | // If there's a fulltext index, we need to drop it first... |
2696 | 2853 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
2697 | 2854 | { |
2698 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2699 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
2855 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2856 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
2700 | 2857 | $upcontext['fulltext_index'][] = $row['Key_name']; |
2858 | + } |
|
2701 | 2859 | $smcFunc['db_free_result']($request); |
2702 | 2860 | |
2703 | - if (isset($upcontext['fulltext_index'])) |
|
2704 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
2861 | + if (isset($upcontext['fulltext_index'])) { |
|
2862 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
2863 | + } |
|
2705 | 2864 | } |
2706 | 2865 | |
2707 | 2866 | // Drop it and make a note... |
@@ -2891,8 +3050,9 @@ discard block |
||
2891 | 3050 | $replace = '%field%'; |
2892 | 3051 | |
2893 | 3052 | // Build a huge REPLACE statement... |
2894 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
2895 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3053 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
3054 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
3055 | + } |
|
2896 | 3056 | } |
2897 | 3057 | |
2898 | 3058 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2902,9 +3062,10 @@ discard block |
||
2902 | 3062 | $upcontext['table_count'] = count($queryTables); |
2903 | 3063 | |
2904 | 3064 | // What ones have we already done? |
2905 | - foreach ($queryTables as $id => $table) |
|
2906 | - if ($id < $_GET['substep']) |
|
3065 | + foreach ($queryTables as $id => $table) { |
|
3066 | + if ($id < $_GET['substep']) |
|
2907 | 3067 | $upcontext['previous_tables'][] = $table; |
3068 | + } |
|
2908 | 3069 | |
2909 | 3070 | $upcontext['cur_table_num'] = $_GET['substep']; |
2910 | 3071 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2941,8 +3102,9 @@ discard block |
||
2941 | 3102 | nextSubstep($substep); |
2942 | 3103 | |
2943 | 3104 | // Just to make sure it doesn't time out. |
2944 | - if (function_exists('apache_reset_timeout')) |
|
2945 | - @apache_reset_timeout(); |
|
3105 | + if (function_exists('apache_reset_timeout')) { |
|
3106 | + @apache_reset_timeout(); |
|
3107 | + } |
|
2946 | 3108 | |
2947 | 3109 | $table_charsets = array(); |
2948 | 3110 | |
@@ -2965,8 +3127,9 @@ discard block |
||
2965 | 3127 | |
2966 | 3128 | // Build structure of columns to operate on organized by charset; only operate on columns not yet utf8 |
2967 | 3129 | if ($charset != 'utf8') { |
2968 | - if (!isset($table_charsets[$charset])) |
|
2969 | - $table_charsets[$charset] = array(); |
|
3130 | + if (!isset($table_charsets[$charset])) { |
|
3131 | + $table_charsets[$charset] = array(); |
|
3132 | + } |
|
2970 | 3133 | |
2971 | 3134 | $table_charsets[$charset][] = $column_info; |
2972 | 3135 | } |
@@ -3007,10 +3170,11 @@ discard block |
||
3007 | 3170 | if (isset($translation_tables[$upcontext['charset_detected']])) |
3008 | 3171 | { |
3009 | 3172 | $update = ''; |
3010 | - foreach ($table_charsets as $charset => $columns) |
|
3011 | - foreach ($columns as $column) |
|
3173 | + foreach ($table_charsets as $charset => $columns) { |
|
3174 | + foreach ($columns as $column) |
|
3012 | 3175 | $update .= ' |
3013 | 3176 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
3177 | + } |
|
3014 | 3178 | |
3015 | 3179 | $smcFunc['db_query']('', ' |
3016 | 3180 | UPDATE {raw:table_name} |
@@ -3035,8 +3199,9 @@ discard block |
||
3035 | 3199 | // Now do the actual conversion (if still needed). |
3036 | 3200 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
3037 | 3201 | { |
3038 | - if ($command_line) |
|
3039 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3202 | + if ($command_line) { |
|
3203 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
3204 | + } |
|
3040 | 3205 | |
3041 | 3206 | $smcFunc['db_query']('', ' |
3042 | 3207 | ALTER TABLE {raw:table_name} |
@@ -3046,12 +3211,14 @@ discard block |
||
3046 | 3211 | ) |
3047 | 3212 | ); |
3048 | 3213 | |
3049 | - if ($command_line) |
|
3050 | - echo " done.\n"; |
|
3214 | + if ($command_line) { |
|
3215 | + echo " done.\n"; |
|
3216 | + } |
|
3051 | 3217 | } |
3052 | 3218 | // If this is XML to keep it nice for the user do one table at a time anyway! |
3053 | - if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) |
|
3054 | - return upgradeExit(); |
|
3219 | + if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) { |
|
3220 | + return upgradeExit(); |
|
3221 | + } |
|
3055 | 3222 | } |
3056 | 3223 | |
3057 | 3224 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -3080,8 +3247,8 @@ discard block |
||
3080 | 3247 | ); |
3081 | 3248 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
3082 | 3249 | { |
3083 | - if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
|
3084 | - $smcFunc['db_query']('', ' |
|
3250 | + if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) { |
|
3251 | + $smcFunc['db_query']('', ' |
|
3085 | 3252 | UPDATE {db_prefix}log_actions |
3086 | 3253 | SET extra = {string:extra} |
3087 | 3254 | WHERE id_action = {int:current_action}', |
@@ -3090,6 +3257,7 @@ discard block |
||
3090 | 3257 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
3091 | 3258 | ) |
3092 | 3259 | ); |
3260 | + } |
|
3093 | 3261 | } |
3094 | 3262 | $smcFunc['db_free_result']($request); |
3095 | 3263 | |
@@ -3111,15 +3279,17 @@ discard block |
||
3111 | 3279 | // First thing's first - did we already do this? |
3112 | 3280 | if (!empty($modSettings['json_done'])) |
3113 | 3281 | { |
3114 | - if ($command_line) |
|
3115 | - return DeleteUpgrade(); |
|
3116 | - else |
|
3117 | - return true; |
|
3282 | + if ($command_line) { |
|
3283 | + return DeleteUpgrade(); |
|
3284 | + } else { |
|
3285 | + return true; |
|
3286 | + } |
|
3118 | 3287 | } |
3119 | 3288 | |
3120 | 3289 | // Done it already - js wise? |
3121 | - if (!empty($_POST['json_done'])) |
|
3122 | - return true; |
|
3290 | + if (!empty($_POST['json_done'])) { |
|
3291 | + return true; |
|
3292 | + } |
|
3123 | 3293 | |
3124 | 3294 | // List of tables affected by this function |
3125 | 3295 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -3151,12 +3321,14 @@ discard block |
||
3151 | 3321 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
3152 | 3322 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
3153 | 3323 | |
3154 | - foreach ($keys as $id => $table) |
|
3155 | - if ($id < $_GET['substep']) |
|
3324 | + foreach ($keys as $id => $table) { |
|
3325 | + if ($id < $_GET['substep']) |
|
3156 | 3326 | $upcontext['previous_tables'][] = $table; |
3327 | + } |
|
3157 | 3328 | |
3158 | - if ($command_line) |
|
3159 | - echo 'Converting data from serialize() to json_encode().'; |
|
3329 | + if ($command_line) { |
|
3330 | + echo 'Converting data from serialize() to json_encode().'; |
|
3331 | + } |
|
3160 | 3332 | |
3161 | 3333 | if (!$support_js || isset($_GET['xml'])) |
3162 | 3334 | { |
@@ -3196,8 +3368,9 @@ discard block |
||
3196 | 3368 | |
3197 | 3369 | // Loop through and fix these... |
3198 | 3370 | $new_settings = array(); |
3199 | - if ($command_line) |
|
3200 | - echo "\n" . 'Fixing some settings...'; |
|
3371 | + if ($command_line) { |
|
3372 | + echo "\n" . 'Fixing some settings...'; |
|
3373 | + } |
|
3201 | 3374 | |
3202 | 3375 | foreach ($serialized_settings as $var) |
3203 | 3376 | { |
@@ -3205,22 +3378,24 @@ discard block |
||
3205 | 3378 | { |
3206 | 3379 | // Attempt to unserialize the setting |
3207 | 3380 | $temp = @safe_unserialize($modSettings[$var]); |
3208 | - if (!$temp && $command_line) |
|
3209 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
3210 | - elseif ($temp !== false) |
|
3211 | - $new_settings[$var] = json_encode($temp); |
|
3381 | + if (!$temp && $command_line) { |
|
3382 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
3383 | + } elseif ($temp !== false) { |
|
3384 | + $new_settings[$var] = json_encode($temp); |
|
3385 | + } |
|
3212 | 3386 | } |
3213 | 3387 | } |
3214 | 3388 | |
3215 | 3389 | // Update everything at once |
3216 | - if (!function_exists('cache_put_data')) |
|
3217 | - require_once($sourcedir . '/Load.php'); |
|
3390 | + if (!function_exists('cache_put_data')) { |
|
3391 | + require_once($sourcedir . '/Load.php'); |
|
3392 | + } |
|
3218 | 3393 | updateSettings($new_settings, true); |
3219 | 3394 | |
3220 | - if ($command_line) |
|
3221 | - echo ' done.'; |
|
3222 | - } |
|
3223 | - elseif ($table == 'themes') |
|
3395 | + if ($command_line) { |
|
3396 | + echo ' done.'; |
|
3397 | + } |
|
3398 | + } elseif ($table == 'themes') |
|
3224 | 3399 | { |
3225 | 3400 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
3226 | 3401 | $query = $smcFunc['db_query']('', ' |
@@ -3239,10 +3414,11 @@ discard block |
||
3239 | 3414 | |
3240 | 3415 | if ($command_line) |
3241 | 3416 | { |
3242 | - if ($temp === false) |
|
3243 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
3244 | - else |
|
3245 | - echo "\n" . 'Fixing admin preferences...'; |
|
3417 | + if ($temp === false) { |
|
3418 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
3419 | + } else { |
|
3420 | + echo "\n" . 'Fixing admin preferences...'; |
|
3421 | + } |
|
3246 | 3422 | } |
3247 | 3423 | |
3248 | 3424 | if ($temp !== false) |
@@ -3264,15 +3440,15 @@ discard block |
||
3264 | 3440 | ) |
3265 | 3441 | ); |
3266 | 3442 | |
3267 | - if ($command_line) |
|
3268 | - echo ' done.'; |
|
3443 | + if ($command_line) { |
|
3444 | + echo ' done.'; |
|
3445 | + } |
|
3269 | 3446 | } |
3270 | 3447 | } |
3271 | 3448 | |
3272 | 3449 | $smcFunc['db_free_result']($query); |
3273 | 3450 | } |
3274 | - } |
|
3275 | - else |
|
3451 | + } else |
|
3276 | 3452 | { |
3277 | 3453 | // First item is always the key... |
3278 | 3454 | $key = $info[0]; |
@@ -3283,8 +3459,7 @@ discard block |
||
3283 | 3459 | { |
3284 | 3460 | $col_select = $info[1]; |
3285 | 3461 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
3286 | - } |
|
3287 | - else |
|
3462 | + } else |
|
3288 | 3463 | { |
3289 | 3464 | $col_select = implode(', ', $info); |
3290 | 3465 | } |
@@ -3317,8 +3492,7 @@ discard block |
||
3317 | 3492 | if ($temp === false && $command_line) |
3318 | 3493 | { |
3319 | 3494 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
3320 | - } |
|
3321 | - else |
|
3495 | + } else |
|
3322 | 3496 | { |
3323 | 3497 | $row[$col] = json_encode($temp); |
3324 | 3498 | |
@@ -3343,16 +3517,18 @@ discard block |
||
3343 | 3517 | } |
3344 | 3518 | } |
3345 | 3519 | |
3346 | - if ($command_line) |
|
3347 | - echo ' done.'; |
|
3520 | + if ($command_line) { |
|
3521 | + echo ' done.'; |
|
3522 | + } |
|
3348 | 3523 | |
3349 | 3524 | // Free up some memory... |
3350 | 3525 | $smcFunc['db_free_result']($query); |
3351 | 3526 | } |
3352 | 3527 | } |
3353 | 3528 | // If this is XML to keep it nice for the user do one table at a time anyway! |
3354 | - if (isset($_GET['xml'])) |
|
3355 | - return upgradeExit(); |
|
3529 | + if (isset($_GET['xml'])) { |
|
3530 | + return upgradeExit(); |
|
3531 | + } |
|
3356 | 3532 | } |
3357 | 3533 | |
3358 | 3534 | if ($command_line) |
@@ -3367,8 +3543,9 @@ discard block |
||
3367 | 3543 | |
3368 | 3544 | $_GET['substep'] = 0; |
3369 | 3545 | // Make sure we move on! |
3370 | - if ($command_line) |
|
3371 | - return DeleteUpgrade(); |
|
3546 | + if ($command_line) { |
|
3547 | + return DeleteUpgrade(); |
|
3548 | + } |
|
3372 | 3549 | |
3373 | 3550 | return true; |
3374 | 3551 | } |
@@ -3425,14 +3602,16 @@ discard block |
||
3425 | 3602 | global $upcontext, $txt, $settings; |
3426 | 3603 | |
3427 | 3604 | // Don't call me twice! |
3428 | - if (!empty($upcontext['chmod_called'])) |
|
3429 | - return; |
|
3605 | + if (!empty($upcontext['chmod_called'])) { |
|
3606 | + return; |
|
3607 | + } |
|
3430 | 3608 | |
3431 | 3609 | $upcontext['chmod_called'] = true; |
3432 | 3610 | |
3433 | 3611 | // Nothing? |
3434 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
3435 | - return; |
|
3612 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
3613 | + return; |
|
3614 | + } |
|
3436 | 3615 | |
3437 | 3616 | // Was it a problem with Windows? |
3438 | 3617 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3464,11 +3643,12 @@ discard block |
||
3464 | 3643 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\'); |
3465 | 3644 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
3466 | 3645 | |
3467 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
3468 | - echo ' |
|
3646 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
3647 | + echo ' |
|
3469 | 3648 | content.write(\'<hr>\n\t\t\t\'); |
3470 | 3649 | content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\'); |
3471 | 3650 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
3651 | + } |
|
3472 | 3652 | |
3473 | 3653 | echo ' |
3474 | 3654 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3476,16 +3656,18 @@ discard block |
||
3476 | 3656 | } |
3477 | 3657 | </script>'; |
3478 | 3658 | |
3479 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
3480 | - echo ' |
|
3659 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
3660 | + echo ' |
|
3481 | 3661 | <div class="error_message red"> |
3482 | 3662 | <p>', $txt['upgrade_ftp_error'], '<p> |
3483 | 3663 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
3484 | 3664 | </div>'; |
3665 | + } |
|
3485 | 3666 | |
3486 | - if (empty($upcontext['chmod_in_form'])) |
|
3487 | - echo ' |
|
3667 | + if (empty($upcontext['chmod_in_form'])) { |
|
3668 | + echo ' |
|
3488 | 3669 | <form action="', $upcontext['form_url'], '" method="post">'; |
3670 | + } |
|
3489 | 3671 | |
3490 | 3672 | echo ' |
3491 | 3673 | <dl class="settings"> |
@@ -3527,9 +3709,10 @@ discard block |
||
3527 | 3709 | <input type="submit" value="', $txt['ftp_connect'], '" class="button"> |
3528 | 3710 | </div>'; |
3529 | 3711 | |
3530 | - if (empty($upcontext['chmod_in_form'])) |
|
3531 | - echo ' |
|
3712 | + if (empty($upcontext['chmod_in_form'])) { |
|
3713 | + echo ' |
|
3532 | 3714 | </form>'; |
3715 | + } |
|
3533 | 3716 | |
3534 | 3717 | echo ' |
3535 | 3718 | </div><!-- .panel -->'; |
@@ -3593,9 +3776,10 @@ discard block |
||
3593 | 3776 | <h2>', $txt['upgrade_progress'], '</h2> |
3594 | 3777 | <ul>'; |
3595 | 3778 | |
3596 | - foreach ($upcontext['steps'] as $num => $step) |
|
3597 | - echo ' |
|
3779 | + foreach ($upcontext['steps'] as $num => $step) { |
|
3780 | + echo ' |
|
3598 | 3781 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
3782 | + } |
|
3599 | 3783 | |
3600 | 3784 | echo ' |
3601 | 3785 | </ul> |
@@ -3608,13 +3792,14 @@ discard block |
||
3608 | 3792 | <span id="overall_text">', $upcontext['overall_percent'], '%</span> |
3609 | 3793 | </div>'; |
3610 | 3794 | |
3611 | - if (isset($upcontext['step_progress'])) |
|
3612 | - echo ' |
|
3795 | + if (isset($upcontext['step_progress'])) { |
|
3796 | + echo ' |
|
3613 | 3797 | <div id="progress_bar_step" class="progress_bar progress_yellow"> |
3614 | 3798 | <h3>', $txt['upgrade_step_progress'], '</h3> |
3615 | 3799 | <div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div> |
3616 | 3800 | <span id="step_text">', $upcontext['step_progress'], '%</span> |
3617 | 3801 | </div>'; |
3802 | + } |
|
3618 | 3803 | |
3619 | 3804 | echo ' |
3620 | 3805 | <div id="substep_bar_div" class="progress_bar ', isset($upcontext['substep_progress']) ? '' : 'hidden', '"> |
@@ -3645,31 +3830,35 @@ discard block |
||
3645 | 3830 | { |
3646 | 3831 | global $upcontext, $txt; |
3647 | 3832 | |
3648 | - if (!empty($upcontext['pause'])) |
|
3649 | - echo ' |
|
3833 | + if (!empty($upcontext['pause'])) { |
|
3834 | + echo ' |
|
3650 | 3835 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
3651 | 3836 | |
3652 | 3837 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
3653 | 3838 | <h3> |
3654 | 3839 | ', $txt['upgrade_paused_overload'], ' |
3655 | 3840 | </h3>'; |
3841 | + } |
|
3656 | 3842 | |
3657 | - if (!empty($upcontext['custom_warning'])) |
|
3658 | - echo ' |
|
3843 | + if (!empty($upcontext['custom_warning'])) { |
|
3844 | + echo ' |
|
3659 | 3845 | <div class="errorbox"> |
3660 | 3846 | <h3>', $txt['upgrade_note'], '</h3> |
3661 | 3847 | ', $upcontext['custom_warning'], ' |
3662 | 3848 | </div>'; |
3849 | + } |
|
3663 | 3850 | |
3664 | 3851 | echo ' |
3665 | 3852 | <div class="righttext" style="margin: 1ex;">'; |
3666 | 3853 | |
3667 | - if (!empty($upcontext['continue'])) |
|
3668 | - echo ' |
|
3854 | + if (!empty($upcontext['continue'])) { |
|
3855 | + echo ' |
|
3669 | 3856 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">'; |
3670 | - if (!empty($upcontext['skip'])) |
|
3671 | - echo ' |
|
3857 | + } |
|
3858 | + if (!empty($upcontext['skip'])) { |
|
3859 | + echo ' |
|
3672 | 3860 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">'; |
3861 | + } |
|
3673 | 3862 | |
3674 | 3863 | echo ' |
3675 | 3864 | </div> |
@@ -3720,11 +3909,12 @@ discard block |
||
3720 | 3909 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
3721 | 3910 | <smf>'; |
3722 | 3911 | |
3723 | - if (!empty($upcontext['get_data'])) |
|
3724 | - foreach ($upcontext['get_data'] as $k => $v) |
|
3912 | + if (!empty($upcontext['get_data'])) { |
|
3913 | + foreach ($upcontext['get_data'] as $k => $v) |
|
3725 | 3914 | echo ' |
3726 | 3915 | <get key="', $k, '">', $v, '</get>'; |
3727 | -} |
|
3916 | + } |
|
3917 | + } |
|
3728 | 3918 | |
3729 | 3919 | function template_xml_below() |
3730 | 3920 | { |
@@ -3764,20 +3954,22 @@ discard block |
||
3764 | 3954 | template_chmod(); |
3765 | 3955 | |
3766 | 3956 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
3767 | - if ($upcontext['is_large_forum']) |
|
3768 | - echo ' |
|
3957 | + if ($upcontext['is_large_forum']) { |
|
3958 | + echo ' |
|
3769 | 3959 | <div class="errorbox"> |
3770 | 3960 | <h3>', $txt['upgrade_warning'], '</h3> |
3771 | 3961 | ', $txt['upgrade_warning_lots_data'], ' |
3772 | 3962 | </div>'; |
3963 | + } |
|
3773 | 3964 | |
3774 | 3965 | // A warning message? |
3775 | - if (!empty($upcontext['warning'])) |
|
3776 | - echo ' |
|
3966 | + if (!empty($upcontext['warning'])) { |
|
3967 | + echo ' |
|
3777 | 3968 | <div class="errorbox"> |
3778 | 3969 | <h3>', $txt['upgrade_warning'], '</h3> |
3779 | 3970 | ', $upcontext['warning'], ' |
3780 | 3971 | </div>'; |
3972 | + } |
|
3781 | 3973 | |
3782 | 3974 | // Paths are incorrect? |
3783 | 3975 | echo ' |
@@ -3808,16 +4000,18 @@ discard block |
||
3808 | 4000 | <p>', sprintf($txt[$agoTxt], $ago_seconds, $ago_minutes, $ago_hours), '</p> |
3809 | 4001 | <p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>'; |
3810 | 4002 | |
3811 | - if ($updated < 600) |
|
3812 | - echo ' |
|
4003 | + if ($updated < 600) { |
|
4004 | + echo ' |
|
3813 | 4005 | <p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>'; |
4006 | + } |
|
3814 | 4007 | |
3815 | - if ($updated > $upcontext['inactive_timeout']) |
|
3816 | - echo ' |
|
4008 | + if ($updated > $upcontext['inactive_timeout']) { |
|
4009 | + echo ' |
|
3817 | 4010 | <p>',$txt['upgrade_run'], '</p>'; |
3818 | - else |
|
3819 | - echo ' |
|
4011 | + } else { |
|
4012 | + echo ' |
|
3820 | 4013 | <p>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'), '</p>'; |
4014 | + } |
|
3821 | 4015 | |
3822 | 4016 | echo ' |
3823 | 4017 | </div>'; |
@@ -3833,9 +4027,10 @@ discard block |
||
3833 | 4027 | <dd> |
3834 | 4028 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>'; |
3835 | 4029 | |
3836 | - if (!empty($upcontext['username_incorrect'])) |
|
3837 | - echo ' |
|
4030 | + if (!empty($upcontext['username_incorrect'])) { |
|
4031 | + echo ' |
|
3838 | 4032 | <div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>'; |
4033 | + } |
|
3839 | 4034 | |
3840 | 4035 | echo ' |
3841 | 4036 | </dd> |
@@ -3846,9 +4041,10 @@ discard block |
||
3846 | 4041 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '> |
3847 | 4042 | <input type="hidden" name="hash_passwrd" value="">'; |
3848 | 4043 | |
3849 | - if (!empty($upcontext['password_failed'])) |
|
3850 | - echo ' |
|
4044 | + if (!empty($upcontext['password_failed'])) { |
|
4045 | + echo ' |
|
3851 | 4046 | <div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>'; |
4047 | + } |
|
3852 | 4048 | |
3853 | 4049 | echo ' |
3854 | 4050 | </dd>'; |
@@ -3916,12 +4112,13 @@ discard block |
||
3916 | 4112 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
3917 | 4113 | |
3918 | 4114 | // Warning message? |
3919 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
3920 | - echo ' |
|
4115 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
4116 | + echo ' |
|
3921 | 4117 | <div class="errorbox"> |
3922 | 4118 | <h3>', $txt['upgrade_warning'] ,'</h3> |
3923 | 4119 | ', $upcontext['upgrade_options_warning'], ' |
3924 | 4120 | </div>'; |
4121 | + } |
|
3925 | 4122 | |
3926 | 4123 | echo ' |
3927 | 4124 | <ul class="upgrade_settings"> |
@@ -3950,12 +4147,13 @@ discard block |
||
3950 | 4147 | <label for="empty_error">', $txt['upgrade_empty_errlog'], '</label> |
3951 | 4148 | </li>'; |
3952 | 4149 | |
3953 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
3954 | - echo ' |
|
4150 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
4151 | + echo ' |
|
3955 | 4152 | <li> |
3956 | 4153 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1"> |
3957 | 4154 | <label for="delete_karma">', $txt['upgrade_delete_karma'], '</label> |
3958 | 4155 | </li>'; |
4156 | + } |
|
3959 | 4157 | |
3960 | 4158 | echo ' |
3961 | 4159 | <li> |
@@ -3995,10 +4193,11 @@ discard block |
||
3995 | 4193 | </div>'; |
3996 | 4194 | |
3997 | 4195 | // Dont any tables so far? |
3998 | - if (!empty($upcontext['previous_tables'])) |
|
3999 | - foreach ($upcontext['previous_tables'] as $table) |
|
4196 | + if (!empty($upcontext['previous_tables'])) { |
|
4197 | + foreach ($upcontext['previous_tables'] as $table) |
|
4000 | 4198 | echo ' |
4001 | 4199 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4200 | + } |
|
4002 | 4201 | |
4003 | 4202 | echo ' |
4004 | 4203 | <h3 id="current_tab"> |
@@ -4037,12 +4236,13 @@ discard block |
||
4037 | 4236 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4038 | 4237 | |
4039 | 4238 | // If debug flood the screen. |
4040 | - if ($is_debug) |
|
4041 | - echo ' |
|
4239 | + if ($is_debug) { |
|
4240 | + echo ' |
|
4042 | 4241 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4043 | 4242 | |
4044 | 4243 | if (document.getElementById(\'debug_section\').scrollHeight) |
4045 | 4244 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4245 | + } |
|
4046 | 4246 | |
4047 | 4247 | echo ' |
4048 | 4248 | // Get the next update... |
@@ -4075,8 +4275,9 @@ discard block |
||
4075 | 4275 | { |
4076 | 4276 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt; |
4077 | 4277 | |
4078 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
4079 | - $is_debug = true; |
|
4278 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
4279 | + $is_debug = true; |
|
4280 | + } |
|
4080 | 4281 | |
4081 | 4282 | echo ' |
4082 | 4283 | <h3>', $txt['upgrade_db_changes'], '</h3> |
@@ -4091,8 +4292,9 @@ discard block |
||
4091 | 4292 | { |
4092 | 4293 | foreach ($upcontext['actioned_items'] as $num => $item) |
4093 | 4294 | { |
4094 | - if ($num != 0) |
|
4095 | - echo ' Successful!'; |
|
4295 | + if ($num != 0) { |
|
4296 | + echo ' Successful!'; |
|
4297 | + } |
|
4096 | 4298 | echo '<br>' . $item; |
4097 | 4299 | } |
4098 | 4300 | |
@@ -4107,20 +4309,20 @@ discard block |
||
4107 | 4309 | $seconds = intval($active % 60); |
4108 | 4310 | |
4109 | 4311 | echo '', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '<br>'; |
4312 | + } else { |
|
4313 | + echo '', $txt['upgrade_success'], '<br>'; |
|
4110 | 4314 | } |
4111 | - else |
|
4112 | - echo '', $txt['upgrade_success'], '<br>'; |
|
4113 | 4315 | |
4114 | 4316 | echo ' |
4115 | 4317 | <p id="commess">', $txt['upgrade_db_complete'], '</p>'; |
4116 | 4318 | } |
4117 | - } |
|
4118 | - else |
|
4319 | + } else |
|
4119 | 4320 | { |
4120 | 4321 | // Tell them how many files we have in total. |
4121 | - if ($upcontext['file_count'] > 1) |
|
4122 | - echo ' |
|
4322 | + if ($upcontext['file_count'] > 1) { |
|
4323 | + echo ' |
|
4123 | 4324 | <strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
4325 | + } |
|
4124 | 4326 | |
4125 | 4327 | echo ' |
4126 | 4328 | <h3 id="info2"> |
@@ -4140,10 +4342,10 @@ discard block |
||
4140 | 4342 | |
4141 | 4343 | echo ' |
4142 | 4344 | <p id="upgradeCompleted">', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '</p>'; |
4143 | - } |
|
4144 | - else |
|
4145 | - echo ' |
|
4345 | + } else { |
|
4346 | + echo ' |
|
4146 | 4347 | <p id="upgradeCompleted"></p>'; |
4348 | + } |
|
4147 | 4349 | |
4148 | 4350 | echo ' |
4149 | 4351 | <div id="debug_section"> |
@@ -4179,9 +4381,10 @@ discard block |
||
4179 | 4381 | var getData = ""; |
4180 | 4382 | var debugItems = ', $upcontext['debug_items'], ';'; |
4181 | 4383 | |
4182 | - if ($is_debug) |
|
4183 | - echo ' |
|
4384 | + if ($is_debug) { |
|
4385 | + echo ' |
|
4184 | 4386 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
4387 | + } |
|
4185 | 4388 | |
4186 | 4389 | echo ' |
4187 | 4390 | function getNextItem() |
@@ -4221,9 +4424,10 @@ discard block |
||
4221 | 4424 | document.getElementById("error_block").classList.remove("hidden"); |
4222 | 4425 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
4223 | 4426 | |
4224 | - if ($is_debug) |
|
4225 | - echo ' |
|
4427 | + if ($is_debug) { |
|
4428 | + echo ' |
|
4226 | 4429 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
4430 | + } |
|
4227 | 4431 | |
4228 | 4432 | echo ' |
4229 | 4433 | } |
@@ -4244,9 +4448,10 @@ discard block |
||
4244 | 4448 | document.getElementById("error_block").classList.remove("hidden"); |
4245 | 4449 | setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);'; |
4246 | 4450 | |
4247 | - if ($is_debug) |
|
4248 | - echo ' |
|
4451 | + if ($is_debug) { |
|
4452 | + echo ' |
|
4249 | 4453 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
4454 | + } |
|
4250 | 4455 | |
4251 | 4456 | echo ' |
4252 | 4457 | } |
@@ -4304,8 +4509,8 @@ discard block |
||
4304 | 4509 | {'; |
4305 | 4510 | |
4306 | 4511 | // Database Changes, tell us how much time we spen to do this. If this gets updated via JS. |
4307 | - if ($is_debug) |
|
4308 | - echo ' |
|
4512 | + if ($is_debug) { |
|
4513 | + echo ' |
|
4309 | 4514 | document.getElementById(\'debug_section\').classList.add("hidden"); |
4310 | 4515 | |
4311 | 4516 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4320,6 +4525,7 @@ discard block |
||
4320 | 4525 | completedTxt = completedTxt.replace("%1$d", diffSeconds).replace("%2$d", diffMinutes).replace("%3$d", diffHours); |
4321 | 4526 | console.log(completedTxt, upgradeFinishedTime, diffTime, diffHours, diffMinutes, diffSeconds); |
4322 | 4527 | setInnerHTML(document.getElementById("upgradeCompleted"), completedTxt);'; |
4528 | + } |
|
4323 | 4529 | |
4324 | 4530 | echo ' |
4325 | 4531 | |
@@ -4327,9 +4533,10 @@ discard block |
||
4327 | 4533 | document.getElementById(\'contbutt\').disabled = 0; |
4328 | 4534 | document.getElementById(\'database_done\').value = 1;'; |
4329 | 4535 | |
4330 | - if ($upcontext['file_count'] > 1) |
|
4331 | - echo ' |
|
4536 | + if ($upcontext['file_count'] > 1) { |
|
4537 | + echo ' |
|
4332 | 4538 | document.getElementById(\'info1\').classList.add(\'hidden\');'; |
4539 | + } |
|
4333 | 4540 | |
4334 | 4541 | echo ' |
4335 | 4542 | document.getElementById(\'info2\').classList.add(\'hidden\'); |
@@ -4342,9 +4549,10 @@ discard block |
||
4342 | 4549 | lastItem = 0; |
4343 | 4550 | prevFile = curFile;'; |
4344 | 4551 | |
4345 | - if ($is_debug) |
|
4346 | - echo ' |
|
4552 | + if ($is_debug) { |
|
4553 | + echo ' |
|
4347 | 4554 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
4555 | + } |
|
4348 | 4556 | |
4349 | 4557 | echo ' |
4350 | 4558 | getNextItem(); |
@@ -4352,8 +4560,8 @@ discard block |
||
4352 | 4560 | }'; |
4353 | 4561 | |
4354 | 4562 | // If debug scroll the screen. |
4355 | - if ($is_debug) |
|
4356 | - echo ' |
|
4563 | + if ($is_debug) { |
|
4564 | + echo ' |
|
4357 | 4565 | if (iLastSubStepProgress == -1) |
4358 | 4566 | { |
4359 | 4567 | // Give it consistent dots. |
@@ -4372,6 +4580,7 @@ discard block |
||
4372 | 4580 | |
4373 | 4581 | if (document.getElementById(\'debug_section\').scrollHeight) |
4374 | 4582 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4583 | + } |
|
4375 | 4584 | |
4376 | 4585 | echo ' |
4377 | 4586 | // Update the page. |
@@ -4432,9 +4641,10 @@ discard block |
||
4432 | 4641 | }'; |
4433 | 4642 | |
4434 | 4643 | // Start things off assuming we've not errored. |
4435 | - if (empty($upcontext['error_message'])) |
|
4436 | - echo ' |
|
4644 | + if (empty($upcontext['error_message'])) { |
|
4645 | + echo ' |
|
4437 | 4646 | getNextItem();'; |
4647 | + } |
|
4438 | 4648 | |
4439 | 4649 | echo ' |
4440 | 4650 | //# sourceURL=dynamicScript-dbch.js |
@@ -4452,18 +4662,21 @@ discard block |
||
4452 | 4662 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
4453 | 4663 | <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>'; |
4454 | 4664 | |
4455 | - if (!empty($upcontext['error_message'])) |
|
4456 | - echo ' |
|
4665 | + if (!empty($upcontext['error_message'])) { |
|
4666 | + echo ' |
|
4457 | 4667 | <error>', $upcontext['error_message'], '</error>'; |
4668 | + } |
|
4458 | 4669 | |
4459 | - if (!empty($upcontext['error_string'])) |
|
4460 | - echo ' |
|
4670 | + if (!empty($upcontext['error_string'])) { |
|
4671 | + echo ' |
|
4461 | 4672 | <sql>', $upcontext['error_string'], '</sql>'; |
4673 | + } |
|
4462 | 4674 | |
4463 | - if ($is_debug) |
|
4464 | - echo ' |
|
4675 | + if ($is_debug) { |
|
4676 | + echo ' |
|
4465 | 4677 | <curtime>', time(), '</curtime>'; |
4466 | -} |
|
4678 | + } |
|
4679 | + } |
|
4467 | 4680 | |
4468 | 4681 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
4469 | 4682 | function template_convert_utf8() |
@@ -4480,10 +4693,11 @@ discard block |
||
4480 | 4693 | </div>'; |
4481 | 4694 | |
4482 | 4695 | // Done any tables so far? |
4483 | - if (!empty($upcontext['previous_tables'])) |
|
4484 | - foreach ($upcontext['previous_tables'] as $table) |
|
4696 | + if (!empty($upcontext['previous_tables'])) { |
|
4697 | + foreach ($upcontext['previous_tables'] as $table) |
|
4485 | 4698 | echo ' |
4486 | 4699 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4700 | + } |
|
4487 | 4701 | |
4488 | 4702 | echo ' |
4489 | 4703 | <h3 id="current_tab"> |
@@ -4491,9 +4705,10 @@ discard block |
||
4491 | 4705 | </h3>'; |
4492 | 4706 | |
4493 | 4707 | // If we dropped their index, let's let them know |
4494 | - if ($upcontext['dropping_index']) |
|
4495 | - echo ' |
|
4708 | + if ($upcontext['dropping_index']) { |
|
4709 | + echo ' |
|
4496 | 4710 | <p id="indexmsg" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', ' style="font-weight: bold; font-style: italic">', $txt['upgrade_fulltext'], '</p>'; |
4711 | + } |
|
4497 | 4712 | |
4498 | 4713 | // Completion notification |
4499 | 4714 | echo ' |
@@ -4530,12 +4745,13 @@ discard block |
||
4530 | 4745 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4531 | 4746 | |
4532 | 4747 | // If debug flood the screen. |
4533 | - if ($is_debug) |
|
4534 | - echo ' |
|
4748 | + if ($is_debug) { |
|
4749 | + echo ' |
|
4535 | 4750 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4536 | 4751 | |
4537 | 4752 | if (document.getElementById(\'debug_section\').scrollHeight) |
4538 | 4753 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4754 | + } |
|
4539 | 4755 | |
4540 | 4756 | echo ' |
4541 | 4757 | // Get the next update... |
@@ -4581,10 +4797,11 @@ discard block |
||
4581 | 4797 | </div>'; |
4582 | 4798 | |
4583 | 4799 | // Dont any tables so far? |
4584 | - if (!empty($upcontext['previous_tables'])) |
|
4585 | - foreach ($upcontext['previous_tables'] as $table) |
|
4800 | + if (!empty($upcontext['previous_tables'])) { |
|
4801 | + foreach ($upcontext['previous_tables'] as $table) |
|
4586 | 4802 | echo ' |
4587 | 4803 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
4804 | + } |
|
4588 | 4805 | |
4589 | 4806 | echo ' |
4590 | 4807 | <h3 id="current_tab"> |
@@ -4593,9 +4810,10 @@ discard block |
||
4593 | 4810 | <p id="commess" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', '">', $txt['upgrade_json_completed'], '</p>'; |
4594 | 4811 | |
4595 | 4812 | // Try to make sure substep was reset. |
4596 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
4597 | - echo ' |
|
4813 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
4814 | + echo ' |
|
4598 | 4815 | <input type="hidden" name="substep" id="substep" value="0">'; |
4816 | + } |
|
4599 | 4817 | |
4600 | 4818 | // Continue please! |
4601 | 4819 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4628,12 +4846,13 @@ discard block |
||
4628 | 4846 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
4629 | 4847 | |
4630 | 4848 | // If debug flood the screen. |
4631 | - if ($is_debug) |
|
4632 | - echo ' |
|
4849 | + if ($is_debug) { |
|
4850 | + echo ' |
|
4633 | 4851 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
4634 | 4852 | |
4635 | 4853 | if (document.getElementById(\'debug_section\').scrollHeight) |
4636 | 4854 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
4855 | + } |
|
4637 | 4856 | |
4638 | 4857 | echo ' |
4639 | 4858 | // Get the next update... |
@@ -4669,8 +4888,8 @@ discard block |
||
4669 | 4888 | <h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>. ', $txt['upgrade_done3'], '</h3> |
4670 | 4889 | <form action="', $boardurl, '/index.php">'; |
4671 | 4890 | |
4672 | - if (!empty($upcontext['can_delete_script'])) |
|
4673 | - echo ' |
|
4891 | + if (!empty($upcontext['can_delete_script'])) { |
|
4892 | + echo ' |
|
4674 | 4893 | <label> |
4675 | 4894 | <input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], ' |
4676 | 4895 | </label> |
@@ -4684,6 +4903,7 @@ discard block |
||
4684 | 4903 | } |
4685 | 4904 | </script> |
4686 | 4905 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
4906 | + } |
|
4687 | 4907 | |
4688 | 4908 | // Show Upgrade time in debug mode when we completed the upgrade process totatly |
4689 | 4909 | if ($is_debug) |
@@ -4693,12 +4913,13 @@ discard block |
||
4693 | 4913 | $minutes = intval(($active / 60) % 60); |
4694 | 4914 | $seconds = intval($active % 60); |
4695 | 4915 | |
4696 | - if ($hours > 0) |
|
4697 | - echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
4698 | - elseif ($minutes > 0) |
|
4699 | - echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
4700 | - elseif ($seconds > 0) |
|
4701 | - echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
4916 | + if ($hours > 0) { |
|
4917 | + echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
4918 | + } elseif ($minutes > 0) { |
|
4919 | + echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
4920 | + } elseif ($seconds > 0) { |
|
4921 | + echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
4922 | + } |
|
4702 | 4923 | } |
4703 | 4924 | |
4704 | 4925 | echo ' |
@@ -4728,8 +4949,9 @@ discard block |
||
4728 | 4949 | |
4729 | 4950 | $current_substep = $_GET['substep']; |
4730 | 4951 | |
4731 | - if (empty($_GET['a'])) |
|
4732 | - $_GET['a'] = 0; |
|
4952 | + if (empty($_GET['a'])) { |
|
4953 | + $_GET['a'] = 0; |
|
4954 | + } |
|
4733 | 4955 | $step_progress['name'] = 'Converting ips'; |
4734 | 4956 | $step_progress['current'] = $_GET['a']; |
4735 | 4957 | |
@@ -4772,16 +4994,19 @@ discard block |
||
4772 | 4994 | 'empty' => '', |
4773 | 4995 | 'limit' => $limit, |
4774 | 4996 | )); |
4775 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4776 | - $arIp[] = $row[$oldCol]; |
|
4997 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4998 | + $arIp[] = $row[$oldCol]; |
|
4999 | + } |
|
4777 | 5000 | $smcFunc['db_free_result']($request); |
4778 | 5001 | |
4779 | 5002 | // Special case, null ip could keep us in a loop. |
4780 | - if (is_null($arIp[0])) |
|
4781 | - unset($arIp[0]); |
|
5003 | + if (is_null($arIp[0])) { |
|
5004 | + unset($arIp[0]); |
|
5005 | + } |
|
4782 | 5006 | |
4783 | - if (empty($arIp)) |
|
4784 | - $is_done = true; |
|
5007 | + if (empty($arIp)) { |
|
5008 | + $is_done = true; |
|
5009 | + } |
|
4785 | 5010 | |
4786 | 5011 | $updates = array(); |
4787 | 5012 | $cases = array(); |
@@ -4790,16 +5015,18 @@ discard block |
||
4790 | 5015 | { |
4791 | 5016 | $arIp[$i] = trim($arIp[$i]); |
4792 | 5017 | |
4793 | - if (empty($arIp[$i])) |
|
4794 | - continue; |
|
5018 | + if (empty($arIp[$i])) { |
|
5019 | + continue; |
|
5020 | + } |
|
4795 | 5021 | |
4796 | 5022 | $updates['ip' . $i] = $arIp[$i]; |
4797 | 5023 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
4798 | 5024 | |
4799 | 5025 | if ($setSize > 0 && $i % $setSize === 0) |
4800 | 5026 | { |
4801 | - if (count($updates) == 1) |
|
4802 | - continue; |
|
5027 | + if (count($updates) == 1) { |
|
5028 | + continue; |
|
5029 | + } |
|
4803 | 5030 | |
4804 | 5031 | $updates['whereSet'] = array_values($updates); |
4805 | 5032 | $smcFunc['db_query']('', ' |
@@ -4833,8 +5060,7 @@ discard block |
||
4833 | 5060 | 'ip' => $ip |
4834 | 5061 | )); |
4835 | 5062 | } |
4836 | - } |
|
4837 | - else |
|
5063 | + } else |
|
4838 | 5064 | { |
4839 | 5065 | $updates['whereSet'] = array_values($updates); |
4840 | 5066 | $smcFunc['db_query']('', ' |
@@ -4848,9 +5074,9 @@ discard block |
||
4848 | 5074 | $updates |
4849 | 5075 | ); |
4850 | 5076 | } |
5077 | + } else { |
|
5078 | + $is_done = true; |
|
4851 | 5079 | } |
4852 | - else |
|
4853 | - $is_done = true; |
|
4854 | 5080 | |
4855 | 5081 | $_GET['a'] += $limit; |
4856 | 5082 | $step_progress['current'] = $_GET['a']; |
@@ -4876,11 +5102,12 @@ discard block |
||
4876 | 5102 | |
4877 | 5103 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
4878 | 5104 | |
4879 | - if (isset($columns[$column])) |
|
4880 | - return $columns[$column]; |
|
4881 | - else |
|
4882 | - return null; |
|
4883 | -} |
|
5105 | + if (isset($columns[$column])) { |
|
5106 | + return $columns[$column]; |
|
5107 | + } else { |
|
5108 | + return null; |
|
5109 | + } |
|
5110 | + } |
|
4884 | 5111 | |
4885 | 5112 | /** |
4886 | 5113 | * Takes the changes to be made during the upgradeOptions step, grabs all known Settings data from Settings.php, then runs |
@@ -5154,18 +5381,20 @@ discard block |
||
5154 | 5381 | global $$setVar; |
5155 | 5382 | |
5156 | 5383 | // Find the setting. |
5157 | - if ($setType == 'string' || $setType == 'string_fatal') |
|
5158 | - $original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\''); |
|
5159 | - elseif ($setType == 'int' || $setType == 'int_fatal') |
|
5160 | - $original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0); |
|
5161 | - elseif ($setType == 'bool' || $setType == 'bool_fatal') |
|
5162 | - $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false'); |
|
5163 | - elseif ($setType == 'null' || $setType == 'null_fatal') |
|
5164 | - $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null'); |
|
5384 | + if ($setType == 'string' || $setType == 'string_fatal') { |
|
5385 | + $original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\''); |
|
5386 | + } elseif ($setType == 'int' || $setType == 'int_fatal') { |
|
5387 | + $original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0); |
|
5388 | + } elseif ($setType == 'bool' || $setType == 'bool_fatal') { |
|
5389 | + $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false'); |
|
5390 | + } elseif ($setType == 'null' || $setType == 'null_fatal') { |
|
5391 | + $original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null'); |
|
5392 | + } |
|
5165 | 5393 | |
5166 | 5394 | // Well this isn't good. Do we fix it or bail? |
5167 | - if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) |
|
5168 | - return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file. Unable to migrate your Settings file to a new version.'); |
|
5395 | + if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) { |
|
5396 | + return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file. Unable to migrate your Settings file to a new version.'); |
|
5397 | + } |
|
5169 | 5398 | } |
5170 | 5399 | |
5171 | 5400 | // Finally, merge the changes with the new ones. |
@@ -5173,8 +5402,9 @@ discard block |
||
5173 | 5402 | foreach ($changes as $setVar => $value) |
5174 | 5403 | { |
5175 | 5404 | // Nothing needed here. |
5176 | - if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) |
|
5177 | - continue; |
|
5405 | + if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) { |
|
5406 | + continue; |
|
5407 | + } |
|
5178 | 5408 | |
5179 | 5409 | $config_vars[$setVar] = $value; |
5180 | 5410 | } |
@@ -5187,15 +5417,17 @@ discard block |
||
5187 | 5417 | $last_settings_change = filemtime($boarddir . '/Settings.php'); |
5188 | 5418 | |
5189 | 5419 | // remove any /r's that made there way in here |
5190 | - foreach ($settingsArray as $k => $dummy) |
|
5191 | - $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
5420 | + foreach ($settingsArray as $k => $dummy) { |
|
5421 | + $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
5422 | + } |
|
5192 | 5423 | |
5193 | 5424 | // go line by line and see whats changing |
5194 | 5425 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
5195 | 5426 | { |
5196 | 5427 | // Don't trim or bother with it if it's not a variable. |
5197 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
5198 | - continue; |
|
5428 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
5429 | + continue; |
|
5430 | + } |
|
5199 | 5431 | |
5200 | 5432 | $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; |
5201 | 5433 | |
@@ -5203,9 +5435,9 @@ discard block |
||
5203 | 5435 | foreach ($config_vars as $var => $val) |
5204 | 5436 | { |
5205 | 5437 | // be sure someone is not updating db_last_error this with a group |
5206 | - if ($var === 'db_last_error') |
|
5207 | - unset($config_vars[$var]); |
|
5208 | - elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
5438 | + if ($var === 'db_last_error') { |
|
5439 | + unset($config_vars[$var]); |
|
5440 | + } elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
5209 | 5441 | { |
5210 | 5442 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
5211 | 5443 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n"; |
@@ -5216,34 +5448,39 @@ discard block |
||
5216 | 5448 | } |
5217 | 5449 | |
5218 | 5450 | // End of the file ... maybe |
5219 | - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') |
|
5220 | - $end = $i; |
|
5451 | + if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') { |
|
5452 | + $end = $i; |
|
5453 | + } |
|
5221 | 5454 | } |
5222 | 5455 | |
5223 | 5456 | // This should never happen, but apparently it is happening. |
5224 | - if (empty($end) || $end < 10) |
|
5225 | - $end = count($settingsArray) - 1; |
|
5457 | + if (empty($end) || $end < 10) { |
|
5458 | + $end = count($settingsArray) - 1; |
|
5459 | + } |
|
5226 | 5460 | |
5227 | 5461 | // Still more variables to go? Then lets add them at the end. |
5228 | 5462 | if (!empty($config_vars)) |
5229 | 5463 | { |
5230 | - if (trim($settingsArray[$end]) == '?' . '>') |
|
5231 | - $settingsArray[$end++] = ''; |
|
5232 | - else |
|
5233 | - $end++; |
|
5464 | + if (trim($settingsArray[$end]) == '?' . '>') { |
|
5465 | + $settingsArray[$end++] = ''; |
|
5466 | + } else { |
|
5467 | + $end++; |
|
5468 | + } |
|
5234 | 5469 | |
5235 | 5470 | // Add in any newly defined vars that were passed |
5236 | - foreach ($config_vars as $var => $val) |
|
5237 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
5471 | + foreach ($config_vars as $var => $val) { |
|
5472 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
5473 | + } |
|
5238 | 5474 | |
5239 | 5475 | $settingsArray[$end] = '?' . '>'; |
5476 | + } else { |
|
5477 | + $settingsArray[$end] = trim($settingsArray[$end]); |
|
5240 | 5478 | } |
5241 | - else |
|
5242 | - $settingsArray[$end] = trim($settingsArray[$end]); |
|
5243 | 5479 | |
5244 | 5480 | // Sanity error checking: the file needs to be at least 12 lines. |
5245 | - if (count($settingsArray) < 12) |
|
5246 | - return throw_error('The upgrader could not process your Settings file for updates. Unable to migrate your Settings file to a new version.'); |
|
5481 | + if (count($settingsArray) < 12) { |
|
5482 | + return throw_error('The upgrader could not process your Settings file for updates. Unable to migrate your Settings file to a new version.'); |
|
5483 | + } |
|
5247 | 5484 | |
5248 | 5485 | // Try to avoid a few pitfalls: |
5249 | 5486 | // - like a possible race condition, |
@@ -5251,8 +5488,9 @@ discard block |
||
5251 | 5488 | // |
5252 | 5489 | // Check before you act: if cache is enabled, we can do a simple write test |
5253 | 5490 | // to validate that we even write things on this filesystem. |
5254 | - if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
5255 | - $cachedir = $boarddir . '/cache'; |
|
5491 | + if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
5492 | + $cachedir = $boarddir . '/cache'; |
|
5493 | + } |
|
5256 | 5494 | |
5257 | 5495 | $test_fp = @fopen($cachedir . '/settings_update.tmp', "w+"); |
5258 | 5496 | if ($test_fp) |
@@ -5263,8 +5501,9 @@ discard block |
||
5263 | 5501 | |
5264 | 5502 | // Oops. Low disk space, perhaps. Don't mess with Settings.php then. |
5265 | 5503 | // No means no. :P |
5266 | - if ($written_bytes !== 4) |
|
5267 | - return throw_error('The upgrader could not write a test file, perhaps not enough storage? Unable to migrate your Settings file to a new version.'); |
|
5504 | + if ($written_bytes !== 4) { |
|
5505 | + return throw_error('The upgrader could not write a test file, perhaps not enough storage? Unable to migrate your Settings file to a new version.'); |
|
5506 | + } |
|
5268 | 5507 | } |
5269 | 5508 | |
5270 | 5509 | // Protect me from what I want! :P |
@@ -5282,8 +5521,9 @@ discard block |
||
5282 | 5521 | // survey says ... |
5283 | 5522 | if ($written_bytes !== strlen($write_settings) && !$settings_backup_fail) |
5284 | 5523 | { |
5285 | - if (file_exists($boarddir . '/Settings_bak.php')) |
|
5286 | - @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
5524 | + if (file_exists($boarddir . '/Settings_bak.php')) { |
|
5525 | + @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
5526 | + } |
|
5287 | 5527 | |
5288 | 5528 | return throw_error('The upgrader detected a bad Settings file and reverted the changes. Unable to migrate your Settings file to a new version.'); |
5289 | 5529 | } |
@@ -5291,9 +5531,10 @@ discard block |
||
5291 | 5531 | |
5292 | 5532 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
5293 | 5533 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
5294 | - if (function_exists('opcache_invalidate')) |
|
5295 | - opcache_invalidate($boarddir . '/Settings.php', true); |
|
5296 | -} |
|
5534 | + if (function_exists('opcache_invalidate')) { |
|
5535 | + opcache_invalidate($boarddir . '/Settings.php', true); |
|
5536 | + } |
|
5537 | + } |
|
5297 | 5538 | |
5298 | 5539 | /** |
5299 | 5540 | * Determine if we should auto select the migrate Settings file. This is determined by a variety of missing settings. |
@@ -5310,23 +5551,27 @@ discard block |
||
5310 | 5551 | global $boarddir, $packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled, $db_show_debug; |
5311 | 5552 | |
5312 | 5553 | // We should not migrate if db_show_debug is in there, some dev stuff going on here. |
5313 | - if (isset($db_show_debug)) |
|
5314 | - return false; |
|
5554 | + if (isset($db_show_debug)) { |
|
5555 | + return false; |
|
5556 | + } |
|
5315 | 5557 | |
5316 | 5558 | $file_contents = file_get_contents($boarddir . '/Settings.php'); |
5317 | 5559 | |
5318 | 5560 | // Is there a include statement somewhere in there? Some advanced handling of the variables elsewhere? |
5319 | 5561 | // Try our best to stay away from the cachedir match. |
5320 | - if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) |
|
5321 | - return false; |
|
5562 | + if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) { |
|
5563 | + return false; |
|
5564 | + } |
|
5322 | 5565 | |
5323 | 5566 | // If we find a mention of $GLOBALS, there may be a integration going on. |
5324 | - if (preg_match('~\$GLOBALS\[~im', $file_contents)) |
|
5325 | - return false; |
|
5567 | + if (preg_match('~\$GLOBALS\[~im', $file_contents)) { |
|
5568 | + return false; |
|
5569 | + } |
|
5326 | 5570 | |
5327 | 5571 | // If these are not set, it makes us a canidate to migrate. |
5328 | - if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) |
|
5329 | - return true; |
|
5572 | + if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) { |
|
5573 | + return true; |
|
5574 | + } |
|
5330 | 5575 | |
5331 | 5576 | return false; |
5332 | 5577 | } |
@@ -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 | * The main entrance point for the Manage Members screen. |
@@ -109,12 +110,13 @@ discard block |
||
109 | 110 | $context['tabs'][$context['last_tab']]['is_last'] = true; |
110 | 111 | |
111 | 112 | // Find the active tab. |
112 | - if (isset($context['tabs'][$context['current_subaction']])) |
|
113 | - $context['tabs'][$context['current_subaction']]['is_selected'] = true; |
|
114 | - elseif (isset($context['current_subaction'])) |
|
115 | - foreach ($context['tabs'] as $id_tab => $tab_data) |
|
113 | + if (isset($context['tabs'][$context['current_subaction']])) { |
|
114 | + $context['tabs'][$context['current_subaction']]['is_selected'] = true; |
|
115 | + } elseif (isset($context['current_subaction'])) { |
|
116 | + foreach ($context['tabs'] as $id_tab => $tab_data) |
|
116 | 117 | if (!empty($tab_data['selected_actions']) && in_array($context['current_subaction'], $tab_data['selected_actions'])) |
117 | 118 | $context['tabs'][$id_tab]['is_selected'] = true; |
119 | + } |
|
118 | 120 | |
119 | 121 | call_helper($subActions[$context['current_subaction']][0]); |
120 | 122 | } |
@@ -144,8 +146,9 @@ discard block |
||
144 | 146 | foreach ($_POST['delete'] as $key => $value) |
145 | 147 | { |
146 | 148 | // Don't delete yourself, idiot. |
147 | - if ($value != $user_info['id']) |
|
148 | - $delete[$key] = (int) $value; |
|
149 | + if ($value != $user_info['id']) { |
|
150 | + $delete[$key] = (int) $value; |
|
151 | + } |
|
149 | 152 | } |
150 | 153 | |
151 | 154 | if (!empty($delete)) |
@@ -181,17 +184,18 @@ discard block |
||
181 | 184 | ); |
182 | 185 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
183 | 186 | { |
184 | - if ($row['min_posts'] == -1) |
|
185 | - $context['membergroups'][] = array( |
|
187 | + if ($row['min_posts'] == -1) { |
|
188 | + $context['membergroups'][] = array( |
|
186 | 189 | 'id' => $row['id_group'], |
187 | 190 | 'name' => $row['group_name'], |
188 | 191 | 'can_be_additional' => true |
189 | 192 | ); |
190 | - else |
|
191 | - $context['postgroups'][] = array( |
|
193 | + } else { |
|
194 | + $context['postgroups'][] = array( |
|
192 | 195 | 'id' => $row['id_group'], |
193 | 196 | 'name' => $row['group_name'] |
194 | 197 | ); |
198 | + } |
|
195 | 199 | } |
196 | 200 | $smcFunc['db_free_result']($request); |
197 | 201 | |
@@ -263,14 +267,15 @@ discard block |
||
263 | 267 | call_integration_hook('integrate_view_members_params', array(&$params)); |
264 | 268 | |
265 | 269 | $search_params = array(); |
266 | - if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) |
|
267 | - $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
268 | - elseif (!empty($_POST)) |
|
270 | + if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) { |
|
271 | + $search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true); |
|
272 | + } elseif (!empty($_POST)) |
|
269 | 273 | { |
270 | 274 | $search_params['types'] = $_POST['types']; |
271 | - foreach ($params as $param_name => $param_info) |
|
272 | - if (isset($_POST[$param_name])) |
|
275 | + foreach ($params as $param_name => $param_info) { |
|
276 | + if (isset($_POST[$param_name])) |
|
273 | 277 | $search_params[$param_name] = $_POST[$param_name]; |
278 | + } |
|
274 | 279 | } |
275 | 280 | |
276 | 281 | $search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null; |
@@ -283,34 +288,38 @@ discard block |
||
283 | 288 | foreach ($params as $param_name => $param_info) |
284 | 289 | { |
285 | 290 | // Not filled in? |
286 | - if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') |
|
287 | - continue; |
|
291 | + if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') { |
|
292 | + continue; |
|
293 | + } |
|
288 | 294 | |
289 | 295 | // Make sure numeric values are really numeric. |
290 | - if (in_array($param_info['type'], array('int', 'age'))) |
|
291 | - $search_params[$param_name] = (int) $search_params[$param_name]; |
|
296 | + if (in_array($param_info['type'], array('int', 'age'))) { |
|
297 | + $search_params[$param_name] = (int) $search_params[$param_name]; |
|
298 | + } |
|
292 | 299 | // Date values have to match the specified format. |
293 | 300 | elseif ($param_info['type'] == 'date') |
294 | 301 | { |
295 | 302 | // Check if this date format is valid. |
296 | - if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) |
|
297 | - continue; |
|
303 | + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) { |
|
304 | + continue; |
|
305 | + } |
|
298 | 306 | |
299 | 307 | $search_params[$param_name] = strtotime($search_params[$param_name]); |
300 | - } |
|
301 | - elseif ($param_info['type'] == 'inet') |
|
308 | + } elseif ($param_info['type'] == 'inet') |
|
302 | 309 | { |
303 | 310 | $search_params[$param_name] = ip2range($search_params[$param_name]); |
304 | - if (empty($search_params[$param_name])) |
|
305 | - continue; |
|
311 | + if (empty($search_params[$param_name])) { |
|
312 | + continue; |
|
313 | + } |
|
306 | 314 | } |
307 | 315 | |
308 | 316 | // Those values that are in some kind of range (<, <=, =, >=, >). |
309 | 317 | if (!empty($param_info['range'])) |
310 | 318 | { |
311 | 319 | // Default to '=', just in case... |
312 | - if (empty($range_trans[$search_params['types'][$param_name]])) |
|
313 | - $search_params['types'][$param_name] = '='; |
|
320 | + if (empty($range_trans[$search_params['types'][$param_name]])) { |
|
321 | + $search_params['types'][$param_name] = '='; |
|
322 | + } |
|
314 | 323 | |
315 | 324 | // Handle special case 'age'. |
316 | 325 | if ($param_info['type'] == 'age') |
@@ -338,16 +347,17 @@ discard block |
||
338 | 347 | elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=') |
339 | 348 | { |
340 | 349 | $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400); |
350 | + } else { |
|
351 | + $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
341 | 352 | } |
342 | - else |
|
343 | - $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
344 | 353 | } |
345 | 354 | // Checkboxes. |
346 | 355 | elseif ($param_info['type'] == 'checkbox') |
347 | 356 | { |
348 | 357 | // Each checkbox or no checkbox at all is checked -> ignore. |
349 | - if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) |
|
350 | - continue; |
|
358 | + if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) { |
|
359 | + continue; |
|
360 | + } |
|
351 | 361 | |
352 | 362 | $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})'; |
353 | 363 | $where_params[$param_name . '_check'] = $search_params[$param_name]; |
@@ -359,24 +369,23 @@ discard block |
||
359 | 369 | { |
360 | 370 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})'; |
361 | 371 | $where_params[$param_name] = $search_params[$param_name][0]; |
362 | - } |
|
363 | - elseif (count($search_params[$param_name]) === 2) |
|
372 | + } elseif (count($search_params[$param_name]) === 2) |
|
364 | 373 | { |
365 | 374 | $query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})'; |
366 | 375 | $where_params[$param_name.'_low'] = $search_params[$param_name]['low']; |
367 | 376 | $where_params[$param_name.'_high'] = $search_params[$param_name]['high']; |
368 | 377 | } |
369 | 378 | |
370 | - } |
|
371 | - elseif ($param_info['type'] != 'groups') |
|
379 | + } elseif ($param_info['type'] != 'groups') |
|
372 | 380 | { |
373 | 381 | // Replace the wildcard characters ('*' and '?') into MySQL ones. |
374 | 382 | $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'))); |
375 | 383 | |
376 | - if ($smcFunc['db_case_sensitive']) |
|
377 | - $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
378 | - else |
|
379 | - $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
384 | + if ($smcFunc['db_case_sensitive']) { |
|
385 | + $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
386 | + } else { |
|
387 | + $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
388 | + } |
|
380 | 389 | $where_params[$param_name . '_normal'] = '%' . $parameter . '%'; |
381 | 390 | } |
382 | 391 | } |
@@ -392,16 +401,18 @@ discard block |
||
392 | 401 | } |
393 | 402 | |
394 | 403 | // Additional membergroups (these are only relevant if not all primary groups where selected!). |
395 | - if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) |
|
396 | - foreach ($search_params['membergroups'][2] as $mg) |
|
404 | + if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) { |
|
405 | + foreach ($search_params['membergroups'][2] as $mg) |
|
397 | 406 | { |
398 | 407 | $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0'; |
408 | + } |
|
399 | 409 | $where_params['add_group_' . $mg] = $mg; |
400 | 410 | } |
401 | 411 | |
402 | 412 | // Combine the one or two membergroup parts into one query part linked with an OR. |
403 | - if (!empty($mg_query_parts)) |
|
404 | - $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
413 | + if (!empty($mg_query_parts)) { |
|
414 | + $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
415 | + } |
|
405 | 416 | |
406 | 417 | // Get all selected post count related membergroups. |
407 | 418 | if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups'])) |
@@ -413,9 +424,9 @@ discard block |
||
413 | 424 | // Construct the where part of the query. |
414 | 425 | $where = empty($query_parts) ? '1=1' : implode(' |
415 | 426 | AND ', $query_parts); |
427 | + } else { |
|
428 | + $search_url_params = null; |
|
416 | 429 | } |
417 | - else |
|
418 | - $search_url_params = null; |
|
419 | 430 | |
420 | 431 | // Construct the additional URL part with the query info in it. |
421 | 432 | $context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : ''; |
@@ -538,28 +549,32 @@ discard block |
||
538 | 549 | 'function' => function($rowData) use ($txt) |
539 | 550 | { |
540 | 551 | // Calculate number of days since last online. |
541 | - if (empty($rowData['last_login'])) |
|
542 | - $difference = $txt['never']; |
|
543 | - else |
|
552 | + if (empty($rowData['last_login'])) { |
|
553 | + $difference = $txt['never']; |
|
554 | + } else |
|
544 | 555 | { |
545 | 556 | $num_days_difference = jeffsdatediff($rowData['last_login']); |
546 | 557 | |
547 | 558 | // Today. |
548 | - if (empty($num_days_difference)) |
|
549 | - $difference = $txt['viewmembers_today']; |
|
559 | + if (empty($num_days_difference)) { |
|
560 | + $difference = $txt['viewmembers_today']; |
|
561 | + } |
|
550 | 562 | |
551 | 563 | // Yesterday. |
552 | - elseif ($num_days_difference == 1) |
|
553 | - $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
564 | + elseif ($num_days_difference == 1) { |
|
565 | + $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
566 | + } |
|
554 | 567 | |
555 | 568 | // X days ago. |
556 | - else |
|
557 | - $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
569 | + else { |
|
570 | + $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
571 | + } |
|
558 | 572 | } |
559 | 573 | |
560 | 574 | // Show it in italics if they're not activated... |
561 | - if ($rowData['is_activated'] % 10 != 1) |
|
562 | - $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
575 | + if ($rowData['is_activated'] % 10 != 1) { |
|
576 | + $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
577 | + } |
|
563 | 578 | |
564 | 579 | return $difference; |
565 | 580 | }, |
@@ -611,8 +626,9 @@ discard block |
||
611 | 626 | ); |
612 | 627 | |
613 | 628 | // Without enough permissions, don't show 'delete members' checkboxes. |
614 | - if (!allowedTo('profile_remove_any')) |
|
615 | - unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
629 | + if (!allowedTo('profile_remove_any')) { |
|
630 | + unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
631 | + } |
|
616 | 632 | |
617 | 633 | require_once($sourcedir . '/Subs-List.php'); |
618 | 634 | createList($listOptions); |
@@ -655,17 +671,18 @@ discard block |
||
655 | 671 | ); |
656 | 672 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
657 | 673 | { |
658 | - if ($row['min_posts'] == -1) |
|
659 | - $context['membergroups'][] = array( |
|
674 | + if ($row['min_posts'] == -1) { |
|
675 | + $context['membergroups'][] = array( |
|
660 | 676 | 'id' => $row['id_group'], |
661 | 677 | 'name' => $row['group_name'], |
662 | 678 | 'can_be_additional' => true |
663 | 679 | ); |
664 | - else |
|
665 | - $context['postgroups'][] = array( |
|
680 | + } else { |
|
681 | + $context['postgroups'][] = array( |
|
666 | 682 | 'id' => $row['id_group'], |
667 | 683 | 'name' => $row['group_name'] |
668 | 684 | ); |
685 | + } |
|
669 | 686 | } |
670 | 687 | $smcFunc['db_free_result']($request); |
671 | 688 | |
@@ -692,8 +709,9 @@ discard block |
||
692 | 709 | $context['page_title'] = $txt['admin_members']; |
693 | 710 | $context['sub_template'] = 'admin_browse'; |
694 | 711 | $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve'); |
695 | - if (isset($context['tabs'][$context['browse_type']])) |
|
696 | - $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
712 | + if (isset($context['tabs'][$context['browse_type']])) { |
|
713 | + $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
714 | + } |
|
697 | 715 | |
698 | 716 | // Allowed filters are those we can have, in theory. |
699 | 717 | $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2); |
@@ -704,18 +722,20 @@ discard block |
||
704 | 722 | foreach ($context['activation_numbers'] as $type => $amount) |
705 | 723 | { |
706 | 724 | // We have some of these... |
707 | - if (in_array($type, $context['allowed_filters']) && $amount > 0) |
|
708 | - $context['available_filters'][] = array( |
|
725 | + if (in_array($type, $context['allowed_filters']) && $amount > 0) { |
|
726 | + $context['available_filters'][] = array( |
|
709 | 727 | 'type' => $type, |
710 | 728 | 'amount' => $amount, |
711 | 729 | 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?', |
712 | 730 | 'selected' => $type == $context['current_filter'] |
713 | 731 | ); |
732 | + } |
|
714 | 733 | } |
715 | 734 | |
716 | 735 | // If the filter was not sent, set it to whatever has people in it! |
717 | - if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) |
|
718 | - $context['current_filter'] = $context['available_filters'][0]['type']; |
|
736 | + if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) { |
|
737 | + $context['current_filter'] = $context['available_filters'][0]['type']; |
|
738 | + } |
|
719 | 739 | |
720 | 740 | // This little variable is used to determine if we should flag where we are looking. |
721 | 741 | $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1; |
@@ -730,44 +750,47 @@ discard block |
||
730 | 750 | ); |
731 | 751 | |
732 | 752 | // Are we showing duplicate information? |
733 | - if (isset($_GET['showdupes'])) |
|
734 | - $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
753 | + if (isset($_GET['showdupes'])) { |
|
754 | + $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
755 | + } |
|
735 | 756 | $context['show_duplicates'] = !empty($_SESSION['showdupes']); |
736 | 757 | |
737 | 758 | // Determine which actions we should allow on this page. |
738 | 759 | if ($context['browse_type'] == 'approve') |
739 | 760 | { |
740 | 761 | // If we are approving deleted accounts we have a slightly different list... actually a mirror ;) |
741 | - if ($context['current_filter'] == 4) |
|
742 | - $context['allowed_actions'] = array( |
|
762 | + if ($context['current_filter'] == 4) { |
|
763 | + $context['allowed_actions'] = array( |
|
743 | 764 | 'reject' => $txt['admin_browse_w_approve_deletion'], |
744 | 765 | 'ok' => $txt['admin_browse_w_reject'], |
745 | 766 | ); |
746 | - else |
|
747 | - $context['allowed_actions'] = array( |
|
767 | + } else { |
|
768 | + $context['allowed_actions'] = array( |
|
748 | 769 | 'ok' => $txt['admin_browse_w_approve'], |
749 | 770 | 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'], |
750 | 771 | 'require_activation' => $txt['admin_browse_w_approve_require_activate'], |
751 | 772 | 'reject' => $txt['admin_browse_w_reject'], |
752 | 773 | 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'], |
753 | 774 | ); |
754 | - } |
|
755 | - elseif ($context['browse_type'] == 'activate') |
|
756 | - $context['allowed_actions'] = array( |
|
775 | + } |
|
776 | + } elseif ($context['browse_type'] == 'activate') { |
|
777 | + $context['allowed_actions'] = array( |
|
757 | 778 | 'ok' => $txt['admin_browse_w_activate'], |
758 | 779 | 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'], |
759 | 780 | 'delete' => $txt['admin_browse_w_delete'], |
760 | 781 | 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'], |
761 | 782 | 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'], |
762 | 783 | ); |
784 | + } |
|
763 | 785 | |
764 | 786 | // Create an option list for actions allowed to be done with selected members. |
765 | 787 | $allowed_actions = ' |
766 | 788 | <option selected value="">' . $txt['admin_browse_with_selected'] . ':</option> |
767 | 789 | <option value="" disabled>-----------------------------</option>'; |
768 | - foreach ($context['allowed_actions'] as $key => $desc) |
|
769 | - $allowed_actions .= ' |
|
790 | + foreach ($context['allowed_actions'] as $key => $desc) { |
|
791 | + $allowed_actions .= ' |
|
770 | 792 | <option value="' . $key . '">' . $desc . '</option>'; |
793 | + } |
|
771 | 794 | |
772 | 795 | // Setup the Javascript function for selecting an action for the list. |
773 | 796 | $javascript = ' |
@@ -779,15 +802,16 @@ discard block |
||
779 | 802 | var message = "";'; |
780 | 803 | |
781 | 804 | // We have special messages for approving deletion of accounts - it's surprisingly logical - honest. |
782 | - if ($context['current_filter'] == 4) |
|
783 | - $javascript .= ' |
|
805 | + if ($context['current_filter'] == 4) { |
|
806 | + $javascript .= ' |
|
784 | 807 | if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
785 | 808 | message = "' . $txt['admin_browse_w_delete'] . '"; |
786 | 809 | else |
787 | 810 | message = "' . $txt['admin_browse_w_reject'] . '";'; |
811 | + } |
|
788 | 812 | // Otherwise a nice standard message. |
789 | - else |
|
790 | - $javascript .= ' |
|
813 | + else { |
|
814 | + $javascript .= ' |
|
791 | 815 | if (document.forms.postForm.todo.value.indexOf("delete") != -1) |
792 | 816 | message = "' . $txt['admin_browse_w_delete'] . '"; |
793 | 817 | else if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
@@ -796,6 +820,7 @@ discard block |
||
796 | 820 | message = "' . $txt['admin_browse_w_remind'] . '"; |
797 | 821 | else |
798 | 822 | message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";'; |
823 | + } |
|
799 | 824 | $javascript .= ' |
800 | 825 | if (confirm(message + " ' . $txt['admin_browse_warn'] . '")) |
801 | 826 | document.forms.postForm.submit(); |
@@ -928,10 +953,11 @@ discard block |
||
928 | 953 | $member_links = array(); |
929 | 954 | foreach ($rowData['duplicate_members'] as $member) |
930 | 955 | { |
931 | - if ($member['id']) |
|
932 | - $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
933 | - else |
|
934 | - $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
956 | + if ($member['id']) { |
|
957 | + $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
958 | + } else { |
|
959 | + $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
960 | + } |
|
935 | 961 | } |
936 | 962 | return implode(', ', $member_links); |
937 | 963 | }, |
@@ -980,14 +1006,16 @@ discard block |
||
980 | 1006 | ); |
981 | 1007 | |
982 | 1008 | // Pick what column to actually include if we're showing duplicates. |
983 | - if ($context['show_duplicates']) |
|
984 | - unset($listOptions['columns']['email']); |
|
985 | - else |
|
986 | - unset($listOptions['columns']['duplicates']); |
|
1009 | + if ($context['show_duplicates']) { |
|
1010 | + unset($listOptions['columns']['email']); |
|
1011 | + } else { |
|
1012 | + unset($listOptions['columns']['duplicates']); |
|
1013 | + } |
|
987 | 1014 | |
988 | 1015 | // Only show hostname on duplicates as it takes a lot of time. |
989 | - if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) |
|
990 | - unset($listOptions['columns']['hostname']); |
|
1016 | + if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) { |
|
1017 | + unset($listOptions['columns']['hostname']); |
|
1018 | + } |
|
991 | 1019 | |
992 | 1020 | // Is there any need to show filters? |
993 | 1021 | if (isset($context['available_filters']) && count($context['available_filters']) > 1) |
@@ -995,9 +1023,10 @@ discard block |
||
995 | 1023 | $filterOptions = ' |
996 | 1024 | <strong>' . $txt['admin_browse_filter_by'] . ':</strong> |
997 | 1025 | <select name="filter" onchange="this.form.submit();">'; |
998 | - foreach ($context['available_filters'] as $filter) |
|
999 | - $filterOptions .= ' |
|
1026 | + foreach ($context['available_filters'] as $filter) { |
|
1027 | + $filterOptions .= ' |
|
1000 | 1028 | <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>'; |
1029 | + } |
|
1001 | 1030 | $filterOptions .= ' |
1002 | 1031 | </select> |
1003 | 1032 | <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>'; |
@@ -1009,12 +1038,13 @@ discard block |
||
1009 | 1038 | } |
1010 | 1039 | |
1011 | 1040 | // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at. |
1012 | - if (!empty($context['show_filter']) && !empty($context['available_filters'])) |
|
1013 | - $listOptions['additional_rows'][] = array( |
|
1041 | + if (!empty($context['show_filter']) && !empty($context['available_filters'])) { |
|
1042 | + $listOptions['additional_rows'][] = array( |
|
1014 | 1043 | 'position' => 'above_column_headers', |
1015 | 1044 | 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . ((isset($context['current_filter']) && isset($txt['admin_browse_filter_type_'.$context['current_filter']])) ? $txt['admin_browse_filter_type_'.$context['current_filter']] : $context['available_filters'][0]['desc']), |
1016 | 1045 | 'class' => 'filter_row generic_list_wrapper smalltext', |
1017 | 1046 | ); |
1047 | + } |
|
1018 | 1048 | |
1019 | 1049 | // Now that we have all the options, create the list. |
1020 | 1050 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1044,12 +1074,14 @@ discard block |
||
1044 | 1074 | $current_filter = (int) $_REQUEST['orig_filter']; |
1045 | 1075 | |
1046 | 1076 | // If we are applying a filter do just that - then redirect. |
1047 | - if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) |
|
1048 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1077 | + if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) { |
|
1078 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1079 | + } |
|
1049 | 1080 | |
1050 | 1081 | // Nothing to do? |
1051 | - if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) |
|
1052 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1082 | + if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) { |
|
1083 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1084 | + } |
|
1053 | 1085 | |
1054 | 1086 | // Are we dealing with members who have been waiting for > set amount of time? |
1055 | 1087 | if (isset($_POST['time_passed'])) |
@@ -1062,8 +1094,9 @@ discard block |
||
1062 | 1094 | else |
1063 | 1095 | { |
1064 | 1096 | $members = array(); |
1065 | - foreach ($_POST['todoAction'] as $id) |
|
1066 | - $members[] = (int) $id; |
|
1097 | + foreach ($_POST['todoAction'] as $id) { |
|
1098 | + $members[] = (int) $id; |
|
1099 | + } |
|
1067 | 1100 | $condition = ' |
1068 | 1101 | AND id_member IN ({array_int:members})'; |
1069 | 1102 | } |
@@ -1084,8 +1117,9 @@ discard block |
||
1084 | 1117 | $member_count = $smcFunc['db_num_rows']($request); |
1085 | 1118 | |
1086 | 1119 | // If no results then just return! |
1087 | - if ($member_count == 0) |
|
1088 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1120 | + if ($member_count == 0) { |
|
1121 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1122 | + } |
|
1089 | 1123 | |
1090 | 1124 | $member_info = array(); |
1091 | 1125 | $members = array(); |
@@ -1124,8 +1158,9 @@ discard block |
||
1124 | 1158 | // Do we have to let the integration code know about the activations? |
1125 | 1159 | if (!empty($modSettings['integrate_activate'])) |
1126 | 1160 | { |
1127 | - foreach ($member_info as $member) |
|
1128 | - call_integration_hook('integrate_activate', array($member['username'])); |
|
1161 | + foreach ($member_info as $member) { |
|
1162 | + call_integration_hook('integrate_activate', array($member['username'])); |
|
1163 | + } |
|
1129 | 1164 | } |
1130 | 1165 | |
1131 | 1166 | // Check for email. |
@@ -1255,20 +1290,23 @@ discard block |
||
1255 | 1290 | $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; |
1256 | 1291 | |
1257 | 1292 | require_once($sourcedir . '/Logging.php'); |
1258 | - foreach ($member_info as $member) |
|
1259 | - logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1293 | + foreach ($member_info as $member) { |
|
1294 | + logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1295 | + } |
|
1260 | 1296 | } |
1261 | 1297 | |
1262 | 1298 | // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). |
1263 | - if (in_array($current_filter, array(3, 4, 5))) |
|
1264 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1299 | + if (in_array($current_filter, array(3, 4, 5))) { |
|
1300 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1301 | + } |
|
1265 | 1302 | |
1266 | 1303 | // Update the member's stats. (but, we know the member didn't change their name.) |
1267 | 1304 | updateStats('member', false); |
1268 | 1305 | |
1269 | 1306 | // If they haven't been deleted, update the post group statistics on them... |
1270 | - if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) |
|
1271 | - updateStats('postgroups', $members); |
|
1307 | + if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) { |
|
1308 | + updateStats('postgroups', $members); |
|
1309 | + } |
|
1272 | 1310 | |
1273 | 1311 | redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
1274 | 1312 | } |
@@ -1293,10 +1331,11 @@ discard block |
||
1293 | 1331 | $dis = time() - $old; |
1294 | 1332 | |
1295 | 1333 | // Before midnight? |
1296 | - if ($dis < $sinceMidnight) |
|
1297 | - return 0; |
|
1298 | - else |
|
1299 | - $dis -= $sinceMidnight; |
|
1334 | + if ($dis < $sinceMidnight) { |
|
1335 | + return 0; |
|
1336 | + } else { |
|
1337 | + $dis -= $sinceMidnight; |
|
1338 | + } |
|
1300 | 1339 | |
1301 | 1340 | // Divide out the seconds in a day to get the number of days. |
1302 | 1341 | return ceil($dis / (24 * 60 * 60)); |
@@ -1323,16 +1362,18 @@ discard block |
||
1323 | 1362 | $context['activation_numbers'] = array(); |
1324 | 1363 | $context['awaiting_activation'] = 0; |
1325 | 1364 | $context['awaiting_approval'] = 0; |
1326 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1327 | - $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
1365 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1366 | + $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
1367 | + } |
|
1328 | 1368 | $smcFunc['db_free_result']($request); |
1329 | 1369 | |
1330 | 1370 | foreach ($context['activation_numbers'] as $activation_type => $total_members) |
1331 | 1371 | { |
1332 | - if (in_array($activation_type, array(0, 2))) |
|
1333 | - $context['awaiting_activation'] += $total_members; |
|
1334 | - elseif (in_array($activation_type, array(3, 4, 5))) |
|
1335 | - $context['awaiting_approval'] += $total_members; |
|
1372 | + if (in_array($activation_type, array(0, 2))) { |
|
1373 | + $context['awaiting_activation'] += $total_members; |
|
1374 | + } elseif (in_array($activation_type, array(3, 4, 5))) { |
|
1375 | + $context['awaiting_approval'] += $total_members; |
|
1376 | + } |
|
1336 | 1377 | } |
1337 | 1378 | |
1338 | 1379 | } |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
21 | 21 | |
22 | 22 | // Let's pull in useful classes |
23 | -if (!defined('SMF')) |
|
23 | +if (!defined('SMF')) { |
|
24 | 24 | define('SMF', 1); |
25 | +} |
|
25 | 26 | |
26 | 27 | require_once('Sources/Class-Package.php'); |
27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | |
64 | 65 | list ($charcode) = pg_fetch_row($request); |
65 | 66 | |
66 | - if ($charcode == 'UTF8') |
|
67 | - return true; |
|
68 | - else |
|
69 | - return false; |
|
67 | + if ($charcode == 'UTF8') { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
70 | 72 | }, |
71 | 73 | 'utf8_version' => '8.0', |
72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
77 | 79 | |
78 | 80 | // Is it reserved? |
79 | - if ($value == 'pg_') |
|
80 | - return $txt['error_db_prefix_reserved']; |
|
81 | + if ($value == 'pg_') { |
|
82 | + return $txt['error_db_prefix_reserved']; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Is the prefix numeric? |
83 | - if (preg_match('~^\d~', $value)) |
|
84 | - return $txt['error_db_prefix_numeric']; |
|
86 | + if (preg_match('~^\d~', $value)) { |
|
87 | + return $txt['error_db_prefix_numeric']; |
|
88 | + } |
|
85 | 89 | |
86 | 90 | return true; |
87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
128 | 132 | $incontext['skip'] = false; |
129 | 133 | |
130 | 134 | // Call the step and if it returns false that means pause! |
131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
132 | - break; |
|
133 | - elseif (function_exists($step[2])) |
|
134 | - $incontext['current_step']++; |
|
135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
136 | + break; |
|
137 | + } elseif (function_exists($step[2])) { |
|
138 | + $incontext['current_step']++; |
|
139 | + } |
|
135 | 140 | |
136 | 141 | // No warnings pass on. |
137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
147 | 152 | global $databases; |
148 | 153 | |
149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
157 | + } |
|
152 | 158 | |
153 | 159 | // Enable error reporting for fatal errors. |
154 | 160 | error_reporting(E_ERROR | E_PARSE); |
@@ -164,21 +170,23 @@ discard block |
||
164 | 170 | { |
165 | 171 | ob_start(); |
166 | 172 | |
167 | - if (ini_get('session.save_handler') == 'user') |
|
168 | - @ini_set('session.save_handler', 'files'); |
|
169 | - if (function_exists('session_start')) |
|
170 | - @session_start(); |
|
171 | - } |
|
172 | - else |
|
173 | + if (ini_get('session.save_handler') == 'user') { |
|
174 | + @ini_set('session.save_handler', 'files'); |
|
175 | + } |
|
176 | + if (function_exists('session_start')) { |
|
177 | + @session_start(); |
|
178 | + } |
|
179 | + } else |
|
173 | 180 | { |
174 | 181 | ob_start('ob_gzhandler'); |
175 | 182 | |
176 | - if (ini_get('session.save_handler') == 'user') |
|
177 | - @ini_set('session.save_handler', 'files'); |
|
183 | + if (ini_get('session.save_handler') == 'user') { |
|
184 | + @ini_set('session.save_handler', 'files'); |
|
185 | + } |
|
178 | 186 | session_start(); |
179 | 187 | |
180 | - if (!headers_sent()) |
|
181 | - echo '<!DOCTYPE html> |
|
188 | + if (!headers_sent()) { |
|
189 | + echo '<!DOCTYPE html> |
|
182 | 190 | <html> |
183 | 191 | <head> |
184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
188 | 196 | </body> |
189 | 197 | </html>'; |
198 | + } |
|
190 | 199 | exit; |
191 | 200 | } |
192 | 201 | |
193 | 202 | // Add slashes, as long as they aren't already being added. |
194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
195 | - foreach ($_POST as $k => $v) |
|
203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
204 | + foreach ($_POST as $k => $v) |
|
196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
197 | 206 | $_POST[$k] = addslashes($v); |
207 | + } |
|
198 | 208 | |
199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
215 | 225 | $ftp->close(); |
216 | 226 | |
217 | 227 | unset($_SESSION['installer_temp_ftp']); |
218 | - } |
|
219 | - else |
|
228 | + } else |
|
220 | 229 | { |
221 | 230 | @unlink(__FILE__); |
222 | 231 | |
@@ -230,10 +239,11 @@ discard block |
||
230 | 239 | // Now just redirect to a blank.png... |
231 | 240 | $secure = false; |
232 | 241 | |
233 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
234 | - $secure = true; |
|
235 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
236 | - $secure = true; |
|
242 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
243 | + $secure = true; |
|
244 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
245 | + $secure = true; |
|
246 | + } |
|
237 | 247 | |
238 | 248 | header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); |
239 | 249 | exit; |
@@ -244,10 +254,11 @@ discard block |
||
244 | 254 | { |
245 | 255 | // Get PHP's default timezone, if set |
246 | 256 | $ini_tz = ini_get('date.timezone'); |
247 | - if (!empty($ini_tz)) |
|
248 | - $timezone_id = $ini_tz; |
|
249 | - else |
|
250 | - $timezone_id = ''; |
|
257 | + if (!empty($ini_tz)) { |
|
258 | + $timezone_id = $ini_tz; |
|
259 | + } else { |
|
260 | + $timezone_id = ''; |
|
261 | + } |
|
251 | 262 | |
252 | 263 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
253 | 264 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -277,8 +288,9 @@ discard block |
||
277 | 288 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
278 | 289 | while ($entry = $dir->read()) |
279 | 290 | { |
280 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
281 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
291 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
292 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
293 | + } |
|
282 | 294 | } |
283 | 295 | $dir->close(); |
284 | 296 | } |
@@ -325,10 +337,11 @@ discard block |
||
325 | 337 | } |
326 | 338 | |
327 | 339 | // Override the language file? |
328 | - if (isset($_GET['lang_file'])) |
|
329 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
330 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
331 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
340 | + if (isset($_GET['lang_file'])) { |
|
341 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
342 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
343 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
344 | + } |
|
332 | 345 | |
333 | 346 | // Make sure it exists, if it doesn't reset it. |
334 | 347 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -337,8 +350,9 @@ discard block |
||
337 | 350 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
338 | 351 | |
339 | 352 | // If we have english and some other language, use the other language. We Americans hate english :P. |
340 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
341 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
353 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
354 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
355 | + } |
|
342 | 356 | } |
343 | 357 | |
344 | 358 | // And now include the actual language file itself. |
@@ -355,15 +369,18 @@ discard block |
||
355 | 369 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port; |
356 | 370 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4; |
357 | 371 | |
358 | - if (empty($sourcedir)) |
|
359 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
372 | + if (empty($sourcedir)) { |
|
373 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
374 | + } |
|
360 | 375 | |
361 | 376 | // Need this to check whether we need the database password. |
362 | 377 | require(dirname(__FILE__) . '/Settings.php'); |
363 | - if (!defined('SMF')) |
|
364 | - define('SMF', 1); |
|
365 | - if (empty($smcFunc)) |
|
366 | - $smcFunc = array(); |
|
378 | + if (!defined('SMF')) { |
|
379 | + define('SMF', 1); |
|
380 | + } |
|
381 | + if (empty($smcFunc)) { |
|
382 | + $smcFunc = array(); |
|
383 | + } |
|
367 | 384 | |
368 | 385 | $modSettings['disableQueryCheck'] = true; |
369 | 386 | |
@@ -374,14 +391,17 @@ discard block |
||
374 | 391 | |
375 | 392 | $options = array('persist' => $db_persist); |
376 | 393 | |
377 | - if (!empty($db_port)) |
|
378 | - $options['port'] = $db_port; |
|
394 | + if (!empty($db_port)) { |
|
395 | + $options['port'] = $db_port; |
|
396 | + } |
|
379 | 397 | |
380 | - if (!empty($db_mb4)) |
|
381 | - $options['db_mb4'] = $db_mb4; |
|
398 | + if (!empty($db_mb4)) { |
|
399 | + $options['db_mb4'] = $db_mb4; |
|
400 | + } |
|
382 | 401 | |
383 | - if (!$db_connection) |
|
384 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
402 | + if (!$db_connection) { |
|
403 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
|
404 | + } |
|
385 | 405 | } |
386 | 406 | } |
387 | 407 | |
@@ -409,8 +429,9 @@ discard block |
||
409 | 429 | // @todo REMOVE THIS!! |
410 | 430 | else |
411 | 431 | { |
412 | - if (function_exists('doStep' . $_GET['step'])) |
|
413 | - call_user_func('doStep' . $_GET['step']); |
|
432 | + if (function_exists('doStep' . $_GET['step'])) { |
|
433 | + call_user_func('doStep' . $_GET['step']); |
|
434 | + } |
|
414 | 435 | } |
415 | 436 | // Show the footer. |
416 | 437 | template_install_below(); |
@@ -428,8 +449,9 @@ discard block |
||
428 | 449 | $incontext['sub_template'] = 'welcome_message'; |
429 | 450 | |
430 | 451 | // Done the submission? |
431 | - if (isset($_POST['contbutt'])) |
|
432 | - return true; |
|
452 | + if (isset($_POST['contbutt'])) { |
|
453 | + return true; |
|
454 | + } |
|
433 | 455 | |
434 | 456 | // See if we think they have already installed it? |
435 | 457 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -437,14 +459,17 @@ discard block |
||
437 | 459 | $probably_installed = 0; |
438 | 460 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
439 | 461 | { |
440 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
441 | - $probably_installed++; |
|
442 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
443 | - $probably_installed++; |
|
462 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
463 | + $probably_installed++; |
|
464 | + } |
|
465 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
466 | + $probably_installed++; |
|
467 | + } |
|
444 | 468 | } |
445 | 469 | |
446 | - if ($probably_installed == 2) |
|
447 | - $incontext['warning'] = $txt['error_already_installed']; |
|
470 | + if ($probably_installed == 2) { |
|
471 | + $incontext['warning'] = $txt['error_already_installed']; |
|
472 | + } |
|
448 | 473 | } |
449 | 474 | |
450 | 475 | // Is some database support even compiled in? |
@@ -459,45 +484,54 @@ discard block |
||
459 | 484 | $databases[$key]['supported'] = false; |
460 | 485 | $notFoundSQLFile = true; |
461 | 486 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
487 | + } else { |
|
488 | + $incontext['supported_databases'][] = $db; |
|
462 | 489 | } |
463 | - else |
|
464 | - $incontext['supported_databases'][] = $db; |
|
465 | 490 | } |
466 | 491 | } |
467 | 492 | |
468 | 493 | // Check the PHP version. |
469 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) |
|
470 | - $error = 'error_php_too_low'; |
|
494 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) { |
|
495 | + $error = 'error_php_too_low'; |
|
496 | + } |
|
471 | 497 | // Make sure we have a supported database |
472 | - elseif (empty($incontext['supported_databases'])) |
|
473 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
498 | + elseif (empty($incontext['supported_databases'])) { |
|
499 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
500 | + } |
|
474 | 501 | // How about session support? Some crazy sysadmin remove it? |
475 | - elseif (!function_exists('session_start')) |
|
476 | - $error = 'error_session_missing'; |
|
502 | + elseif (!function_exists('session_start')) { |
|
503 | + $error = 'error_session_missing'; |
|
504 | + } |
|
477 | 505 | // Make sure they uploaded all the files. |
478 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
479 | - $error = 'error_missing_files'; |
|
506 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
507 | + $error = 'error_missing_files'; |
|
508 | + } |
|
480 | 509 | // Very simple check on the session.save_path for Windows. |
481 | 510 | // @todo Move this down later if they don't use database-driven sessions? |
482 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
483 | - $error = 'error_session_save_path'; |
|
511 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
512 | + $error = 'error_session_save_path'; |
|
513 | + } |
|
484 | 514 | |
485 | 515 | // Since each of the three messages would look the same, anyway... |
486 | - if (isset($error)) |
|
487 | - $incontext['error'] = $txt[$error]; |
|
516 | + if (isset($error)) { |
|
517 | + $incontext['error'] = $txt[$error]; |
|
518 | + } |
|
488 | 519 | |
489 | 520 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
490 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
491 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
521 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
522 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
523 | + } |
|
492 | 524 | |
493 | 525 | // Confirm mbstring is loaded... |
494 | - if (!extension_loaded('mbstring')) |
|
495 | - $incontext['error'] = $txt['install_no_mbstring']; |
|
526 | + if (!extension_loaded('mbstring')) { |
|
527 | + $incontext['error'] = $txt['install_no_mbstring']; |
|
528 | + } |
|
496 | 529 | |
497 | 530 | // Check for https stream support. |
498 | 531 | $supported_streams = stream_get_wrappers(); |
499 | - if (!in_array('https', $supported_streams)) |
|
500 | - $incontext['warning'] = $txt['install_no_https']; |
|
532 | + if (!in_array('https', $supported_streams)) { |
|
533 | + $incontext['warning'] = $txt['install_no_https']; |
|
534 | + } |
|
501 | 535 | |
502 | 536 | return false; |
503 | 537 | } |
@@ -522,12 +556,14 @@ discard block |
||
522 | 556 | 'Settings_bak.php', |
523 | 557 | ); |
524 | 558 | |
525 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
526 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
559 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
560 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
561 | + } |
|
527 | 562 | |
528 | 563 | // With mod_security installed, we could attempt to fix it with .htaccess. |
529 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
530 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
564 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
565 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
566 | + } |
|
531 | 567 | |
532 | 568 | $failed_files = array(); |
533 | 569 | |
@@ -539,20 +575,23 @@ discard block |
||
539 | 575 | foreach ($writable_files as $file) |
540 | 576 | { |
541 | 577 | // Some files won't exist, try to address up front |
542 | - if (!file_exists(dirname(__FILE__) . '/' . $file)) |
|
543 | - @touch(dirname(__FILE__) . '/' . $file); |
|
578 | + if (!file_exists(dirname(__FILE__) . '/' . $file)) { |
|
579 | + @touch(dirname(__FILE__) . '/' . $file); |
|
580 | + } |
|
544 | 581 | // NOW do the writable check... |
545 | 582 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
546 | 583 | { |
547 | 584 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
548 | 585 | |
549 | 586 | // Well, 755 hopefully worked... if not, try 777. |
550 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
551 | - $failed_files[] = $file; |
|
587 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
588 | + $failed_files[] = $file; |
|
589 | + } |
|
552 | 590 | } |
553 | 591 | } |
554 | - foreach ($extra_files as $file) |
|
555 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
592 | + foreach ($extra_files as $file) { |
|
593 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
594 | + } |
|
556 | 595 | } |
557 | 596 | // Windows is trickier. Let's try opening for r+... |
558 | 597 | else |
@@ -562,30 +601,35 @@ discard block |
||
562 | 601 | foreach ($writable_files as $file) |
563 | 602 | { |
564 | 603 | // Folders can't be opened for write... but the index.php in them can ;) |
565 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
566 | - $file .= '/index.php'; |
|
604 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
605 | + $file .= '/index.php'; |
|
606 | + } |
|
567 | 607 | |
568 | 608 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
569 | 609 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
570 | 610 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
571 | 611 | |
572 | 612 | // Hmm, okay, try just for write in that case... |
573 | - if (!is_resource($fp)) |
|
574 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
613 | + if (!is_resource($fp)) { |
|
614 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
615 | + } |
|
575 | 616 | |
576 | - if (!is_resource($fp)) |
|
577 | - $failed_files[] = $file; |
|
617 | + if (!is_resource($fp)) { |
|
618 | + $failed_files[] = $file; |
|
619 | + } |
|
578 | 620 | |
579 | 621 | @fclose($fp); |
580 | 622 | } |
581 | - foreach ($extra_files as $file) |
|
582 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
623 | + foreach ($extra_files as $file) { |
|
624 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
625 | + } |
|
583 | 626 | } |
584 | 627 | |
585 | 628 | $failure = count($failed_files) >= 1; |
586 | 629 | |
587 | - if (!isset($_SERVER)) |
|
588 | - return !$failure; |
|
630 | + if (!isset($_SERVER)) { |
|
631 | + return !$failure; |
|
632 | + } |
|
589 | 633 | |
590 | 634 | // Put the list into context. |
591 | 635 | $incontext['failed_files'] = $failed_files; |
@@ -633,19 +677,23 @@ discard block |
||
633 | 677 | |
634 | 678 | if (!isset($ftp) || $ftp->error !== false) |
635 | 679 | { |
636 | - if (!isset($ftp)) |
|
637 | - $ftp = new ftp_connection(null); |
|
680 | + if (!isset($ftp)) { |
|
681 | + $ftp = new ftp_connection(null); |
|
682 | + } |
|
638 | 683 | // Save the error so we can mess with listing... |
639 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
640 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
684 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
685 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
686 | + } |
|
641 | 687 | |
642 | 688 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
643 | 689 | |
644 | - if (empty($_POST['ftp_path']) && $found_path) |
|
645 | - $_POST['ftp_path'] = $detect_path; |
|
690 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
691 | + $_POST['ftp_path'] = $detect_path; |
|
692 | + } |
|
646 | 693 | |
647 | - if (!isset($_POST['ftp_username'])) |
|
648 | - $_POST['ftp_username'] = $username; |
|
694 | + if (!isset($_POST['ftp_username'])) { |
|
695 | + $_POST['ftp_username'] = $username; |
|
696 | + } |
|
649 | 697 | |
650 | 698 | // Set the username etc, into context. |
651 | 699 | $incontext['ftp'] = array( |
@@ -657,8 +705,7 @@ discard block |
||
657 | 705 | ); |
658 | 706 | |
659 | 707 | return false; |
660 | - } |
|
661 | - else |
|
708 | + } else |
|
662 | 709 | { |
663 | 710 | $_SESSION['installer_temp_ftp'] = array( |
664 | 711 | 'server' => $_POST['ftp_server'], |
@@ -672,10 +719,12 @@ discard block |
||
672 | 719 | |
673 | 720 | foreach ($failed_files as $file) |
674 | 721 | { |
675 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
676 | - $ftp->chmod($file, 0755); |
|
677 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
678 | - $ftp->chmod($file, 0777); |
|
722 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
723 | + $ftp->chmod($file, 0755); |
|
724 | + } |
|
725 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
726 | + $ftp->chmod($file, 0777); |
|
727 | + } |
|
679 | 728 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
680 | 729 | { |
681 | 730 | $failed_files_updated[] = $file; |
@@ -731,15 +780,17 @@ discard block |
||
731 | 780 | |
732 | 781 | if (!$foundOne) |
733 | 782 | { |
734 | - if (isset($db['default_host'])) |
|
735 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
783 | + if (isset($db['default_host'])) { |
|
784 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
785 | + } |
|
736 | 786 | if (isset($db['default_user'])) |
737 | 787 | { |
738 | 788 | $incontext['db']['user'] = ini_get($db['default_user']); |
739 | 789 | $incontext['db']['name'] = ini_get($db['default_user']); |
740 | 790 | } |
741 | - if (isset($db['default_password'])) |
|
742 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
791 | + if (isset($db['default_password'])) { |
|
792 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
793 | + } |
|
743 | 794 | |
744 | 795 | // For simplicity and less confusion, leave the port blank by default |
745 | 796 | $incontext['db']['port'] = ''; |
@@ -758,10 +809,10 @@ discard block |
||
758 | 809 | $incontext['db']['server'] = $_POST['db_server']; |
759 | 810 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
760 | 811 | |
761 | - if (!empty($_POST['db_port'])) |
|
762 | - $incontext['db']['port'] = $_POST['db_port']; |
|
763 | - } |
|
764 | - else |
|
812 | + if (!empty($_POST['db_port'])) { |
|
813 | + $incontext['db']['port'] = $_POST['db_port']; |
|
814 | + } |
|
815 | + } else |
|
765 | 816 | { |
766 | 817 | $incontext['db']['prefix'] = 'smf_'; |
767 | 818 | } |
@@ -797,10 +848,11 @@ discard block |
||
797 | 848 | if (!empty($_POST['db_port'])) |
798 | 849 | { |
799 | 850 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
800 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
801 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
802 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
803 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
851 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
852 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
853 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
854 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
855 | + } |
|
804 | 856 | } |
805 | 857 | |
806 | 858 | // God I hope it saved! |
@@ -813,8 +865,9 @@ discard block |
||
813 | 865 | // Make sure it works. |
814 | 866 | require(dirname(__FILE__) . '/Settings.php'); |
815 | 867 | |
816 | - if (empty($sourcedir)) |
|
817 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
868 | + if (empty($sourcedir)) { |
|
869 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
870 | + } |
|
818 | 871 | |
819 | 872 | // Better find the database file! |
820 | 873 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -824,12 +877,14 @@ discard block |
||
824 | 877 | } |
825 | 878 | |
826 | 879 | // Now include it for database functions! |
827 | - if (!defined('SMF')) |
|
828 | - define('SMF', 1); |
|
880 | + if (!defined('SMF')) { |
|
881 | + define('SMF', 1); |
|
882 | + } |
|
829 | 883 | |
830 | 884 | $modSettings['disableQueryCheck'] = true; |
831 | - if (empty($smcFunc)) |
|
832 | - $smcFunc = array(); |
|
885 | + if (empty($smcFunc)) { |
|
886 | + $smcFunc = array(); |
|
887 | + } |
|
833 | 888 | |
834 | 889 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
835 | 890 | |
@@ -838,11 +893,13 @@ discard block |
||
838 | 893 | |
839 | 894 | $options = array('non_fatal' => true, 'dont_select_db' => !$needsDB); |
840 | 895 | // Add in the port if needed |
841 | - if (!empty($db_port)) |
|
842 | - $options['port'] = $db_port; |
|
896 | + if (!empty($db_port)) { |
|
897 | + $options['port'] = $db_port; |
|
898 | + } |
|
843 | 899 | |
844 | - if (!empty($db_mb4)) |
|
845 | - $options['db_mb4'] = $db_mb4; |
|
900 | + if (!empty($db_mb4)) { |
|
901 | + $options['db_mb4'] = $db_mb4; |
|
902 | + } |
|
846 | 903 | |
847 | 904 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
848 | 905 | |
@@ -928,12 +985,14 @@ discard block |
||
928 | 985 | $incontext['page_title'] = $txt['install_settings']; |
929 | 986 | |
930 | 987 | // Let's see if we got the database type correct. |
931 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
932 | - $db_type = $_POST['db_type']; |
|
988 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
989 | + $db_type = $_POST['db_type']; |
|
990 | + } |
|
933 | 991 | |
934 | 992 | // Else we'd better be able to get the connection. |
935 | - else |
|
936 | - load_database(); |
|
993 | + else { |
|
994 | + load_database(); |
|
995 | + } |
|
937 | 996 | |
938 | 997 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
939 | 998 | |
@@ -942,10 +1001,11 @@ discard block |
||
942 | 1001 | |
943 | 1002 | $secure = false; |
944 | 1003 | |
945 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
946 | - $secure = true; |
|
947 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
948 | - $secure = true; |
|
1004 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
1005 | + $secure = true; |
|
1006 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
1007 | + $secure = true; |
|
1008 | + } |
|
949 | 1009 | |
950 | 1010 | // Now, to put what we've learned together... and add a path. |
951 | 1011 | $incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); |
@@ -977,18 +1037,21 @@ discard block |
||
977 | 1037 | // Submitting? |
978 | 1038 | if (isset($_POST['boardurl'])) |
979 | 1039 | { |
980 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
981 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
982 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
983 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
984 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
985 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1040 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1041 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1042 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1043 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1044 | + } |
|
1045 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1046 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1047 | + } |
|
986 | 1048 | |
987 | 1049 | //Make sure boardurl is aligned with ssl setting |
988 | - if (empty($_POST['force_ssl'])) |
|
989 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
990 | - else |
|
991 | - $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1050 | + if (empty($_POST['force_ssl'])) { |
|
1051 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://')); |
|
1052 | + } else { |
|
1053 | + $_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://')); |
|
1054 | + } |
|
992 | 1055 | |
993 | 1056 | // Save these variables. |
994 | 1057 | $vars = array( |
@@ -1027,10 +1090,10 @@ discard block |
||
1027 | 1090 | { |
1028 | 1091 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
1029 | 1092 | return false; |
1030 | - } |
|
1031 | - else |
|
1032 | - // Set the character set here. |
|
1093 | + } else { |
|
1094 | + // Set the character set here. |
|
1033 | 1095 | updateSettingsFile(array('db_character_set' => 'utf8')); |
1096 | + } |
|
1034 | 1097 | } |
1035 | 1098 | |
1036 | 1099 | // Good, skip on. |
@@ -1050,8 +1113,9 @@ discard block |
||
1050 | 1113 | $incontext['continue'] = 1; |
1051 | 1114 | |
1052 | 1115 | // Already done? |
1053 | - if (isset($_POST['pop_done'])) |
|
1054 | - return true; |
|
1116 | + if (isset($_POST['pop_done'])) { |
|
1117 | + return true; |
|
1118 | + } |
|
1055 | 1119 | |
1056 | 1120 | // Reload settings. |
1057 | 1121 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1069,8 +1133,9 @@ discard block |
||
1069 | 1133 | $modSettings = array(); |
1070 | 1134 | if ($result !== false) |
1071 | 1135 | { |
1072 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1073 | - $modSettings[$row['variable']] = $row['value']; |
|
1136 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1137 | + $modSettings[$row['variable']] = $row['value']; |
|
1138 | + } |
|
1074 | 1139 | $smcFunc['db_free_result']($result); |
1075 | 1140 | |
1076 | 1141 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1083,20 +1148,22 @@ discard block |
||
1083 | 1148 | $modSettings['disableQueryCheck'] = true; |
1084 | 1149 | |
1085 | 1150 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
1086 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
1087 | - $smcFunc['db_query']('', ' |
|
1151 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
1152 | + $smcFunc['db_query']('', ' |
|
1088 | 1153 | SET NAMES {string:utf8}', |
1089 | 1154 | array( |
1090 | 1155 | 'db_error_skip' => true, |
1091 | 1156 | 'utf8' => 'utf8', |
1092 | 1157 | ) |
1093 | 1158 | ); |
1159 | + } |
|
1094 | 1160 | |
1095 | 1161 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
1096 | - if (substr(__DIR__, -1) == '\\') |
|
1097 | - $attachdir = __DIR__ . 'attachments'; |
|
1098 | - else |
|
1099 | - $attachdir = __DIR__ . '/attachments'; |
|
1162 | + if (substr(__DIR__, -1) == '\\') { |
|
1163 | + $attachdir = __DIR__ . 'attachments'; |
|
1164 | + } else { |
|
1165 | + $attachdir = __DIR__ . '/attachments'; |
|
1166 | + } |
|
1100 | 1167 | |
1101 | 1168 | $replaces = array( |
1102 | 1169 | '{$db_prefix}' => $db_prefix, |
@@ -1113,8 +1180,9 @@ discard block |
||
1113 | 1180 | |
1114 | 1181 | foreach ($txt as $key => $value) |
1115 | 1182 | { |
1116 | - if (substr($key, 0, 8) == 'default_') |
|
1117 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1183 | + if (substr($key, 0, 8) == 'default_') { |
|
1184 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1185 | + } |
|
1118 | 1186 | } |
1119 | 1187 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
1120 | 1188 | |
@@ -1129,8 +1197,9 @@ discard block |
||
1129 | 1197 | |
1130 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
1131 | 1199 | { |
1132 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
1133 | - $engines[] = $row['Engine']; |
|
1200 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
1201 | + $engines[] = $row['Engine']; |
|
1202 | + } |
|
1134 | 1203 | } |
1135 | 1204 | |
1136 | 1205 | // Done with this now |
@@ -1154,8 +1223,7 @@ discard block |
||
1154 | 1223 | $replaces['START TRANSACTION;'] = ''; |
1155 | 1224 | $replaces['COMMIT;'] = ''; |
1156 | 1225 | } |
1157 | - } |
|
1158 | - else |
|
1226 | + } else |
|
1159 | 1227 | { |
1160 | 1228 | $has_innodb = false; |
1161 | 1229 | } |
@@ -1177,21 +1245,24 @@ discard block |
||
1177 | 1245 | foreach ($sql_lines as $count => $line) |
1178 | 1246 | { |
1179 | 1247 | // No comments allowed! |
1180 | - if (substr(trim($line), 0, 1) != '#') |
|
1181 | - $current_statement .= "\n" . rtrim($line); |
|
1248 | + if (substr(trim($line), 0, 1) != '#') { |
|
1249 | + $current_statement .= "\n" . rtrim($line); |
|
1250 | + } |
|
1182 | 1251 | |
1183 | 1252 | // Is this the end of the query string? |
1184 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
1185 | - continue; |
|
1253 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
1254 | + continue; |
|
1255 | + } |
|
1186 | 1256 | |
1187 | 1257 | // Does this table already exist? If so, don't insert more data into it! |
1188 | 1258 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
1189 | 1259 | { |
1190 | 1260 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1191 | - if (!empty($matches[0])) |
|
1192 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1193 | - else |
|
1194 | - $incontext['sql_results']['insert_dups']++; |
|
1261 | + if (!empty($matches[0])) { |
|
1262 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1263 | + } else { |
|
1264 | + $incontext['sql_results']['insert_dups']++; |
|
1265 | + } |
|
1195 | 1266 | |
1196 | 1267 | $current_statement = ''; |
1197 | 1268 | continue; |
@@ -1212,18 +1283,18 @@ discard block |
||
1212 | 1283 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
1213 | 1284 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
1214 | 1285 | } |
1215 | - } |
|
1216 | - else |
|
1286 | + } else |
|
1217 | 1287 | { |
1218 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1219 | - $incontext['sql_results']['tables']++; |
|
1220 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1288 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
1289 | + $incontext['sql_results']['tables']++; |
|
1290 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1221 | 1291 | { |
1222 | 1292 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1223 | - if (!empty($matches[0])) |
|
1224 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1225 | - else |
|
1226 | - $incontext['sql_results']['inserts']++; |
|
1293 | + if (!empty($matches[0])) { |
|
1294 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1295 | + } else { |
|
1296 | + $incontext['sql_results']['inserts']++; |
|
1297 | + } |
|
1227 | 1298 | } |
1228 | 1299 | } |
1229 | 1300 | |
@@ -1236,15 +1307,17 @@ discard block |
||
1236 | 1307 | // Sort out the context for the SQL. |
1237 | 1308 | foreach ($incontext['sql_results'] as $key => $number) |
1238 | 1309 | { |
1239 | - if ($number == 0) |
|
1240 | - unset($incontext['sql_results'][$key]); |
|
1241 | - else |
|
1242 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1310 | + if ($number == 0) { |
|
1311 | + unset($incontext['sql_results'][$key]); |
|
1312 | + } else { |
|
1313 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1314 | + } |
|
1243 | 1315 | } |
1244 | 1316 | |
1245 | 1317 | // Make sure UTF will be used globally. |
1246 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
1247 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1318 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
1319 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1320 | + } |
|
1248 | 1321 | |
1249 | 1322 | // Auto-detect local & global cookie settings |
1250 | 1323 | $url_parts = parse_url($boardurl); |
@@ -1273,15 +1346,19 @@ discard block |
||
1273 | 1346 | |
1274 | 1347 | // Look for subfolder, if found, set localCookie |
1275 | 1348 | // Checking for len > 1 ensures you don't have just a slash... |
1276 | - if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) |
|
1277 | - $localCookies = '1'; |
|
1349 | + if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) { |
|
1350 | + $localCookies = '1'; |
|
1351 | + } |
|
1278 | 1352 | |
1279 | - if (isset($globalCookies)) |
|
1280 | - $newSettings[] = array('globalCookies', $globalCookies); |
|
1281 | - if (isset($globalCookiesDomain)) |
|
1282 | - $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1283 | - if (isset($localCookies)) |
|
1284 | - $newSettings[] = array('localCookies', $localCookies); |
|
1353 | + if (isset($globalCookies)) { |
|
1354 | + $newSettings[] = array('globalCookies', $globalCookies); |
|
1355 | + } |
|
1356 | + if (isset($globalCookiesDomain)) { |
|
1357 | + $newSettings[] = array('globalCookiesDomain', $globalCookiesDomain); |
|
1358 | + } |
|
1359 | + if (isset($localCookies)) { |
|
1360 | + $newSettings[] = array('localCookies', $localCookies); |
|
1361 | + } |
|
1285 | 1362 | } |
1286 | 1363 | |
1287 | 1364 | // Are we allowing stat collection? |
@@ -1299,16 +1376,17 @@ discard block |
||
1299 | 1376 | fwrite($fp, $out); |
1300 | 1377 | |
1301 | 1378 | $return_data = ''; |
1302 | - while (!feof($fp)) |
|
1303 | - $return_data .= fgets($fp, 128); |
|
1379 | + while (!feof($fp)) { |
|
1380 | + $return_data .= fgets($fp, 128); |
|
1381 | + } |
|
1304 | 1382 | |
1305 | 1383 | fclose($fp); |
1306 | 1384 | |
1307 | 1385 | // Get the unique site ID. |
1308 | 1386 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1309 | 1387 | |
1310 | - if (!empty($ID[1])) |
|
1311 | - $smcFunc['db_insert']('replace', |
|
1388 | + if (!empty($ID[1])) { |
|
1389 | + $smcFunc['db_insert']('replace', |
|
1312 | 1390 | $db_prefix . 'settings', |
1313 | 1391 | array('variable' => 'string', 'value' => 'string'), |
1314 | 1392 | array( |
@@ -1317,11 +1395,12 @@ discard block |
||
1317 | 1395 | ), |
1318 | 1396 | array('variable') |
1319 | 1397 | ); |
1398 | + } |
|
1320 | 1399 | } |
1321 | 1400 | } |
1322 | 1401 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
1323 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
1324 | - $smcFunc['db_query']('', ' |
|
1402 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
1403 | + $smcFunc['db_query']('', ' |
|
1325 | 1404 | DELETE FROM {db_prefix}settings |
1326 | 1405 | WHERE variable = {string:enable_sm_stats}', |
1327 | 1406 | array( |
@@ -1329,20 +1408,23 @@ discard block |
||
1329 | 1408 | 'db_error_skip' => true, |
1330 | 1409 | ) |
1331 | 1410 | ); |
1411 | + } |
|
1332 | 1412 | |
1333 | 1413 | // Are we enabling SSL? |
1334 | - if (!empty($_POST['force_ssl'])) |
|
1335 | - $newSettings[] = array('force_ssl', 1); |
|
1414 | + if (!empty($_POST['force_ssl'])) { |
|
1415 | + $newSettings[] = array('force_ssl', 1); |
|
1416 | + } |
|
1336 | 1417 | |
1337 | 1418 | // Setting a timezone is required. |
1338 | 1419 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
1339 | 1420 | { |
1340 | 1421 | // Get PHP's default timezone, if set |
1341 | 1422 | $ini_tz = ini_get('date.timezone'); |
1342 | - if (!empty($ini_tz)) |
|
1343 | - $timezone_id = $ini_tz; |
|
1344 | - else |
|
1345 | - $timezone_id = ''; |
|
1423 | + if (!empty($ini_tz)) { |
|
1424 | + $timezone_id = $ini_tz; |
|
1425 | + } else { |
|
1426 | + $timezone_id = ''; |
|
1427 | + } |
|
1346 | 1428 | |
1347 | 1429 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
1348 | 1430 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1351,8 +1433,9 @@ discard block |
||
1351 | 1433 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
1352 | 1434 | } |
1353 | 1435 | |
1354 | - if (date_default_timezone_set($timezone_id)) |
|
1355 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
1436 | + if (date_default_timezone_set($timezone_id)) { |
|
1437 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
1438 | + } |
|
1356 | 1439 | } |
1357 | 1440 | |
1358 | 1441 | if (!empty($newSettings)) |
@@ -1383,16 +1466,18 @@ discard block |
||
1383 | 1466 | } |
1384 | 1467 | |
1385 | 1468 | // MySQL specific stuff |
1386 | - if (substr($db_type, 0, 5) != 'mysql') |
|
1387 | - return false; |
|
1469 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
1470 | + return false; |
|
1471 | + } |
|
1388 | 1472 | |
1389 | 1473 | // Find database user privileges. |
1390 | 1474 | $privs = array(); |
1391 | 1475 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
1392 | 1476 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
1393 | 1477 | { |
1394 | - if ($row['Privilege'] == 'Alter') |
|
1395 | - $privs[] = $row['Privilege']; |
|
1478 | + if ($row['Privilege'] == 'Alter') { |
|
1479 | + $privs[] = $row['Privilege']; |
|
1480 | + } |
|
1396 | 1481 | } |
1397 | 1482 | $smcFunc['db_free_result']($get_privs); |
1398 | 1483 | |
@@ -1422,8 +1507,9 @@ discard block |
||
1422 | 1507 | $incontext['continue'] = 1; |
1423 | 1508 | |
1424 | 1509 | // Skipping? |
1425 | - if (!empty($_POST['skip'])) |
|
1426 | - return true; |
|
1510 | + if (!empty($_POST['skip'])) { |
|
1511 | + return true; |
|
1512 | + } |
|
1427 | 1513 | |
1428 | 1514 | // Need this to check whether we need the database password. |
1429 | 1515 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1440,18 +1526,22 @@ discard block |
||
1440 | 1526 | // We need this to properly hash the password for Admin |
1441 | 1527 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
1442 | 1528 | global $sourcedir; |
1443 | - if (function_exists('mb_strtolower')) |
|
1444 | - return mb_strtolower($string, 'UTF-8'); |
|
1529 | + if (function_exists('mb_strtolower')) { |
|
1530 | + return mb_strtolower($string, 'UTF-8'); |
|
1531 | + } |
|
1445 | 1532 | require_once($sourcedir . '/Subs-Charset.php'); |
1446 | 1533 | return utf8_strtolower($string); |
1447 | 1534 | }; |
1448 | 1535 | |
1449 | - if (!isset($_POST['username'])) |
|
1450 | - $_POST['username'] = ''; |
|
1451 | - if (!isset($_POST['email'])) |
|
1452 | - $_POST['email'] = ''; |
|
1453 | - if (!isset($_POST['server_email'])) |
|
1454 | - $_POST['server_email'] = ''; |
|
1536 | + if (!isset($_POST['username'])) { |
|
1537 | + $_POST['username'] = ''; |
|
1538 | + } |
|
1539 | + if (!isset($_POST['email'])) { |
|
1540 | + $_POST['email'] = ''; |
|
1541 | + } |
|
1542 | + if (!isset($_POST['server_email'])) { |
|
1543 | + $_POST['server_email'] = ''; |
|
1544 | + } |
|
1455 | 1545 | |
1456 | 1546 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
1457 | 1547 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1470,8 +1560,9 @@ discard block |
||
1470 | 1560 | 'admin_group' => 1, |
1471 | 1561 | ) |
1472 | 1562 | ); |
1473 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1474 | - $incontext['skip'] = 1; |
|
1563 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1564 | + $incontext['skip'] = 1; |
|
1565 | + } |
|
1475 | 1566 | $smcFunc['db_free_result']($request); |
1476 | 1567 | |
1477 | 1568 | // Trying to create an account? |
@@ -1502,8 +1593,9 @@ discard block |
||
1502 | 1593 | } |
1503 | 1594 | |
1504 | 1595 | // Update the webmaster's email? |
1505 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
1506 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1596 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
1597 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1598 | + } |
|
1507 | 1599 | |
1508 | 1600 | // Work out whether we're going to have dodgy characters and remove them. |
1509 | 1601 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1526,32 +1618,27 @@ discard block |
||
1526 | 1618 | $smcFunc['db_free_result']($result); |
1527 | 1619 | |
1528 | 1620 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
1529 | - } |
|
1530 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1621 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1531 | 1622 | { |
1532 | 1623 | // Try the previous step again. |
1533 | 1624 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
1534 | 1625 | return false; |
1535 | - } |
|
1536 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1626 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1537 | 1627 | { |
1538 | 1628 | // Try the previous step again. |
1539 | 1629 | $incontext['error'] = $txt['error_invalid_characters_username']; |
1540 | 1630 | return false; |
1541 | - } |
|
1542 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1631 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1543 | 1632 | { |
1544 | 1633 | // One step back, this time fill out a proper admin email address. |
1545 | 1634 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
1546 | 1635 | return false; |
1547 | - } |
|
1548 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1636 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1549 | 1637 | { |
1550 | 1638 | // One step back, this time fill out a proper admin email address. |
1551 | 1639 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
1552 | 1640 | return false; |
1553 | - } |
|
1554 | - elseif ($_POST['username'] != '') |
|
1641 | + } elseif ($_POST['username'] != '') |
|
1555 | 1642 | { |
1556 | 1643 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
1557 | 1644 | |
@@ -1619,17 +1706,19 @@ discard block |
||
1619 | 1706 | reloadSettings(); |
1620 | 1707 | |
1621 | 1708 | // Bring a warning over. |
1622 | - if (!empty($incontext['account_existed'])) |
|
1623 | - $incontext['warning'] = $incontext['account_existed']; |
|
1709 | + if (!empty($incontext['account_existed'])) { |
|
1710 | + $incontext['warning'] = $incontext['account_existed']; |
|
1711 | + } |
|
1624 | 1712 | |
1625 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
1626 | - $smcFunc['db_query']('', ' |
|
1713 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
1714 | + $smcFunc['db_query']('', ' |
|
1627 | 1715 | SET NAMES {string:db_character_set}', |
1628 | 1716 | array( |
1629 | 1717 | 'db_character_set' => $db_character_set, |
1630 | 1718 | 'db_error_skip' => true, |
1631 | 1719 | ) |
1632 | 1720 | ); |
1721 | + } |
|
1633 | 1722 | |
1634 | 1723 | // As track stats is by default enabled let's add some activity. |
1635 | 1724 | $smcFunc['db_insert']('ignore', |
@@ -1650,14 +1739,16 @@ discard block |
||
1650 | 1739 | // Only proceed if we can load the data. |
1651 | 1740 | if ($request) |
1652 | 1741 | { |
1653 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1654 | - $modSettings[$row[0]] = $row[1]; |
|
1742 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1743 | + $modSettings[$row[0]] = $row[1]; |
|
1744 | + } |
|
1655 | 1745 | $smcFunc['db_free_result']($request); |
1656 | 1746 | } |
1657 | 1747 | |
1658 | 1748 | // Automatically log them in ;) |
1659 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
1660 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1749 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
1750 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1751 | + } |
|
1661 | 1752 | |
1662 | 1753 | $result = $smcFunc['db_query']('', ' |
1663 | 1754 | SELECT value |
@@ -1668,13 +1759,14 @@ discard block |
||
1668 | 1759 | 'db_error_skip' => true, |
1669 | 1760 | ) |
1670 | 1761 | ); |
1671 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1672 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1762 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1763 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1764 | + } |
|
1673 | 1765 | $smcFunc['db_free_result']($result); |
1674 | 1766 | |
1675 | - if (empty($db_sessions)) |
|
1676 | - $_SESSION['admin_time'] = time(); |
|
1677 | - else |
|
1767 | + if (empty($db_sessions)) { |
|
1768 | + $_SESSION['admin_time'] = time(); |
|
1769 | + } else |
|
1678 | 1770 | { |
1679 | 1771 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
1680 | 1772 | |
@@ -1698,8 +1790,9 @@ discard block |
||
1698 | 1790 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
1699 | 1791 | function($string){ |
1700 | 1792 | global $sourcedir; |
1701 | - if (function_exists('mb_strtolower')) |
|
1702 | - return mb_strtolower($string, 'UTF-8'); |
|
1793 | + if (function_exists('mb_strtolower')) { |
|
1794 | + return mb_strtolower($string, 'UTF-8'); |
|
1795 | + } |
|
1703 | 1796 | require_once($sourcedir . '/Subs-Charset.php'); |
1704 | 1797 | return utf8_strtolower($string); |
1705 | 1798 | }; |
@@ -1715,8 +1808,9 @@ discard block |
||
1715 | 1808 | ) |
1716 | 1809 | ); |
1717 | 1810 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
1718 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1719 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1811 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1812 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1813 | + } |
|
1720 | 1814 | $smcFunc['db_free_result']($request); |
1721 | 1815 | |
1722 | 1816 | // Now is the perfect time to fetch the SM files. |
@@ -1735,8 +1829,9 @@ discard block |
||
1735 | 1829 | |
1736 | 1830 | // Check if we need some stupid MySQL fix. |
1737 | 1831 | $server_version = $smcFunc['db_server_info'](); |
1738 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1739 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1832 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1833 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1834 | + } |
|
1740 | 1835 | |
1741 | 1836 | // Some final context for the template. |
1742 | 1837 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1756,8 +1851,9 @@ discard block |
||
1756 | 1851 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
1757 | 1852 | |
1758 | 1853 | // @todo Do we just want to read the file in clean, and split it this way always? |
1759 | - if (count($settingsArray) == 1) |
|
1760 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1854 | + if (count($settingsArray) == 1) { |
|
1855 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1856 | + } |
|
1761 | 1857 | |
1762 | 1858 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
1763 | 1859 | { |
@@ -1765,25 +1861,29 @@ discard block |
||
1765 | 1861 | if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}') |
1766 | 1862 | { |
1767 | 1863 | // Set the ten lines to nothing. |
1768 | - for ($j=0; $j < 10; $j++) |
|
1769 | - $settingsArray[$i++] = ''; |
|
1864 | + for ($j=0; $j < 10; $j++) { |
|
1865 | + $settingsArray[$i++] = ''; |
|
1866 | + } |
|
1770 | 1867 | |
1771 | 1868 | continue; |
1772 | 1869 | } |
1773 | 1870 | |
1774 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
1775 | - $settingsArray[$i] = ''; |
|
1871 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
1872 | + $settingsArray[$i] = ''; |
|
1873 | + } |
|
1776 | 1874 | |
1777 | 1875 | // Don't trim or bother with it if it's not a variable. |
1778 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
1779 | - continue; |
|
1876 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
1877 | + continue; |
|
1878 | + } |
|
1780 | 1879 | |
1781 | 1880 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
1782 | 1881 | |
1783 | - foreach ($vars as $var => $val) |
|
1784 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1882 | + foreach ($vars as $var => $val) { |
|
1883 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1785 | 1884 | { |
1786 | 1885 | $comment = strstr($settingsArray[$i], '#'); |
1886 | + } |
|
1787 | 1887 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
1788 | 1888 | unset($vars[$var]); |
1789 | 1889 | } |
@@ -1793,36 +1893,41 @@ discard block |
||
1793 | 1893 | if (!empty($vars)) |
1794 | 1894 | { |
1795 | 1895 | $settingsArray[$i++] = ''; |
1796 | - foreach ($vars as $var => $val) |
|
1797 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1896 | + foreach ($vars as $var => $val) { |
|
1897 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1898 | + } |
|
1798 | 1899 | } |
1799 | 1900 | |
1800 | 1901 | // Blank out the file - done to fix a oddity with some servers. |
1801 | 1902 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
1802 | - if (!$fp) |
|
1803 | - return false; |
|
1903 | + if (!$fp) { |
|
1904 | + return false; |
|
1905 | + } |
|
1804 | 1906 | fclose($fp); |
1805 | 1907 | |
1806 | 1908 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
1807 | 1909 | |
1808 | 1910 | // Gotta have one of these ;) |
1809 | - if (trim($settingsArray[0]) != '<?php') |
|
1810 | - fwrite($fp, "<?php\n"); |
|
1911 | + if (trim($settingsArray[0]) != '<?php') { |
|
1912 | + fwrite($fp, "<?php\n"); |
|
1913 | + } |
|
1811 | 1914 | |
1812 | 1915 | $lines = count($settingsArray); |
1813 | 1916 | for ($i = 0; $i < $lines - 1; $i++) |
1814 | 1917 | { |
1815 | 1918 | // Don't just write a bunch of blank lines. |
1816 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
1817 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1919 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
1920 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1921 | + } |
|
1818 | 1922 | } |
1819 | 1923 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
1820 | 1924 | fclose($fp); |
1821 | 1925 | |
1822 | 1926 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
1823 | 1927 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
1824 | - if (function_exists('opcache_invalidate')) |
|
1825 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1928 | + if (function_exists('opcache_invalidate')) { |
|
1929 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1930 | + } |
|
1826 | 1931 | |
1827 | 1932 | return true; |
1828 | 1933 | } |
@@ -1832,10 +1937,11 @@ discard block |
||
1832 | 1937 | global $cachedir; |
1833 | 1938 | |
1834 | 1939 | // Write out the db_last_error file with the error timestamp |
1835 | - if (!empty($cachedir) && is_writable($cachedir)) |
|
1836 | - file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1837 | - else |
|
1838 | - file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1940 | + if (!empty($cachedir) && is_writable($cachedir)) { |
|
1941 | + file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1942 | + } else { |
|
1943 | + file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>'); |
|
1944 | + } |
|
1839 | 1945 | |
1840 | 1946 | return true; |
1841 | 1947 | } |
@@ -1852,9 +1958,9 @@ discard block |
||
1852 | 1958 | SecFilterScanPOST Off |
1853 | 1959 | </IfModule>'; |
1854 | 1960 | |
1855 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
1856 | - return true; |
|
1857 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1961 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
1962 | + return true; |
|
1963 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1858 | 1964 | { |
1859 | 1965 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
1860 | 1966 | |
@@ -1866,29 +1972,28 @@ discard block |
||
1866 | 1972 | fwrite($ht_handle, $htaccess_addition); |
1867 | 1973 | fclose($ht_handle); |
1868 | 1974 | return true; |
1975 | + } else { |
|
1976 | + return false; |
|
1869 | 1977 | } |
1870 | - else |
|
1871 | - return false; |
|
1978 | + } else { |
|
1979 | + return true; |
|
1872 | 1980 | } |
1873 | - else |
|
1874 | - return true; |
|
1875 | - } |
|
1876 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
1877 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1878 | - elseif (is_writable(dirname(__FILE__))) |
|
1981 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
1982 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1983 | + } elseif (is_writable(dirname(__FILE__))) |
|
1879 | 1984 | { |
1880 | 1985 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
1881 | 1986 | { |
1882 | 1987 | fwrite($ht_handle, $htaccess_addition); |
1883 | 1988 | fclose($ht_handle); |
1884 | 1989 | return true; |
1990 | + } else { |
|
1991 | + return false; |
|
1885 | 1992 | } |
1886 | - else |
|
1993 | + } else { |
|
1887 | 1994 | return false; |
1888 | 1995 | } |
1889 | - else |
|
1890 | - return false; |
|
1891 | -} |
|
1996 | + } |
|
1892 | 1997 | |
1893 | 1998 | function template_install_above() |
1894 | 1999 | { |
@@ -1927,9 +2032,10 @@ discard block |
||
1927 | 2032 | <label for="installer_language">', $txt['installer_language'], ':</label> |
1928 | 2033 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
1929 | 2034 | |
1930 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
1931 | - echo ' |
|
2035 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
2036 | + echo ' |
|
1932 | 2037 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
2038 | + } |
|
1933 | 2039 | |
1934 | 2040 | echo ' |
1935 | 2041 | </select> |
@@ -1949,9 +2055,10 @@ discard block |
||
1949 | 2055 | <h2>', $txt['upgrade_progress'], '</h2> |
1950 | 2056 | <ul>'; |
1951 | 2057 | |
1952 | - foreach ($incontext['steps'] as $num => $step) |
|
1953 | - echo ' |
|
2058 | + foreach ($incontext['steps'] as $num => $step) { |
|
2059 | + echo ' |
|
1954 | 2060 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
2061 | + } |
|
1955 | 2062 | |
1956 | 2063 | echo ' |
1957 | 2064 | </ul> |
@@ -1977,20 +2084,23 @@ discard block |
||
1977 | 2084 | echo ' |
1978 | 2085 | <div class="floatright">'; |
1979 | 2086 | |
1980 | - if (!empty($incontext['continue'])) |
|
1981 | - echo ' |
|
2087 | + if (!empty($incontext['continue'])) { |
|
2088 | + echo ' |
|
1982 | 2089 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">'; |
1983 | - if (!empty($incontext['skip'])) |
|
1984 | - echo ' |
|
2090 | + } |
|
2091 | + if (!empty($incontext['skip'])) { |
|
2092 | + echo ' |
|
1985 | 2093 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">'; |
2094 | + } |
|
1986 | 2095 | echo ' |
1987 | 2096 | </div>'; |
1988 | 2097 | } |
1989 | 2098 | |
1990 | 2099 | // Show the closing form tag and other data only if not in the last step |
1991 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
1992 | - echo ' |
|
2100 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
2101 | + echo ' |
|
1993 | 2102 | </form>'; |
2103 | + } |
|
1994 | 2104 | |
1995 | 2105 | echo ' |
1996 | 2106 | </div><!-- .panel --> |
@@ -2023,13 +2133,15 @@ discard block |
||
2023 | 2133 | </div>'; |
2024 | 2134 | |
2025 | 2135 | // Show the warnings, or not. |
2026 | - if (template_warning_divs()) |
|
2027 | - echo ' |
|
2136 | + if (template_warning_divs()) { |
|
2137 | + echo ' |
|
2028 | 2138 | <h3>', $txt['install_all_lovely'], '</h3>'; |
2139 | + } |
|
2029 | 2140 | |
2030 | 2141 | // Say we want the continue button! |
2031 | - if (empty($incontext['error'])) |
|
2032 | - $incontext['continue'] = 1; |
|
2142 | + if (empty($incontext['error'])) { |
|
2143 | + $incontext['continue'] = 1; |
|
2144 | + } |
|
2033 | 2145 | |
2034 | 2146 | // For the latest version stuff. |
2035 | 2147 | echo ' |
@@ -2063,19 +2175,21 @@ discard block |
||
2063 | 2175 | global $txt, $incontext; |
2064 | 2176 | |
2065 | 2177 | // Errors are very serious.. |
2066 | - if (!empty($incontext['error'])) |
|
2067 | - echo ' |
|
2178 | + if (!empty($incontext['error'])) { |
|
2179 | + echo ' |
|
2068 | 2180 | <div class="errorbox"> |
2069 | 2181 | <h3>', $txt['upgrade_critical_error'], '</h3> |
2070 | 2182 | ', $incontext['error'], ' |
2071 | 2183 | </div>'; |
2184 | + } |
|
2072 | 2185 | // A warning message? |
2073 | - elseif (!empty($incontext['warning'])) |
|
2074 | - echo ' |
|
2186 | + elseif (!empty($incontext['warning'])) { |
|
2187 | + echo ' |
|
2075 | 2188 | <div class="errorbox"> |
2076 | 2189 | <h3>', $txt['upgrade_warning'], '</h3> |
2077 | 2190 | ', $incontext['warning'], ' |
2078 | 2191 | </div>'; |
2192 | + } |
|
2079 | 2193 | |
2080 | 2194 | return empty($incontext['error']) && empty($incontext['warning']); |
2081 | 2195 | } |
@@ -2091,26 +2205,29 @@ discard block |
||
2091 | 2205 | <li>', $incontext['failed_files']), '</li> |
2092 | 2206 | </ul>'; |
2093 | 2207 | |
2094 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
2095 | - echo ' |
|
2208 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
2209 | + echo ' |
|
2096 | 2210 | <hr> |
2097 | 2211 | <p>', $txt['chmod_linux_info'], '</p> |
2098 | 2212 | <samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>'; |
2213 | + } |
|
2099 | 2214 | |
2100 | 2215 | // This is serious! |
2101 | - if (!template_warning_divs()) |
|
2102 | - return; |
|
2216 | + if (!template_warning_divs()) { |
|
2217 | + return; |
|
2218 | + } |
|
2103 | 2219 | |
2104 | 2220 | echo ' |
2105 | 2221 | <hr> |
2106 | 2222 | <p>', $txt['ftp_setup_info'], '</p>'; |
2107 | 2223 | |
2108 | - if (!empty($incontext['ftp_errors'])) |
|
2109 | - echo ' |
|
2224 | + if (!empty($incontext['ftp_errors'])) { |
|
2225 | + echo ' |
|
2110 | 2226 | <div class="error_message"> |
2111 | 2227 | ', $txt['error_ftp_no_connect'], '<br><br> |
2112 | 2228 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
2113 | 2229 | </div>'; |
2230 | + } |
|
2114 | 2231 | |
2115 | 2232 | echo ' |
2116 | 2233 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2179,16 +2296,16 @@ discard block |
||
2179 | 2296 | <dd> |
2180 | 2297 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
2181 | 2298 | |
2182 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
2183 | - echo ' |
|
2299 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
2300 | + echo ' |
|
2184 | 2301 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
2302 | + } |
|
2185 | 2303 | |
2186 | 2304 | echo ' |
2187 | 2305 | </select> |
2188 | 2306 | <div class="smalltext">', $txt['db_settings_type_info'], '</div> |
2189 | 2307 | </dd>'; |
2190 | - } |
|
2191 | - else |
|
2308 | + } else |
|
2192 | 2309 | { |
2193 | 2310 | echo ' |
2194 | 2311 | <dd> |
@@ -2356,9 +2473,10 @@ discard block |
||
2356 | 2473 | <div class="red">', $txt['error_db_queries'], '</div> |
2357 | 2474 | <ul>'; |
2358 | 2475 | |
2359 | - foreach ($incontext['failures'] as $line => $fail) |
|
2360 | - echo ' |
|
2476 | + foreach ($incontext['failures'] as $line => $fail) { |
|
2477 | + echo ' |
|
2361 | 2478 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
2479 | + } |
|
2362 | 2480 | |
2363 | 2481 | echo ' |
2364 | 2482 | </ul>'; |
@@ -2423,15 +2541,16 @@ discard block |
||
2423 | 2541 | </dd> |
2424 | 2542 | </dl>'; |
2425 | 2543 | |
2426 | - if ($incontext['require_db_confirm']) |
|
2427 | - echo ' |
|
2544 | + if ($incontext['require_db_confirm']) { |
|
2545 | + echo ' |
|
2428 | 2546 | <h2>', $txt['user_settings_database'], '</h2> |
2429 | 2547 | <p>', $txt['user_settings_database_info'], '</p> |
2430 | 2548 | |
2431 | 2549 | <div class="lefttext"> |
2432 | 2550 | <input type="password" name="password3" size="30"> |
2433 | 2551 | </div>'; |
2434 | -} |
|
2552 | + } |
|
2553 | + } |
|
2435 | 2554 | |
2436 | 2555 | // Tell them it's done, and to delete. |
2437 | 2556 | function template_delete_install() |
@@ -2444,13 +2563,14 @@ discard block |
||
2444 | 2563 | template_warning_divs(); |
2445 | 2564 | |
2446 | 2565 | // Install directory still writable? |
2447 | - if ($incontext['dir_still_writable']) |
|
2448 | - echo ' |
|
2566 | + if ($incontext['dir_still_writable']) { |
|
2567 | + echo ' |
|
2449 | 2568 | <p><em>', $txt['still_writable'], '</em></p>'; |
2569 | + } |
|
2450 | 2570 | |
2451 | 2571 | // Don't show the box if it's like 99% sure it won't work :P. |
2452 | - if ($incontext['probably_delete_install']) |
|
2453 | - echo ' |
|
2572 | + if ($incontext['probably_delete_install']) { |
|
2573 | + echo ' |
|
2454 | 2574 | <label> |
2455 | 2575 | <input type="checkbox" id="delete_self" onclick="doTheDelete();"> |
2456 | 2576 | <strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong> |
@@ -2466,6 +2586,7 @@ discard block |
||
2466 | 2586 | theCheck.disabled = true; |
2467 | 2587 | } |
2468 | 2588 | </script>'; |
2589 | + } |
|
2469 | 2590 | |
2470 | 2591 | echo ' |
2471 | 2592 | <p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p> |
@@ -191,12 +191,15 @@ discard block |
||
191 | 191 | $tasksdir = $sourcedir . '/tasks'; |
192 | 192 | |
193 | 193 | # Make sure the paths are correct... at least try to fix them. |
194 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
194 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
195 | 195 | $boarddir = dirname(__FILE__); |
196 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
196 | +} |
|
197 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
197 | 198 | $sourcedir = $boarddir . '/Sources'; |
198 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
199 | +} |
|
200 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
199 | 201 | $cachedir = $boarddir . '/cache'; |
202 | +} |
|
200 | 203 | |
201 | 204 | ######### Legacy Settings ######### |
202 | 205 | # UTF-8 is now the only character set supported in 2.1. |
@@ -204,8 +207,9 @@ discard block |
||
204 | 207 | |
205 | 208 | ########## Error-Catching ########## |
206 | 209 | # Note: You shouldn't touch these settings. |
207 | -if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) |
|
210 | +if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) { |
|
208 | 211 | include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'); |
212 | +} |
|
209 | 213 | |
210 | 214 | if (!isset($db_last_error)) |
211 | 215 | { |
@@ -217,10 +221,11 @@ discard block |
||
217 | 221 | if (file_exists(dirname(__FILE__) . '/install.php')) |
218 | 222 | { |
219 | 223 | $secure = false; |
220 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
221 | - $secure = true; |
|
222 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
223 | - $secure = true; |
|
224 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
225 | + $secure = true; |
|
226 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
227 | + $secure = true; |
|
228 | + } |
|
224 | 229 | |
225 | 230 | header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
226 | 231 | } |
@@ -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) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -66,15 +67,18 @@ discard block |
||
66 | 67 | 'db_native_replace' => 'smf_db_native_replace', |
67 | 68 | 'db_cte_support' => 'smf_db_cte_support', |
68 | 69 | ); |
70 | + } |
|
69 | 71 | |
70 | 72 | // We are not going to make it very far without these. |
71 | - if (!function_exists('pg_pconnect')) |
|
72 | - display_db_error(); |
|
73 | + if (!function_exists('pg_pconnect')) { |
|
74 | + display_db_error(); |
|
75 | + } |
|
73 | 76 | |
74 | - if (!empty($db_options['persist'])) |
|
75 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
76 | - else |
|
77 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
77 | + if (!empty($db_options['persist'])) { |
|
78 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
79 | + } else { |
|
80 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
81 | + } |
|
78 | 82 | |
79 | 83 | // Something's wrong, show an error if its fatal (which we assume it is) |
80 | 84 | if (!$connection) |
@@ -82,15 +86,15 @@ discard block |
||
82 | 86 | if (!empty($db_options['non_fatal'])) |
83 | 87 | { |
84 | 88 | return null; |
85 | - } |
|
86 | - else |
|
89 | + } else |
|
87 | 90 | { |
88 | 91 | display_db_error(); |
89 | 92 | } |
90 | 93 | } |
91 | 94 | |
92 | - if (!empty($db_options['db_mb4'])) |
|
93 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
95 | + if (!empty($db_options['db_mb4'])) { |
|
96 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
97 | + } |
|
94 | 98 | |
95 | 99 | return $connection; |
96 | 100 | } |
@@ -137,31 +141,38 @@ discard block |
||
137 | 141 | |
138 | 142 | list ($values, $connection) = $db_callback; |
139 | 143 | |
140 | - if ($matches[1] === 'db_prefix') |
|
141 | - return $db_prefix; |
|
144 | + if ($matches[1] === 'db_prefix') { |
|
145 | + return $db_prefix; |
|
146 | + } |
|
142 | 147 | |
143 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
144 | - return $user_info[$matches[1]]; |
|
148 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
149 | + return $user_info[$matches[1]]; |
|
150 | + } |
|
145 | 151 | |
146 | - if ($matches[1] === 'empty') |
|
147 | - return '\'\''; |
|
152 | + if ($matches[1] === 'empty') { |
|
153 | + return '\'\''; |
|
154 | + } |
|
148 | 155 | |
149 | - if (!isset($matches[2])) |
|
150 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
156 | + if (!isset($matches[2])) { |
|
157 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
158 | + } |
|
151 | 159 | |
152 | - if ($matches[1] === 'literal') |
|
153 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
160 | + if ($matches[1] === 'literal') { |
|
161 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
162 | + } |
|
154 | 163 | |
155 | - if (!isset($values[$matches[2]])) |
|
156 | - 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__); |
|
164 | + if (!isset($values[$matches[2]])) { |
|
165 | + 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__); |
|
166 | + } |
|
157 | 167 | |
158 | 168 | $replacement = $values[$matches[2]]; |
159 | 169 | |
160 | 170 | switch ($matches[1]) |
161 | 171 | { |
162 | 172 | case 'int': |
163 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
164 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
173 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
174 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
175 | + } |
|
165 | 176 | return (string) (int) $replacement; |
166 | 177 | break; |
167 | 178 | |
@@ -173,65 +184,73 @@ discard block |
||
173 | 184 | case 'array_int': |
174 | 185 | if (is_array($replacement)) |
175 | 186 | { |
176 | - if (empty($replacement)) |
|
177 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
187 | + if (empty($replacement)) { |
|
188 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
189 | + } |
|
178 | 190 | |
179 | 191 | foreach ($replacement as $key => $value) |
180 | 192 | { |
181 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
182 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
194 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | + } |
|
183 | 196 | |
184 | 197 | $replacement[$key] = (string) (int) $value; |
185 | 198 | } |
186 | 199 | |
187 | 200 | return implode(', ', $replacement); |
201 | + } else { |
|
202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
188 | 203 | } |
189 | - else |
|
190 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
191 | 204 | |
192 | 205 | break; |
193 | 206 | |
194 | 207 | case 'array_string': |
195 | 208 | if (is_array($replacement)) |
196 | 209 | { |
197 | - if (empty($replacement)) |
|
198 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
210 | + if (empty($replacement)) { |
|
211 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
212 | + } |
|
199 | 213 | |
200 | - foreach ($replacement as $key => $value) |
|
201 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
214 | + foreach ($replacement as $key => $value) { |
|
215 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
216 | + } |
|
202 | 217 | |
203 | 218 | return implode(', ', $replacement); |
219 | + } else { |
|
220 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
204 | 221 | } |
205 | - else |
|
206 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
207 | 222 | break; |
208 | 223 | |
209 | 224 | case 'date': |
210 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
211 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
212 | - else |
|
213 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
226 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
227 | + } else { |
|
228 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + } |
|
214 | 230 | break; |
215 | 231 | |
216 | 232 | case 'time': |
217 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
218 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
233 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
234 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
235 | + } else { |
|
236 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | + } |
|
221 | 238 | break; |
222 | 239 | |
223 | 240 | case 'datetime': |
224 | - 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) |
|
225 | - return 'to_timestamp('. |
|
241 | + 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) { |
|
242 | + return 'to_timestamp('. |
|
226 | 243 | 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]). |
227 | 244 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
228 | - else |
|
229 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
245 | + } else { |
|
246 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | + } |
|
230 | 248 | break; |
231 | 249 | |
232 | 250 | case 'float': |
233 | - if (!is_numeric($replacement)) |
|
234 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
251 | + if (!is_numeric($replacement)) { |
|
252 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
253 | + } |
|
235 | 254 | return (string) (float) $replacement; |
236 | 255 | break; |
237 | 256 | |
@@ -244,31 +263,36 @@ discard block |
||
244 | 263 | break; |
245 | 264 | |
246 | 265 | case 'inet': |
247 | - if ($replacement == 'null' || $replacement == '') |
|
248 | - return 'null'; |
|
249 | - if (inet_pton($replacement) === false) |
|
250 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if ($replacement == 'null' || $replacement == '') { |
|
267 | + return 'null'; |
|
268 | + } |
|
269 | + if (inet_pton($replacement) === false) { |
|
270 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
271 | + } |
|
251 | 272 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
252 | 273 | |
253 | 274 | case 'array_inet': |
254 | 275 | if (is_array($replacement)) |
255 | 276 | { |
256 | - if (empty($replacement)) |
|
257 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + if (empty($replacement)) { |
|
278 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
279 | + } |
|
258 | 280 | |
259 | 281 | foreach ($replacement as $key => $value) |
260 | 282 | { |
261 | - if ($replacement == 'null' || $replacement == '') |
|
262 | - $replacement[$key] = 'null'; |
|
263 | - if (!isValidIP($value)) |
|
264 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + if ($replacement == 'null' || $replacement == '') { |
|
284 | + $replacement[$key] = 'null'; |
|
285 | + } |
|
286 | + if (!isValidIP($value)) { |
|
287 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
288 | + } |
|
265 | 289 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
266 | 290 | } |
267 | 291 | |
268 | 292 | return implode(', ', $replacement); |
293 | + } else { |
|
294 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | 295 | } |
270 | - else |
|
271 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | 296 | break; |
273 | 297 | |
274 | 298 | default: |
@@ -356,14 +380,16 @@ discard block |
||
356 | 380 | ), |
357 | 381 | ); |
358 | 382 | |
359 | - if (isset($replacements[$identifier])) |
|
360 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
383 | + if (isset($replacements[$identifier])) { |
|
384 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
385 | + } |
|
361 | 386 | |
362 | 387 | // Limits need to be a little different. |
363 | 388 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
364 | 389 | |
365 | - if (trim($db_string) == '') |
|
366 | - return false; |
|
390 | + if (trim($db_string) == '') { |
|
391 | + return false; |
|
392 | + } |
|
367 | 393 | |
368 | 394 | // Comments that are allowed in a query are preg_removed. |
369 | 395 | static $allowed_comments_from = array( |
@@ -383,8 +409,9 @@ discard block |
||
383 | 409 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
384 | 410 | $db_replace_result = 0; |
385 | 411 | |
386 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
387 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
412 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
413 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
414 | + } |
|
388 | 415 | |
389 | 416 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
390 | 417 | { |
@@ -409,17 +436,18 @@ discard block |
||
409 | 436 | while (true) |
410 | 437 | { |
411 | 438 | $pos = strpos($db_string_1, '\'', $pos + 1); |
412 | - if ($pos === false) |
|
413 | - break; |
|
439 | + if ($pos === false) { |
|
440 | + break; |
|
441 | + } |
|
414 | 442 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
415 | 443 | |
416 | 444 | while (true) |
417 | 445 | { |
418 | 446 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
419 | 447 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
420 | - if ($pos1 === false) |
|
421 | - break; |
|
422 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
448 | + if ($pos1 === false) { |
|
449 | + break; |
|
450 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
423 | 451 | { |
424 | 452 | $pos = $pos1; |
425 | 453 | break; |
@@ -435,16 +463,19 @@ discard block |
||
435 | 463 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
436 | 464 | |
437 | 465 | // Comments? We don't use comments in our queries, we leave 'em outside! |
438 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
439 | - $fail = true; |
|
466 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
467 | + $fail = true; |
|
468 | + } |
|
440 | 469 | // Trying to change passwords, slow us down, or something? |
441 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
442 | - $fail = true; |
|
443 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
444 | - $fail = true; |
|
470 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
471 | + $fail = true; |
|
472 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
473 | + $fail = true; |
|
474 | + } |
|
445 | 475 | |
446 | - if (!empty($fail) && function_exists('log_error')) |
|
447 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
476 | + if (!empty($fail) && function_exists('log_error')) { |
|
477 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
478 | + } |
|
448 | 479 | } |
449 | 480 | |
450 | 481 | // Set optimize stuff |
@@ -471,8 +502,9 @@ discard block |
||
471 | 502 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
472 | 503 | |
473 | 504 | // Initialize $db_cache if not already initialized. |
474 | - if (!isset($db_cache)) |
|
475 | - $db_cache = array(); |
|
505 | + if (!isset($db_cache)) { |
|
506 | + $db_cache = array(); |
|
507 | + } |
|
476 | 508 | |
477 | 509 | if (!empty($_SESSION['debug_redirect'])) |
478 | 510 | { |
@@ -490,12 +522,14 @@ discard block |
||
490 | 522 | |
491 | 523 | $db_last_result = @pg_query($connection, $db_string); |
492 | 524 | |
493 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
494 | - $db_last_result = smf_db_error($db_string, $connection); |
|
525 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
526 | + $db_last_result = smf_db_error($db_string, $connection); |
|
527 | + } |
|
495 | 528 | |
496 | 529 | // Debugging. |
497 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
498 | - $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = microtime(true) - $st; |
|
532 | + } |
|
499 | 533 | |
500 | 534 | return $db_last_result; |
501 | 535 | } |
@@ -512,10 +546,11 @@ discard block |
||
512 | 546 | { |
513 | 547 | global $db_last_result, $db_replace_result; |
514 | 548 | |
515 | - if ($db_replace_result) |
|
516 | - return $db_replace_result; |
|
517 | - elseif ($result === null && !$db_last_result) |
|
518 | - return 0; |
|
549 | + if ($db_replace_result) { |
|
550 | + return $db_replace_result; |
|
551 | + } elseif ($result === null && !$db_last_result) { |
|
552 | + return 0; |
|
553 | + } |
|
519 | 554 | |
520 | 555 | return pg_affected_rows($result === null ? $db_last_result : $result); |
521 | 556 | } |
@@ -539,8 +574,9 @@ discard block |
||
539 | 574 | array( |
540 | 575 | ) |
541 | 576 | ); |
542 | - if (!$request) |
|
543 | - return false; |
|
577 | + if (!$request) { |
|
578 | + return false; |
|
579 | + } |
|
544 | 580 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
545 | 581 | $smcFunc['db_free_result']($request); |
546 | 582 | |
@@ -561,12 +597,13 @@ discard block |
||
561 | 597 | // Decide which connection to use |
562 | 598 | $connection = $connection === null ? $db_connection : $connection; |
563 | 599 | |
564 | - if ($type == 'begin') |
|
565 | - return @pg_query($connection, 'BEGIN'); |
|
566 | - elseif ($type == 'rollback') |
|
567 | - return @pg_query($connection, 'ROLLBACK'); |
|
568 | - elseif ($type == 'commit') |
|
569 | - return @pg_query($connection, 'COMMIT'); |
|
600 | + if ($type == 'begin') { |
|
601 | + return @pg_query($connection, 'BEGIN'); |
|
602 | + } elseif ($type == 'rollback') { |
|
603 | + return @pg_query($connection, 'ROLLBACK'); |
|
604 | + } elseif ($type == 'commit') { |
|
605 | + return @pg_query($connection, 'COMMIT'); |
|
606 | + } |
|
570 | 607 | |
571 | 608 | return false; |
572 | 609 | } |
@@ -594,19 +631,22 @@ discard block |
||
594 | 631 | $query_error = @pg_last_error($connection); |
595 | 632 | |
596 | 633 | // Log the error. |
597 | - if (function_exists('log_error')) |
|
598 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
634 | + if (function_exists('log_error')) { |
|
635 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
636 | + } |
|
599 | 637 | |
600 | 638 | // Nothing's defined yet... just die with it. |
601 | - if (empty($context) || empty($txt)) |
|
602 | - die($query_error); |
|
639 | + if (empty($context) || empty($txt)) { |
|
640 | + die($query_error); |
|
641 | + } |
|
603 | 642 | |
604 | 643 | // Show an error message, if possible. |
605 | 644 | $context['error_title'] = $txt['database_error']; |
606 | - if (allowedTo('admin_forum')) |
|
607 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
608 | - else |
|
609 | - $context['error_message'] = $txt['try_again']; |
|
645 | + if (allowedTo('admin_forum')) { |
|
646 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
647 | + } else { |
|
648 | + $context['error_message'] = $txt['try_again']; |
|
649 | + } |
|
610 | 650 | |
611 | 651 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
612 | 652 | { |
@@ -628,12 +668,14 @@ discard block |
||
628 | 668 | { |
629 | 669 | global $db_row_count; |
630 | 670 | |
631 | - if ($counter !== false) |
|
632 | - return pg_fetch_row($request, $counter); |
|
671 | + if ($counter !== false) { |
|
672 | + return pg_fetch_row($request, $counter); |
|
673 | + } |
|
633 | 674 | |
634 | 675 | // Reset the row counter... |
635 | - if (!isset($db_row_count[(int) $request])) |
|
636 | - $db_row_count[(int) $request] = 0; |
|
676 | + if (!isset($db_row_count[(int) $request])) { |
|
677 | + $db_row_count[(int) $request] = 0; |
|
678 | + } |
|
637 | 679 | |
638 | 680 | // Return the right row. |
639 | 681 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -650,12 +692,14 @@ discard block |
||
650 | 692 | { |
651 | 693 | global $db_row_count; |
652 | 694 | |
653 | - if ($counter !== false) |
|
654 | - return pg_fetch_assoc($request, $counter); |
|
695 | + if ($counter !== false) { |
|
696 | + return pg_fetch_assoc($request, $counter); |
|
697 | + } |
|
655 | 698 | |
656 | 699 | // Reset the row counter... |
657 | - if (!isset($db_row_count[(int) $request])) |
|
658 | - $db_row_count[(int) $request] = 0; |
|
700 | + if (!isset($db_row_count[(int) $request])) { |
|
701 | + $db_row_count[(int) $request] = 0; |
|
702 | + } |
|
659 | 703 | |
660 | 704 | // Return the right row. |
661 | 705 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -697,19 +741,22 @@ discard block |
||
697 | 741 | |
698 | 742 | $replace = ''; |
699 | 743 | |
700 | - if (empty($data)) |
|
701 | - return; |
|
744 | + if (empty($data)) { |
|
745 | + return; |
|
746 | + } |
|
702 | 747 | |
703 | - if (!is_array($data[array_rand($data)])) |
|
704 | - $data = array($data); |
|
748 | + if (!is_array($data[array_rand($data)])) { |
|
749 | + $data = array($data); |
|
750 | + } |
|
705 | 751 | |
706 | 752 | // Replace the prefix holder with the actual prefix. |
707 | 753 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
708 | 754 | |
709 | 755 | // Sanity check for replace is key part of the columns array |
710 | - if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) |
|
711 | - smf_db_error_backtrace('Primary Key field missing in insert call', |
|
756 | + if ($method == 'replace' && count(array_intersect_key($columns, array_flip($keys))) !== count($keys)) { |
|
757 | + smf_db_error_backtrace('Primary Key field missing in insert call', |
|
712 | 758 | 'Change the method of db insert to insert or add the pk field to the columns array', E_USER_ERROR, __FILE__, __LINE__); |
759 | + } |
|
713 | 760 | |
714 | 761 | // PostgreSQL doesn't support replace: we implement a MySQL-compatible behavior instead |
715 | 762 | if ($method == 'replace' || $method == 'ignore') |
@@ -732,32 +779,35 @@ discard block |
||
732 | 779 | $key_str .= ($count_pk > 0 ? ',' : ''); |
733 | 780 | $key_str .= $columnName; |
734 | 781 | $count_pk++; |
735 | - } |
|
736 | - else if ($method == 'replace') //normal field |
|
782 | + } else if ($method == 'replace') { |
|
783 | + //normal field |
|
737 | 784 | { |
738 | 785 | $col_str .= ($count > 0 ? ',' : ''); |
786 | + } |
|
739 | 787 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
740 | 788 | $count++; |
741 | 789 | } |
742 | 790 | } |
743 | - if ($method == 'replace') |
|
744 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
745 | - else |
|
746 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
747 | - } |
|
748 | - else if ($method == 'replace') |
|
791 | + if ($method == 'replace') { |
|
792 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
793 | + } else { |
|
794 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
795 | + } |
|
796 | + } else if ($method == 'replace') |
|
749 | 797 | { |
750 | 798 | foreach ($columns as $columnName => $type) |
751 | 799 | { |
752 | 800 | // Are we restricting the length? |
753 | - if (strpos($type, 'string-') !== false) |
|
754 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
755 | - else |
|
756 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
801 | + if (strpos($type, 'string-') !== false) { |
|
802 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
803 | + } else { |
|
804 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
805 | + } |
|
757 | 806 | |
758 | 807 | // A key? That's what we were looking for. |
759 | - if (in_array($columnName, $keys)) |
|
760 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
808 | + if (in_array($columnName, $keys)) { |
|
809 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
810 | + } |
|
761 | 811 | $count++; |
762 | 812 | } |
763 | 813 | |
@@ -793,10 +843,11 @@ discard block |
||
793 | 843 | foreach ($columns as $columnName => $type) |
794 | 844 | { |
795 | 845 | // Are we restricting the length? |
796 | - if (strpos($type, 'string-') !== false) |
|
797 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
798 | - else |
|
799 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
846 | + if (strpos($type, 'string-') !== false) { |
|
847 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
848 | + } else { |
|
849 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
850 | + } |
|
800 | 851 | } |
801 | 852 | $insertData = substr($insertData, 0, -2) . ')'; |
802 | 853 | |
@@ -805,8 +856,9 @@ discard block |
||
805 | 856 | |
806 | 857 | // Here's where the variables are injected to the query. |
807 | 858 | $insertRows = array(); |
808 | - foreach ($data as $dataRow) |
|
809 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
859 | + foreach ($data as $dataRow) { |
|
860 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
861 | + } |
|
810 | 862 | |
811 | 863 | // Do the insert. |
812 | 864 | $request = $smcFunc['db_query']('', ' |
@@ -823,19 +875,21 @@ discard block |
||
823 | 875 | |
824 | 876 | if ($with_returning && $request !== false) |
825 | 877 | { |
826 | - if ($returnmode === 2) |
|
827 | - $return_var = array(); |
|
878 | + if ($returnmode === 2) { |
|
879 | + $return_var = array(); |
|
880 | + } |
|
828 | 881 | |
829 | 882 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
830 | 883 | { |
831 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
884 | + if (is_numeric($row[0])) { |
|
885 | + // try to emulate mysql limitation |
|
832 | 886 | { |
833 | 887 | if ($returnmode === 1) |
834 | 888 | $return_var = $row[0]; |
835 | - elseif ($returnmode === 2) |
|
836 | - $return_var[] = $row[0]; |
|
837 | - } |
|
838 | - else |
|
889 | + } elseif ($returnmode === 2) { |
|
890 | + $return_var[] = $row[0]; |
|
891 | + } |
|
892 | + } else |
|
839 | 893 | { |
840 | 894 | $with_returning = false; |
841 | 895 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -844,9 +898,10 @@ discard block |
||
844 | 898 | } |
845 | 899 | } |
846 | 900 | |
847 | - if ($with_returning && !empty($return_var)) |
|
848 | - return $return_var; |
|
849 | -} |
|
901 | + if ($with_returning && !empty($return_var)) { |
|
902 | + return $return_var; |
|
903 | + } |
|
904 | + } |
|
850 | 905 | |
851 | 906 | /** |
852 | 907 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -883,8 +938,9 @@ discard block |
||
883 | 938 | */ |
884 | 939 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
885 | 940 | { |
886 | - if (empty($log_message)) |
|
887 | - $log_message = $error_message; |
|
941 | + if (empty($log_message)) { |
|
942 | + $log_message = $error_message; |
|
943 | + } |
|
888 | 944 | |
889 | 945 | foreach (debug_backtrace() as $step) |
890 | 946 | { |
@@ -903,12 +959,14 @@ discard block |
||
903 | 959 | } |
904 | 960 | |
905 | 961 | // A special case - we want the file and line numbers for debugging. |
906 | - if ($error_type == 'return') |
|
907 | - return array($file, $line); |
|
962 | + if ($error_type == 'return') { |
|
963 | + return array($file, $line); |
|
964 | + } |
|
908 | 965 | |
909 | 966 | // Is always a critical error. |
910 | - if (function_exists('log_error')) |
|
911 | - log_error($log_message, 'critical', $file, $line); |
|
967 | + if (function_exists('log_error')) { |
|
968 | + log_error($log_message, 'critical', $file, $line); |
|
969 | + } |
|
912 | 970 | |
913 | 971 | if (function_exists('fatal_error')) |
914 | 972 | { |
@@ -916,12 +974,12 @@ discard block |
||
916 | 974 | |
917 | 975 | // Cannot continue... |
918 | 976 | exit; |
977 | + } elseif ($error_type) { |
|
978 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
979 | + } else { |
|
980 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
981 | + } |
|
919 | 982 | } |
920 | - elseif ($error_type) |
|
921 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
922 | - else |
|
923 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
924 | -} |
|
925 | 983 | |
926 | 984 | /** |
927 | 985 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -938,10 +996,11 @@ discard block |
||
938 | 996 | '\\' => '\\\\', |
939 | 997 | ); |
940 | 998 | |
941 | - if ($translate_human_wildcards) |
|
942 | - $replacements += array( |
|
999 | + if ($translate_human_wildcards) { |
|
1000 | + $replacements += array( |
|
943 | 1001 | '*' => '%', |
944 | 1002 | ); |
1003 | + } |
|
945 | 1004 | |
946 | 1005 | return strtr($string, $replacements); |
947 | 1006 | } |
@@ -970,14 +1029,16 @@ discard block |
||
970 | 1029 | static $pg_error_data_prep; |
971 | 1030 | |
972 | 1031 | // without database we can't do anything |
973 | - if (empty($db_connection)) |
|
974 | - return; |
|
1032 | + if (empty($db_connection)) { |
|
1033 | + return; |
|
1034 | + } |
|
975 | 1035 | |
976 | - if (empty($pg_error_data_prep)) |
|
977 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1036 | + if (empty($pg_error_data_prep)) { |
|
1037 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
978 | 1038 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
979 | 1039 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)' |
980 | 1040 | ); |
1041 | + } |
|
981 | 1042 | |
982 | 1043 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
983 | 1044 | } |
@@ -997,8 +1058,9 @@ discard block |
||
997 | 1058 | $count = count($array_values); |
998 | 1059 | $then = ($desc ? ' THEN -' : ' THEN '); |
999 | 1060 | |
1000 | - for ($i = 0; $i < $count; $i++) |
|
1001 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1061 | + for ($i = 0; $i < $count; $i++) { |
|
1062 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1063 | + } |
|
1002 | 1064 | |
1003 | 1065 | $return .= 'END'; |
1004 | 1066 | return $return; |
@@ -1021,11 +1083,13 @@ discard block |
||
1021 | 1083 | //pg 9.5 got replace support |
1022 | 1084 | $pg_version = $smcFunc['db_get_version'](); |
1023 | 1085 | // if we got a Beta Version |
1024 | - if (stripos($pg_version, 'beta') !== false) |
|
1025 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1086 | + if (stripos($pg_version, 'beta') !== false) { |
|
1087 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1088 | + } |
|
1026 | 1089 | // or RC |
1027 | - if (stripos($pg_version, 'rc') !== false) |
|
1028 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1090 | + if (stripos($pg_version, 'rc') !== false) { |
|
1091 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1092 | + } |
|
1029 | 1093 | |
1030 | 1094 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
1031 | 1095 | } |
@@ -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 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version, $settings; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -64,8 +66,9 @@ discard block |
||
64 | 66 | if (!empty($_REQUEST['c']) && empty($board)) |
65 | 67 | { |
66 | 68 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
67 | - foreach ($_REQUEST['c'] as $i => $c) |
|
68 | - $_REQUEST['c'][$i] = (int) $c; |
|
69 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
70 | + $_REQUEST['c'][$i] = (int) $c; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | if (count($_REQUEST['c']) == 1) |
71 | 74 | { |
@@ -101,18 +104,20 @@ discard block |
||
101 | 104 | } |
102 | 105 | $smcFunc['db_free_result']($request); |
103 | 106 | |
104 | - if (!empty($boards)) |
|
105 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
107 | + if (!empty($boards)) { |
|
108 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | // Try to limit the number of messages we look through. |
108 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
109 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
110 | - } |
|
111 | - elseif (!empty($_REQUEST['boards'])) |
|
112 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
113 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
114 | + } |
|
115 | + } elseif (!empty($_REQUEST['boards'])) |
|
112 | 116 | { |
113 | 117 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
114 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
115 | - $_REQUEST['boards'][$i] = (int) $b; |
|
118 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
119 | + $_REQUEST['boards'][$i] = (int) $b; |
|
120 | + } |
|
116 | 121 | |
117 | 122 | $request = $smcFunc['db_query']('', ' |
118 | 123 | SELECT b.id_board, b.num_posts, b.name |
@@ -128,29 +133,32 @@ discard block |
||
128 | 133 | |
129 | 134 | // Either the board specified doesn't exist or you have no access. |
130 | 135 | $num_boards = $smcFunc['db_num_rows']($request); |
131 | - if ($num_boards == 0) |
|
132 | - fatal_lang_error('no_board'); |
|
136 | + if ($num_boards == 0) { |
|
137 | + fatal_lang_error('no_board'); |
|
138 | + } |
|
133 | 139 | |
134 | 140 | $total_posts = 0; |
135 | 141 | $boards = array(); |
136 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
137 | 143 | { |
138 | - if ($num_boards == 1) |
|
139 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
144 | + if ($num_boards == 1) { |
|
145 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
146 | + } |
|
140 | 147 | |
141 | 148 | $boards[] = $row['id_board']; |
142 | 149 | $total_posts += $row['num_posts']; |
143 | 150 | } |
144 | 151 | $smcFunc['db_free_result']($request); |
145 | 152 | |
146 | - if (!empty($boards)) |
|
147 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
153 | + if (!empty($boards)) { |
|
154 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
155 | + } |
|
148 | 156 | |
149 | 157 | // The more boards, the more we're going to look through... |
150 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
151 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
152 | - } |
|
153 | - elseif (!empty($board)) |
|
158 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
159 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
160 | + } |
|
161 | + } elseif (!empty($board)) |
|
154 | 162 | { |
155 | 163 | $request = $smcFunc['db_query']('', ' |
156 | 164 | SELECT num_posts |
@@ -170,10 +178,10 @@ discard block |
||
170 | 178 | $query_this_board = 'b.id_board = ' . $board; |
171 | 179 | |
172 | 180 | // Try to look through just a few messages, if at all possible. |
173 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
174 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
175 | - } |
|
176 | - else |
|
181 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
182 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
183 | + } |
|
184 | + } else |
|
177 | 185 | { |
178 | 186 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
179 | 187 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -196,30 +204,35 @@ discard block |
||
196 | 204 | // Easy adding of sub actions |
197 | 205 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
198 | 206 | |
199 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
200 | - $_GET['sa'] = 'recent'; |
|
207 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
208 | + $_GET['sa'] = 'recent'; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | // We only want some information, not all of it. |
203 | 212 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
204 | - foreach (array('board', 'boards', 'c') as $var) |
|
205 | - if (isset($_REQUEST[$var])) |
|
213 | + foreach (array('board', 'boards', 'c') as $var) { |
|
214 | + if (isset($_REQUEST[$var])) |
|
206 | 215 | $cachekey[] = $_REQUEST[$var]; |
216 | + } |
|
207 | 217 | $cachekey = md5($smcFunc['json_encode']($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
208 | 218 | $cache_t = microtime(true); |
209 | 219 | |
210 | 220 | // Get the associative array representing the xml. |
211 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
212 | - $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
222 | + $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
223 | + } |
|
213 | 224 | if (empty($xml_data)) |
214 | 225 | { |
215 | 226 | $call = call_helper($subActions[$_GET['sa']][0], true); |
216 | 227 | |
217 | - if (!empty($call)) |
|
218 | - $xml_data = call_user_func($call, $xml_format); |
|
228 | + if (!empty($call)) { |
|
229 | + $xml_data = call_user_func($call, $xml_format); |
|
230 | + } |
|
219 | 231 | |
220 | 232 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
221 | - || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) |
|
222 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
233 | + || (!$user_info['is_guest'] && (microtime(true) - $cache_t > 0.2)))) { |
|
234 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
235 | + } |
|
223 | 236 | } |
224 | 237 | |
225 | 238 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -259,43 +272,49 @@ discard block |
||
259 | 272 | call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa'])); |
260 | 273 | |
261 | 274 | // These can't be empty |
262 | - foreach (array('title', 'desc', 'source') as $mkey) |
|
263 | - $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
275 | + foreach (array('title', 'desc', 'source') as $mkey) { |
|
276 | + $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
277 | + } |
|
264 | 278 | |
265 | 279 | // Sanitize basic feed metadata values |
266 | - foreach ($feed_meta as $mkey => $mvalue) |
|
267 | - $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
280 | + foreach ($feed_meta as $mkey => $mvalue) { |
|
281 | + $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
282 | + } |
|
268 | 283 | |
269 | 284 | $ns_string = ''; |
270 | 285 | if (!empty($namespaces[$xml_format])) |
271 | 286 | { |
272 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
273 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
287 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
288 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
289 | + } |
|
274 | 290 | } |
275 | 291 | |
276 | 292 | $extraFeedTags_string = ''; |
277 | 293 | if (!empty($extraFeedTags[$xml_format])) |
278 | 294 | { |
279 | 295 | $indent = "\t" . ($xml_format !== 'atom' ? "\t" : ''); |
280 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
281 | - $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
297 | + $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
298 | + } |
|
282 | 299 | } |
283 | 300 | |
284 | 301 | // This is an xml file.... |
285 | 302 | ob_end_clean(); |
286 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
287 | - @ob_start('ob_gzhandler'); |
|
288 | - else |
|
289 | - ob_start(); |
|
303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
304 | + @ob_start('ob_gzhandler'); |
|
305 | + } else { |
|
306 | + ob_start(); |
|
307 | + } |
|
290 | 308 | |
291 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
292 | - header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
293 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
294 | - header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | - elseif ($xml_format == 'atom') |
|
296 | - header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | - elseif ($xml_format == 'rdf') |
|
298 | - header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
310 | + header('content-type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
312 | + header('content-type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
313 | + } elseif ($xml_format == 'atom') { |
|
314 | + header('content-type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
315 | + } elseif ($xml_format == 'rdf') { |
|
316 | + header('content-type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
317 | + } |
|
299 | 318 | |
300 | 319 | // First, output the xml header. |
301 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -303,10 +322,11 @@ discard block |
||
303 | 322 | // Are we outputting an rss feed or one with more information? |
304 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
305 | 324 | { |
306 | - if ($xml_format == 'rss2') |
|
307 | - foreach ($_REQUEST as $var => $val) |
|
325 | + if ($xml_format == 'rss2') { |
|
326 | + foreach ($_REQUEST as $var => $val) |
|
308 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
309 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
329 | + } |
|
310 | 330 | |
311 | 331 | // Start with an RSS 2.0 header. |
312 | 332 | echo ' |
@@ -327,9 +347,10 @@ discard block |
||
327 | 347 | <language>' . $feed_meta['language'] . '</language>' : ''; |
328 | 348 | |
329 | 349 | // RSS2 calls for this. |
330 | - if ($xml_format == 'rss2') |
|
331 | - echo ' |
|
350 | + if ($xml_format == 'rss2') { |
|
351 | + echo ' |
|
332 | 352 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
353 | + } |
|
333 | 354 | |
334 | 355 | echo $extraFeedTags_string; |
335 | 356 | |
@@ -340,12 +361,12 @@ discard block |
||
340 | 361 | echo ' |
341 | 362 | </channel> |
342 | 363 | </rss>'; |
343 | - } |
|
344 | - elseif ($xml_format == 'atom') |
|
364 | + } elseif ($xml_format == 'atom') |
|
345 | 365 | { |
346 | - foreach ($_REQUEST as $var => $val) |
|
347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
366 | + foreach ($_REQUEST as $var => $val) { |
|
367 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
348 | 368 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
369 | + } |
|
349 | 370 | |
350 | 371 | echo ' |
351 | 372 | <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '> |
@@ -371,8 +392,7 @@ discard block |
||
371 | 392 | |
372 | 393 | echo ' |
373 | 394 | </feed>'; |
374 | - } |
|
375 | - elseif ($xml_format == 'rdf') |
|
395 | + } elseif ($xml_format == 'rdf') |
|
376 | 396 | { |
377 | 397 | echo ' |
378 | 398 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +457,15 @@ discard block |
||
437 | 457 | { |
438 | 458 | global $modSettings, $context, $scripturl; |
439 | 459 | |
440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
441 | - return $val; |
|
460 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
461 | + return $val; |
|
462 | + } |
|
442 | 463 | |
443 | 464 | call_integration_hook('integrate_fix_url', array(&$val)); |
444 | 465 | |
445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
446 | - return $val; |
|
466 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
467 | + return $val; |
|
468 | + } |
|
447 | 469 | |
448 | 470 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
449 | 471 | { |
@@ -466,8 +488,9 @@ discard block |
||
466 | 488 | global $smcFunc; |
467 | 489 | |
468 | 490 | // Do we even need to do this? |
469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
470 | - return $data; |
|
491 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
492 | + return $data; |
|
493 | + } |
|
471 | 494 | |
472 | 495 | $cdata = '<, |
478 | 501 | $smcFunc['strpos']($data, ']', $pos), |
479 | 502 | ); |
480 | - if ($ns != '') |
|
481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
503 | + if ($ns != '') { |
|
504 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
505 | + } |
|
482 | 506 | foreach ($positions as $k => $dummy) |
483 | 507 | { |
484 | - if ($dummy === false) |
|
485 | - unset($positions[$k]); |
|
508 | + if ($dummy === false) { |
|
509 | + unset($positions[$k]); |
|
510 | + } |
|
486 | 511 | } |
487 | 512 | |
488 | 513 | $old = $pos; |
489 | 514 | $pos = empty($positions) ? $n : min($positions); |
490 | 515 | |
491 | - if ($pos - $old > 0) |
|
492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
493 | - if ($pos >= $n) |
|
494 | - break; |
|
516 | + if ($pos - $old > 0) { |
|
517 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
518 | + } |
|
519 | + if ($pos >= $n) { |
|
520 | + break; |
|
521 | + } |
|
495 | 522 | |
496 | 523 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
497 | 524 | { |
498 | 525 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
499 | - if ($pos2 === false) |
|
500 | - $pos2 = $n; |
|
501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
503 | - else |
|
504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
530 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
531 | + } else { |
|
532 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
535 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
508 | 536 | { |
509 | 537 | $cdata .= ']]>]< == '&') |
|
539 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
513 | 540 | { |
514 | 541 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
515 | - if ($pos2 === false) |
|
516 | - $pos2 = $n; |
|
542 | + if ($pos2 === false) { |
|
543 | + $pos2 = $n; |
|
544 | + } |
|
517 | 545 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
518 | 546 | |
519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
549 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
550 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
551 | + } |
|
523 | 552 | |
524 | 553 | $pos = $pos2 + 1; |
525 | 554 | } |
@@ -559,8 +588,9 @@ discard block |
||
559 | 588 | 'gender', |
560 | 589 | 'blurb', |
561 | 590 | ); |
562 | - if ($xml_format != 'atom') |
|
563 | - $keysToCdata[] = 'category'; |
|
591 | + if ($xml_format != 'atom') { |
|
592 | + $keysToCdata[] = 'category'; |
|
593 | + } |
|
564 | 594 | |
565 | 595 | if (!empty($forceCdataKeys)) |
566 | 596 | { |
@@ -577,8 +607,9 @@ discard block |
||
577 | 607 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
578 | 608 | |
579 | 609 | // Skip it, it's been set to null. |
580 | - if ($key === null || ($val === null && $attrs === null)) |
|
581 | - continue; |
|
610 | + if ($key === null || ($val === null && $attrs === null)) { |
|
611 | + continue; |
|
612 | + } |
|
582 | 613 | |
583 | 614 | $forceCdata = in_array($key, $forceCdataKeys); |
584 | 615 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -591,16 +622,16 @@ discard block |
||
591 | 622 | |
592 | 623 | if (!empty($attrs)) |
593 | 624 | { |
594 | - foreach ($attrs as $attr_key => $attr_value) |
|
595 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
625 | + foreach ($attrs as $attr_key => $attr_value) { |
|
626 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
627 | + } |
|
596 | 628 | } |
597 | 629 | |
598 | 630 | // If it's empty, simply output an empty element. |
599 | 631 | if (empty($val)) |
600 | 632 | { |
601 | 633 | echo ' />'; |
602 | - } |
|
603 | - else |
|
634 | + } else |
|
604 | 635 | { |
605 | 636 | echo '>'; |
606 | 637 | |
@@ -612,11 +643,13 @@ discard block |
||
612 | 643 | echo "\n", str_repeat("\t", $i); |
613 | 644 | } |
614 | 645 | // A string with returns in it.... show this as a multiline element. |
615 | - elseif (strpos($val, "\n") !== false) |
|
616 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
646 | + elseif (strpos($val, "\n") !== false) { |
|
647 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
648 | + } |
|
617 | 649 | // A simple string. |
618 | - else |
|
619 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
650 | + else { |
|
651 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
652 | + } |
|
620 | 653 | |
621 | 654 | // Ending tag. |
622 | 655 | echo '</', $key, '>'; |
@@ -636,8 +669,9 @@ discard block |
||
636 | 669 | { |
637 | 670 | global $scripturl, $smcFunc; |
638 | 671 | |
639 | - if (!allowedTo('view_mlist')) |
|
640 | - return array(); |
|
672 | + if (!allowedTo('view_mlist')) { |
|
673 | + return array(); |
|
674 | + } |
|
641 | 675 | |
642 | 676 | // Find the most recent members. |
643 | 677 | $request = $smcFunc['db_query']('', ' |
@@ -656,8 +690,8 @@ discard block |
||
656 | 690 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
657 | 691 | |
658 | 692 | // Make the data look rss-ish. |
659 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
660 | - $data[] = array( |
|
693 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
694 | + $data[] = array( |
|
661 | 695 | 'tag' => 'item', |
662 | 696 | 'content' => array( |
663 | 697 | array( |
@@ -685,8 +719,8 @@ discard block |
||
685 | 719 | ), |
686 | 720 | ), |
687 | 721 | ); |
688 | - elseif ($xml_format == 'rdf') |
|
689 | - $data[] = array( |
|
722 | + } elseif ($xml_format == 'rdf') { |
|
723 | + $data[] = array( |
|
690 | 724 | 'tag' => 'item', |
691 | 725 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
692 | 726 | 'content' => array( |
@@ -704,8 +738,8 @@ discard block |
||
704 | 738 | ), |
705 | 739 | ), |
706 | 740 | ); |
707 | - elseif ($xml_format == 'atom') |
|
708 | - $data[] = array( |
|
741 | + } elseif ($xml_format == 'atom') { |
|
742 | + $data[] = array( |
|
709 | 743 | 'tag' => 'entry', |
710 | 744 | 'content' => array( |
711 | 745 | array( |
@@ -734,9 +768,10 @@ discard block |
||
734 | 768 | ), |
735 | 769 | ), |
736 | 770 | ); |
771 | + } |
|
737 | 772 | // More logical format for the data, but harder to apply. |
738 | - else |
|
739 | - $data[] = array( |
|
773 | + else { |
|
774 | + $data[] = array( |
|
740 | 775 | 'tag' => 'member', |
741 | 776 | 'content' => array( |
742 | 777 | array( |
@@ -757,6 +792,7 @@ discard block |
||
757 | 792 | ), |
758 | 793 | ), |
759 | 794 | ); |
795 | + } |
|
760 | 796 | } |
761 | 797 | $smcFunc['db_free_result']($request); |
762 | 798 | |
@@ -817,22 +853,24 @@ discard block |
||
817 | 853 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
818 | 854 | { |
819 | 855 | $smcFunc['db_free_result']($request); |
820 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
821 | - unset($context['optimize_msg']['lowest']); |
|
822 | - else |
|
823 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
856 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
857 | + unset($context['optimize_msg']['lowest']); |
|
858 | + } else { |
|
859 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
860 | + } |
|
824 | 861 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
825 | 862 | $loops++; |
863 | + } else { |
|
864 | + $done = true; |
|
826 | 865 | } |
827 | - else |
|
828 | - $done = true; |
|
829 | 866 | } |
830 | 867 | $data = array(); |
831 | 868 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
832 | 869 | { |
833 | 870 | // Limit the length of the message, if the option is set. |
834 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
835 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
871 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
872 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
873 | + } |
|
836 | 874 | |
837 | 875 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
838 | 876 | |
@@ -859,8 +897,9 @@ discard block |
||
859 | 897 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
860 | 898 | { |
861 | 899 | // Include approved attachments only |
862 | - if ($attach['approved']) |
|
863 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
900 | + if ($attach['approved']) { |
|
901 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
902 | + } |
|
864 | 903 | } |
865 | 904 | $smcFunc['db_free_result']($attach_request); |
866 | 905 | |
@@ -868,16 +907,17 @@ discard block |
||
868 | 907 | if (!empty($loaded_attachments)) |
869 | 908 | { |
870 | 909 | uasort($loaded_attachments, function($a, $b) { |
871 | - if ($a['filesize'] == $b['filesize']) |
|
872 | - return 0; |
|
910 | + if ($a['filesize'] == $b['filesize']) { |
|
911 | + return 0; |
|
912 | + } |
|
873 | 913 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
874 | 914 | }); |
915 | + } else { |
|
916 | + $loaded_attachments = null; |
|
875 | 917 | } |
876 | - else |
|
877 | - $loaded_attachments = null; |
|
918 | + } else { |
|
919 | + $loaded_attachments = null; |
|
878 | 920 | } |
879 | - else |
|
880 | - $loaded_attachments = null; |
|
881 | 921 | |
882 | 922 | // Create a GUID for this topic using the tag URI scheme |
883 | 923 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -894,9 +934,9 @@ discard block |
||
894 | 934 | 'length' => $attachment['filesize'], |
895 | 935 | 'type' => $attachment['mime_type'], |
896 | 936 | ); |
937 | + } else { |
|
938 | + $enclosure = null; |
|
897 | 939 | } |
898 | - else |
|
899 | - $enclosure = null; |
|
900 | 940 | |
901 | 941 | $data[] = array( |
902 | 942 | 'tag' => 'item', |
@@ -942,8 +982,7 @@ discard block |
||
942 | 982 | ), |
943 | 983 | ), |
944 | 984 | ); |
945 | - } |
|
946 | - elseif ($xml_format == 'rdf') |
|
985 | + } elseif ($xml_format == 'rdf') |
|
947 | 986 | { |
948 | 987 | $data[] = array( |
949 | 988 | 'tag' => 'item', |
@@ -967,8 +1006,7 @@ discard block |
||
967 | 1006 | ), |
968 | 1007 | ), |
969 | 1008 | ); |
970 | - } |
|
971 | - elseif ($xml_format == 'atom') |
|
1009 | + } elseif ($xml_format == 'atom') |
|
972 | 1010 | { |
973 | 1011 | // Only one attachment allowed |
974 | 1012 | if (!empty($loaded_attachments)) |
@@ -980,9 +1018,9 @@ discard block |
||
980 | 1018 | 'length' => $attachment['filesize'], |
981 | 1019 | 'type' => $attachment['mime_type'], |
982 | 1020 | ); |
1021 | + } else { |
|
1022 | + $enclosure = null; |
|
983 | 1023 | } |
984 | - else |
|
985 | - $enclosure = null; |
|
986 | 1024 | |
987 | 1025 | $data[] = array( |
988 | 1026 | 'tag' => 'entry', |
@@ -1082,9 +1120,9 @@ discard block |
||
1082 | 1120 | ) |
1083 | 1121 | ); |
1084 | 1122 | } |
1123 | + } else { |
|
1124 | + $attachments = null; |
|
1085 | 1125 | } |
1086 | - else |
|
1087 | - $attachments = null; |
|
1088 | 1126 | |
1089 | 1127 | $data[] = array( |
1090 | 1128 | 'tag' => 'article', |
@@ -1202,22 +1240,25 @@ discard block |
||
1202 | 1240 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1203 | 1241 | { |
1204 | 1242 | $smcFunc['db_free_result']($request); |
1205 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1206 | - unset($context['optimize_msg']['lowest']); |
|
1207 | - else |
|
1208 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1243 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1244 | + unset($context['optimize_msg']['lowest']); |
|
1245 | + } else { |
|
1246 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1247 | + } |
|
1209 | 1248 | $loops++; |
1249 | + } else { |
|
1250 | + $done = true; |
|
1210 | 1251 | } |
1211 | - else |
|
1212 | - $done = true; |
|
1213 | 1252 | } |
1214 | 1253 | $messages = array(); |
1215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1216 | - $messages[] = $row['id_msg']; |
|
1254 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1255 | + $messages[] = $row['id_msg']; |
|
1256 | + } |
|
1217 | 1257 | $smcFunc['db_free_result']($request); |
1218 | 1258 | |
1219 | - if (empty($messages)) |
|
1220 | - return array(); |
|
1259 | + if (empty($messages)) { |
|
1260 | + return array(); |
|
1261 | + } |
|
1221 | 1262 | |
1222 | 1263 | // Find the most recent posts this user can see. |
1223 | 1264 | $request = $smcFunc['db_query']('', ' |
@@ -1247,8 +1288,9 @@ discard block |
||
1247 | 1288 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1248 | 1289 | { |
1249 | 1290 | // Limit the length of the message, if the option is set. |
1250 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1251 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1291 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1292 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1293 | + } |
|
1252 | 1294 | |
1253 | 1295 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1254 | 1296 | |
@@ -1275,8 +1317,9 @@ discard block |
||
1275 | 1317 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1276 | 1318 | { |
1277 | 1319 | // Include approved attachments only |
1278 | - if ($attach['approved']) |
|
1279 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1320 | + if ($attach['approved']) { |
|
1321 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1322 | + } |
|
1280 | 1323 | } |
1281 | 1324 | $smcFunc['db_free_result']($attach_request); |
1282 | 1325 | |
@@ -1284,16 +1327,17 @@ discard block |
||
1284 | 1327 | if (!empty($loaded_attachments)) |
1285 | 1328 | { |
1286 | 1329 | uasort($loaded_attachments, function($a, $b) { |
1287 | - if ($a['filesize'] == $b['filesize']) |
|
1288 | - return 0; |
|
1330 | + if ($a['filesize'] == $b['filesize']) { |
|
1331 | + return 0; |
|
1332 | + } |
|
1289 | 1333 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1290 | 1334 | }); |
1335 | + } else { |
|
1336 | + $loaded_attachments = null; |
|
1291 | 1337 | } |
1292 | - else |
|
1293 | - $loaded_attachments = null; |
|
1338 | + } else { |
|
1339 | + $loaded_attachments = null; |
|
1294 | 1340 | } |
1295 | - else |
|
1296 | - $loaded_attachments = null; |
|
1297 | 1341 | |
1298 | 1342 | // Create a GUID for this post using the tag URI scheme |
1299 | 1343 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1310,9 +1354,9 @@ discard block |
||
1310 | 1354 | 'length' => $attachment['filesize'], |
1311 | 1355 | 'type' => $attachment['mime_type'], |
1312 | 1356 | ); |
1357 | + } else { |
|
1358 | + $enclosure = null; |
|
1313 | 1359 | } |
1314 | - else |
|
1315 | - $enclosure = null; |
|
1316 | 1360 | |
1317 | 1361 | $data[] = array( |
1318 | 1362 | 'tag' => 'item', |
@@ -1358,8 +1402,7 @@ discard block |
||
1358 | 1402 | ), |
1359 | 1403 | ), |
1360 | 1404 | ); |
1361 | - } |
|
1362 | - elseif ($xml_format == 'rdf') |
|
1405 | + } elseif ($xml_format == 'rdf') |
|
1363 | 1406 | { |
1364 | 1407 | $data[] = array( |
1365 | 1408 | 'tag' => 'item', |
@@ -1383,8 +1426,7 @@ discard block |
||
1383 | 1426 | ), |
1384 | 1427 | ), |
1385 | 1428 | ); |
1386 | - } |
|
1387 | - elseif ($xml_format == 'atom') |
|
1429 | + } elseif ($xml_format == 'atom') |
|
1388 | 1430 | { |
1389 | 1431 | // Only one attachment allowed |
1390 | 1432 | if (!empty($loaded_attachments)) |
@@ -1396,9 +1438,9 @@ discard block |
||
1396 | 1438 | 'length' => $attachment['filesize'], |
1397 | 1439 | 'type' => $attachment['mime_type'], |
1398 | 1440 | ); |
1441 | + } else { |
|
1442 | + $enclosure = null; |
|
1399 | 1443 | } |
1400 | - else |
|
1401 | - $enclosure = null; |
|
1402 | 1444 | |
1403 | 1445 | $data[] = array( |
1404 | 1446 | 'tag' => 'entry', |
@@ -1498,9 +1540,9 @@ discard block |
||
1498 | 1540 | ) |
1499 | 1541 | ); |
1500 | 1542 | } |
1543 | + } else { |
|
1544 | + $attachments = null; |
|
1501 | 1545 | } |
1502 | - else |
|
1503 | - $attachments = null; |
|
1504 | 1546 | |
1505 | 1547 | $data[] = array( |
1506 | 1548 | 'tag' => 'recent-post', |
@@ -1619,14 +1661,16 @@ discard block |
||
1619 | 1661 | global $scripturl, $memberContext, $user_profile, $user_info; |
1620 | 1662 | |
1621 | 1663 | // You must input a valid user.... |
1622 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1623 | - return array(); |
|
1664 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1665 | + return array(); |
|
1666 | + } |
|
1624 | 1667 | |
1625 | 1668 | // Make sure the id is a number and not "I like trying to hack the database". |
1626 | 1669 | $_GET['u'] = (int) $_GET['u']; |
1627 | 1670 | // Load the member's contextual information! |
1628 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1629 | - return array(); |
|
1671 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1672 | + return array(); |
|
1673 | + } |
|
1630 | 1674 | |
1631 | 1675 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1632 | 1676 | $profile = &$memberContext[$_GET['u']]; |
@@ -1668,8 +1712,7 @@ discard block |
||
1668 | 1712 | ), |
1669 | 1713 | ) |
1670 | 1714 | ); |
1671 | - } |
|
1672 | - elseif ($xml_format == 'rdf') |
|
1715 | + } elseif ($xml_format == 'rdf') |
|
1673 | 1716 | { |
1674 | 1717 | $data[] = array( |
1675 | 1718 | 'tag' => 'item', |
@@ -1693,8 +1736,7 @@ discard block |
||
1693 | 1736 | ), |
1694 | 1737 | ) |
1695 | 1738 | ); |
1696 | - } |
|
1697 | - elseif ($xml_format == 'atom') |
|
1739 | + } elseif ($xml_format == 'atom') |
|
1698 | 1740 | { |
1699 | 1741 | $data[] = array( |
1700 | 1742 | 'tag' => 'entry', |
@@ -1747,8 +1789,7 @@ discard block |
||
1747 | 1789 | ), |
1748 | 1790 | ) |
1749 | 1791 | ); |
1750 | - } |
|
1751 | - else |
|
1792 | + } else |
|
1752 | 1793 | { |
1753 | 1794 | $data = array( |
1754 | 1795 | array( |
@@ -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 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -41,10 +42,11 @@ discard block |
||
41 | 42 | ); |
42 | 43 | |
43 | 44 | // We need to find what's the action. |
44 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
45 | - $context['sub_action'] = $_REQUEST['sa']; |
|
46 | - else |
|
47 | - $context['sub_action'] = 'tasks'; |
|
45 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
46 | + $context['sub_action'] = $_REQUEST['sa']; |
|
47 | + } else { |
|
48 | + $context['sub_action'] = 'tasks'; |
|
49 | + } |
|
48 | 50 | |
49 | 51 | // Now for the lovely tabs. That we all love. |
50 | 52 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -94,9 +96,10 @@ discard block |
||
94 | 96 | |
95 | 97 | // Enable and disable as required. |
96 | 98 | $enablers = array(0); |
97 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
98 | - if ($enabled) |
|
99 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
100 | + if ($enabled) |
|
99 | 101 | $enablers[] = (int) $id; |
102 | + } |
|
100 | 103 | |
101 | 104 | // Do the update! |
102 | 105 | $smcFunc['db_query']('', ' |
@@ -134,8 +137,9 @@ discard block |
||
134 | 137 | |
135 | 138 | // Lets figure out which ones they want to run. |
136 | 139 | $tasks = array(); |
137 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
138 | - $tasks[] = (int) $task; |
|
140 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
141 | + $tasks[] = (int) $task; |
|
142 | + } |
|
139 | 143 | |
140 | 144 | // Load up the tasks. |
141 | 145 | $request = $smcFunc['db_query']('', ' |
@@ -155,36 +159,41 @@ discard block |
||
155 | 159 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
156 | 160 | { |
157 | 161 | // What kind of task are we handling? |
158 | - if (!empty($row['callable'])) |
|
159 | - $task_string = $row['callable']; |
|
162 | + if (!empty($row['callable'])) { |
|
163 | + $task_string = $row['callable']; |
|
164 | + } |
|
160 | 165 | |
161 | 166 | // Default SMF task or old mods? |
162 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
163 | - $task_string = 'scheduled_' . $row['task']; |
|
167 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
168 | + $task_string = 'scheduled_' . $row['task']; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // One last resource, the task name. |
166 | - elseif (!empty($row['task'])) |
|
167 | - $task_string = $row['task']; |
|
172 | + elseif (!empty($row['task'])) { |
|
173 | + $task_string = $row['task']; |
|
174 | + } |
|
168 | 175 | |
169 | 176 | $start_time = microtime(true); |
170 | 177 | // The functions got to exist for us to use it. |
171 | - if (empty($task_string)) |
|
172 | - continue; |
|
178 | + if (empty($task_string)) { |
|
179 | + continue; |
|
180 | + } |
|
173 | 181 | |
174 | 182 | // Try to stop a timeout, this would be bad... |
175 | 183 | @set_time_limit(300); |
176 | - if (function_exists('apache_reset_timeout')) |
|
177 | - @apache_reset_timeout(); |
|
184 | + if (function_exists('apache_reset_timeout')) { |
|
185 | + @apache_reset_timeout(); |
|
186 | + } |
|
178 | 187 | |
179 | 188 | // Get the callable. |
180 | 189 | $callable_task = call_helper($task_string, true); |
181 | 190 | |
182 | 191 | // Perform the task. |
183 | - if (!empty($callable_task)) |
|
184 | - $completed = call_user_func($callable_task); |
|
185 | - |
|
186 | - else |
|
187 | - $completed = false; |
|
192 | + if (!empty($callable_task)) { |
|
193 | + $completed = call_user_func($callable_task); |
|
194 | + } else { |
|
195 | + $completed = false; |
|
196 | + } |
|
188 | 197 | |
189 | 198 | // Log that we did it ;) |
190 | 199 | if ($completed) |
@@ -201,8 +210,9 @@ discard block |
||
201 | 210 | $smcFunc['db_free_result']($request); |
202 | 211 | |
203 | 212 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
204 | - if (!empty($context['scheduled_errors'])) |
|
205 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
213 | + if (!empty($context['scheduled_errors'])) { |
|
214 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
215 | + } |
|
206 | 216 | |
207 | 217 | redirectexit('action=admin;area=scheduledtasks;done'); |
208 | 218 | } |
@@ -374,8 +384,9 @@ discard block |
||
374 | 384 | $context['server_time'] = timeformat(time(), false, 'server'); |
375 | 385 | |
376 | 386 | // Cleaning... |
377 | - if (!isset($_GET['tid'])) |
|
378 | - fatal_lang_error('no_access', false); |
|
387 | + if (!isset($_GET['tid'])) { |
|
388 | + fatal_lang_error('no_access', false); |
|
389 | + } |
|
379 | 390 | $_GET['tid'] = (int) $_GET['tid']; |
380 | 391 | |
381 | 392 | // Saving? |
@@ -391,10 +402,12 @@ discard block |
||
391 | 402 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
392 | 403 | |
393 | 404 | // If a half is empty then assume zero offset! |
394 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
395 | - $matches[2] = 0; |
|
396 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
397 | - $matches[1] = 0; |
|
405 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
406 | + $matches[2] = 0; |
|
407 | + } |
|
408 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
409 | + $matches[1] = 0; |
|
410 | + } |
|
398 | 411 | |
399 | 412 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
400 | 413 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -404,8 +417,9 @@ discard block |
||
404 | 417 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
405 | 418 | |
406 | 419 | // Don't allow one minute intervals. |
407 | - if ($interval == 1 && $unit == 'm') |
|
408 | - $interval = 2; |
|
420 | + if ($interval == 1 && $unit == 'm') { |
|
421 | + $interval = 2; |
|
422 | + } |
|
409 | 423 | |
410 | 424 | // Is it disabled? |
411 | 425 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -443,8 +457,9 @@ discard block |
||
443 | 457 | ); |
444 | 458 | |
445 | 459 | // Should never, ever, happen! |
446 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
447 | - fatal_lang_error('no_access', false); |
|
460 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
461 | + fatal_lang_error('no_access', false); |
|
462 | + } |
|
448 | 463 | |
449 | 464 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
450 | 465 | { |
@@ -602,13 +617,14 @@ discard block |
||
602 | 617 | ) |
603 | 618 | ); |
604 | 619 | $log_entries = array(); |
605 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
606 | - $log_entries[] = array( |
|
620 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
621 | + $log_entries[] = array( |
|
607 | 622 | 'id' => $row['id_log'], |
608 | 623 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
609 | 624 | 'time_run' => $row['time_run'], |
610 | 625 | 'time_taken' => $row['time_taken'], |
611 | 626 | ); |
627 | + } |
|
612 | 628 | $smcFunc['db_free_result']($request); |
613 | 629 | |
614 | 630 | return $log_entries; |
@@ -649,8 +665,9 @@ discard block |
||
649 | 665 | |
650 | 666 | call_integration_hook('integrate_scheduled_tasks_settings', array(&$config_vars)); |
651 | 667 | |
652 | - if ($return_config) |
|
653 | - return $config_vars; |
|
668 | + if ($return_config) { |
|
669 | + return $config_vars; |
|
670 | + } |
|
654 | 671 | |
655 | 672 | // Set up the template. |
656 | 673 | $context['page_title'] = $txt['scheduled_tasks_settings']; |