@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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. |
@@ -153,11 +154,11 @@ discard block |
||
153 | 154 | $language_list = new xmlArray(fetch_web_data($url), true); |
154 | 155 | |
155 | 156 | // Check that the site responded and that the language exists. |
156 | - if (!$language_list->exists('languages')) |
|
157 | - $context['smf_error'] = 'no_response'; |
|
158 | - elseif (!$language_list->exists('languages/language')) |
|
159 | - $context['smf_error'] = 'no_files'; |
|
160 | - else |
|
157 | + if (!$language_list->exists('languages')) { |
|
158 | + $context['smf_error'] = 'no_response'; |
|
159 | + } elseif (!$language_list->exists('languages/language')) { |
|
160 | + $context['smf_error'] = 'no_files'; |
|
161 | + } else |
|
161 | 162 | { |
162 | 163 | $language_list = $language_list->path('languages[0]'); |
163 | 164 | $lang_files = $language_list->set('language'); |
@@ -165,8 +166,9 @@ discard block |
||
165 | 166 | foreach ($lang_files as $file) |
166 | 167 | { |
167 | 168 | // Were we searching? |
168 | - if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) |
|
169 | - continue; |
|
169 | + if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) { |
|
170 | + continue; |
|
171 | + } |
|
170 | 172 | |
171 | 173 | $smf_languages[] = array( |
172 | 174 | 'id' => $file->fetch('id'), |
@@ -177,10 +179,11 @@ discard block |
||
177 | 179 | '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>', |
178 | 180 | ); |
179 | 181 | } |
180 | - if (empty($smf_languages)) |
|
181 | - $context['smf_error'] = 'no_files'; |
|
182 | - else |
|
183 | - return $smf_languages; |
|
182 | + if (empty($smf_languages)) { |
|
183 | + $context['smf_error'] = 'no_files'; |
|
184 | + } else { |
|
185 | + return $smf_languages; |
|
186 | + } |
|
184 | 187 | } |
185 | 188 | } |
186 | 189 | |
@@ -202,8 +205,9 @@ discard block |
||
202 | 205 | require_once($sourcedir . '/Subs-Package.php'); |
203 | 206 | |
204 | 207 | // Clearly we need to know what to request. |
205 | - if (!isset($_GET['did'])) |
|
206 | - fatal_lang_error('no_access', false); |
|
208 | + if (!isset($_GET['did'])) { |
|
209 | + fatal_lang_error('no_access', false); |
|
210 | + } |
|
207 | 211 | |
208 | 212 | // Some lovely context. |
209 | 213 | $context['download_id'] = $_GET['did']; |
@@ -223,8 +227,9 @@ discard block |
||
223 | 227 | foreach ($_POST['copy_file'] as $file) |
224 | 228 | { |
225 | 229 | // Check it's not very bad. |
226 | - if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) |
|
227 | - fatal_error($txt['languages_download_illegal_paths']); |
|
230 | + if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) { |
|
231 | + fatal_error($txt['languages_download_illegal_paths']); |
|
232 | + } |
|
228 | 233 | |
229 | 234 | $chmod_files[] = $boarddir . '/' . $file; |
230 | 235 | $install_files[] = $file; |
@@ -235,8 +240,9 @@ discard block |
||
235 | 240 | $files_left = $file_status['files']['notwritable']; |
236 | 241 | |
237 | 242 | // Something not writable? |
238 | - if (!empty($files_left)) |
|
239 | - $context['error_message'] = $txt['languages_download_not_chmod']; |
|
243 | + if (!empty($files_left)) { |
|
244 | + $context['error_message'] = $txt['languages_download_not_chmod']; |
|
245 | + } |
|
240 | 246 | // Otherwise, go go go! |
241 | 247 | elseif (!empty($install_files)) |
242 | 248 | { |
@@ -250,11 +256,13 @@ discard block |
||
250 | 256 | } |
251 | 257 | |
252 | 258 | // Open up the old china. |
253 | - if (!isset($archive_content)) |
|
254 | - $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
259 | + if (!isset($archive_content)) { |
|
260 | + $archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
261 | + } |
|
255 | 262 | |
256 | - if (empty($archive_content)) |
|
257 | - fatal_error($txt['add_language_error_no_response']); |
|
263 | + if (empty($archive_content)) { |
|
264 | + fatal_error($txt['add_language_error_no_response']); |
|
265 | + } |
|
258 | 266 | |
259 | 267 | // Now for each of the files, let's do some *stuff* |
260 | 268 | $context['files'] = array( |
@@ -269,8 +277,9 @@ discard block |
||
269 | 277 | $extension = substr($filename, strrpos($filename, '.') + 1); |
270 | 278 | |
271 | 279 | // Don't do anything with files we don't understand. |
272 | - if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) |
|
273 | - continue; |
|
280 | + if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) { |
|
281 | + continue; |
|
282 | + } |
|
274 | 283 | |
275 | 284 | // Basic data. |
276 | 285 | $context_data = array( |
@@ -289,8 +298,9 @@ discard block |
||
289 | 298 | // Does the file exist, is it different and can we overwrite? |
290 | 299 | if (file_exists($boarddir . '/' . $file['filename'])) |
291 | 300 | { |
292 | - if (is_writable($boarddir . '/' . $file['filename'])) |
|
293 | - $context_data['writable'] = true; |
|
301 | + if (is_writable($boarddir . '/' . $file['filename'])) { |
|
302 | + $context_data['writable'] = true; |
|
303 | + } |
|
294 | 304 | |
295 | 305 | // Finally, do we actually think the content has changed? |
296 | 306 | if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) |
@@ -303,16 +313,17 @@ discard block |
||
303 | 313 | { |
304 | 314 | $context_data['exists'] = 'same'; |
305 | 315 | $context_data['default_copy'] = false; |
316 | + } else { |
|
317 | + $context_data['exists'] = 'different'; |
|
306 | 318 | } |
307 | - else |
|
308 | - $context_data['exists'] = 'different'; |
|
309 | 319 | } |
310 | 320 | // No overwrite? |
311 | 321 | else |
312 | 322 | { |
313 | 323 | // Can we at least stick it in the directory... |
314 | - if (is_writable($boarddir . '/' . $dirname)) |
|
315 | - $context_data['writable'] = true; |
|
324 | + if (is_writable($boarddir . '/' . $dirname)) { |
|
325 | + $context_data['writable'] = true; |
|
326 | + } |
|
316 | 327 | } |
317 | 328 | |
318 | 329 | // 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... |
@@ -327,8 +338,9 @@ discard block |
||
327 | 338 | list ($name, $language) = explode('.', $filename); |
328 | 339 | |
329 | 340 | // Let's get the new version, I like versions, they tell me that I'm up to date. |
330 | - if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) |
|
331 | - $context_data['version'] = $match[1]; |
|
341 | + if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) { |
|
342 | + $context_data['version'] = $match[1]; |
|
343 | + } |
|
332 | 344 | |
333 | 345 | // Now does the old file exist - if so what is it's version? |
334 | 346 | if (file_exists($boarddir . '/' . $file['filename'])) |
@@ -344,34 +356,35 @@ discard block |
||
344 | 356 | $context_data['cur_version'] = $match[1]; |
345 | 357 | |
346 | 358 | // How does this compare? |
347 | - if ($context_data['cur_version'] == $context_data['version']) |
|
348 | - $context_data['version_compare'] = 'same'; |
|
349 | - elseif ($context_data['cur_version'] > $context_data['version']) |
|
350 | - $context_data['version_compare'] = 'older'; |
|
359 | + if ($context_data['cur_version'] == $context_data['version']) { |
|
360 | + $context_data['version_compare'] = 'same'; |
|
361 | + } elseif ($context_data['cur_version'] > $context_data['version']) { |
|
362 | + $context_data['version_compare'] = 'older'; |
|
363 | + } |
|
351 | 364 | |
352 | 365 | // Don't recommend copying if the version is the same. |
353 | - if ($context_data['version_compare'] != 'newer') |
|
354 | - $context_data['default_copy'] = false; |
|
366 | + if ($context_data['version_compare'] != 'newer') { |
|
367 | + $context_data['default_copy'] = false; |
|
368 | + } |
|
355 | 369 | } |
356 | 370 | } |
357 | 371 | |
358 | 372 | // Add the context data to the main set. |
359 | 373 | $context['files']['lang'][] = $context_data; |
360 | - } |
|
361 | - elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
374 | + } elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
362 | 375 | { |
363 | 376 | // Registration agreement is a primary file |
364 | 377 | $context['files']['lang'][] = $context_data; |
365 | - } |
|
366 | - else |
|
378 | + } else |
|
367 | 379 | { |
368 | 380 | // There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future |
369 | 381 | $context['files']['other'][] = $context_data; |
370 | 382 | } |
371 | 383 | |
372 | 384 | // Collect together all non-writable areas. |
373 | - if (!$context_data['writable']) |
|
374 | - $context['make_writable'][] = $context_data['destination']; |
|
385 | + if (!$context_data['writable']) { |
|
386 | + $context['make_writable'][] = $context_data['destination']; |
|
387 | + } |
|
375 | 388 | } |
376 | 389 | |
377 | 390 | // Before we go to far can we make anything writable, eh, eh? |
@@ -386,22 +399,24 @@ discard block |
||
386 | 399 | { |
387 | 400 | if ($type == 'lang') |
388 | 401 | { |
389 | - foreach ($data as $k => $file) |
|
390 | - if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
402 | + foreach ($data as $k => $file) { |
|
403 | + if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
391 | 404 | $context['files'][$type][$k]['writable'] = true; |
392 | - } |
|
393 | - else |
|
405 | + } |
|
406 | + } else |
|
394 | 407 | { |
395 | - foreach ($data as $theme => $files) |
|
396 | - foreach ($files as $k => $file) |
|
408 | + foreach ($data as $theme => $files) { |
|
409 | + foreach ($files as $k => $file) |
|
397 | 410 | if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
398 | 411 | $context['files'][$type][$theme][$k]['writable'] = true; |
412 | + } |
|
399 | 413 | } |
400 | 414 | } |
401 | 415 | |
402 | 416 | // Are we going to need more language stuff? |
403 | - if (!empty($context['still_not_writable'])) |
|
404 | - loadLanguage('Packages'); |
|
417 | + if (!empty($context['still_not_writable'])) { |
|
418 | + loadLanguage('Packages'); |
|
419 | + } |
|
405 | 420 | } |
406 | 421 | |
407 | 422 | // This is the list for the main files. |
@@ -614,12 +629,13 @@ discard block |
||
614 | 629 | highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true); |
615 | 630 | |
616 | 631 | // Display a warning if we cannot edit the default setting. |
617 | - if (!is_writable($boarddir . '/Settings.php')) |
|
618 | - $listOptions['additional_rows'][] = array( |
|
632 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
633 | + $listOptions['additional_rows'][] = array( |
|
619 | 634 | 'position' => 'after_title', |
620 | 635 | 'value' => $txt['language_settings_writable'], |
621 | 636 | 'class' => 'smalltext alert', |
622 | 637 | ); |
638 | + } |
|
623 | 639 | |
624 | 640 | require_once($sourcedir . '/Subs-List.php'); |
625 | 641 | createList($listOptions); |
@@ -661,10 +677,11 @@ discard block |
||
661 | 677 | |
662 | 678 | // Put them back. |
663 | 679 | $settings['actual_theme_dir'] = $backup_actual_theme_dir; |
664 | - if (!empty($backup_base_theme_dir)) |
|
665 | - $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
666 | - else |
|
667 | - unset($settings['base_theme_dir']); |
|
680 | + if (!empty($backup_base_theme_dir)) { |
|
681 | + $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
682 | + } else { |
|
683 | + unset($settings['base_theme_dir']); |
|
684 | + } |
|
668 | 685 | |
669 | 686 | // Get the language files and data... |
670 | 687 | foreach ($context['languages'] as $lang) |
@@ -693,13 +710,15 @@ discard block |
||
693 | 710 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
694 | 711 | { |
695 | 712 | // Default? |
696 | - if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) |
|
697 | - $row['lngfile'] = $language; |
|
713 | + if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) { |
|
714 | + $row['lngfile'] = $language; |
|
715 | + } |
|
698 | 716 | |
699 | - if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) |
|
700 | - $languages['english']['count'] += $row['num_users']; |
|
701 | - elseif (isset($languages[$row['lngfile']])) |
|
702 | - $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
717 | + if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) { |
|
718 | + $languages['english']['count'] += $row['num_users']; |
|
719 | + } elseif (isset($languages[$row['lngfile']])) { |
|
720 | + $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
721 | + } |
|
703 | 722 | } |
704 | 723 | $smcFunc['db_free_result']($request); |
705 | 724 | |
@@ -739,13 +758,15 @@ discard block |
||
739 | 758 | |
740 | 759 | call_integration_hook('integrate_language_settings', array(&$config_vars)); |
741 | 760 | |
742 | - if ($return_config) |
|
743 | - return $config_vars; |
|
761 | + if ($return_config) { |
|
762 | + return $config_vars; |
|
763 | + } |
|
744 | 764 | |
745 | 765 | // Get our languages. No cache and use utf8. |
746 | 766 | getLanguages(false, false); |
747 | - foreach ($context['languages'] as $lang) |
|
748 | - $config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)'))); |
|
767 | + foreach ($context['languages'] as $lang) { |
|
768 | + $config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)'))); |
|
769 | + } |
|
749 | 770 | |
750 | 771 | // Saving settings? |
751 | 772 | if (isset($_REQUEST['save'])) |
@@ -755,8 +776,9 @@ discard block |
||
755 | 776 | call_integration_hook('integrate_save_language_settings', array(&$config_vars)); |
756 | 777 | |
757 | 778 | saveSettings($config_vars); |
758 | - if (!$settings_not_writable && !$settings_backup_fail) |
|
759 | - $_SESSION['adm-save'] = true; |
|
779 | + if (!$settings_not_writable && !$settings_backup_fail) { |
|
780 | + $_SESSION['adm-save'] = true; |
|
781 | + } |
|
760 | 782 | redirectexit('action=admin;area=languages;sa=settings'); |
761 | 783 | } |
762 | 784 | |
@@ -765,10 +787,11 @@ discard block |
||
765 | 787 | $context['settings_title'] = $txt['language_settings']; |
766 | 788 | $context['save_disabled'] = $settings_not_writable; |
767 | 789 | |
768 | - if ($settings_not_writable) |
|
769 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
770 | - elseif ($settings_backup_fail) |
|
771 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
790 | + if ($settings_not_writable) { |
|
791 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
792 | + } elseif ($settings_backup_fail) { |
|
793 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
794 | + } |
|
772 | 795 | |
773 | 796 | // Fill the config array. |
774 | 797 | prepareServerSettingsContext($config_vars); |
@@ -815,8 +838,9 @@ discard block |
||
815 | 838 | 'theme_dir' => $settings['default_theme_dir'], |
816 | 839 | ), |
817 | 840 | ); |
818 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
819 | - $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
841 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
842 | + $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
843 | + } |
|
820 | 844 | $smcFunc['db_free_result']($request); |
821 | 845 | |
822 | 846 | // This will be where we look |
@@ -828,14 +852,16 @@ discard block |
||
828 | 852 | // Check we have themes with a path and a name - just in case - and add the path. |
829 | 853 | foreach ($themes as $id => $data) |
830 | 854 | { |
831 | - if (count($data) != 2) |
|
832 | - unset($themes[$id]); |
|
833 | - elseif (is_dir($data['theme_dir'] . '/languages')) |
|
834 | - $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
855 | + if (count($data) != 2) { |
|
856 | + unset($themes[$id]); |
|
857 | + } elseif (is_dir($data['theme_dir'] . '/languages')) { |
|
858 | + $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
859 | + } |
|
835 | 860 | |
836 | 861 | // How about image directories? |
837 | - if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) |
|
838 | - $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
862 | + if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { |
|
863 | + $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
864 | + } |
|
839 | 865 | } |
840 | 866 | |
841 | 867 | $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; |
@@ -849,15 +875,17 @@ discard block |
||
849 | 875 | while ($entry = $dir->read()) |
850 | 876 | { |
851 | 877 | // We're only after the files for this language. |
852 | - if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) |
|
853 | - continue; |
|
878 | + if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) { |
|
879 | + continue; |
|
880 | + } |
|
854 | 881 | |
855 | - if (!isset($context['possible_files'][$theme])) |
|
856 | - $context['possible_files'][$theme] = array( |
|
882 | + if (!isset($context['possible_files'][$theme])) { |
|
883 | + $context['possible_files'][$theme] = array( |
|
857 | 884 | 'id' => $theme, |
858 | 885 | 'name' => $themes[$theme]['name'], |
859 | 886 | 'files' => array(), |
860 | 887 | ); |
888 | + } |
|
861 | 889 | |
862 | 890 | $context['possible_files'][$theme]['files'][] = array( |
863 | 891 | 'id' => $matches[1], |
@@ -886,31 +914,36 @@ discard block |
||
886 | 914 | { |
887 | 915 | $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; |
888 | 916 | $result = package_create_backup('backup_lang_' . $context['lang_id']); |
889 | - if (!$result) |
|
890 | - fatal_lang_error('could_not_language_backup', false); |
|
917 | + if (!$result) { |
|
918 | + fatal_lang_error('could_not_language_backup', false); |
|
919 | + } |
|
891 | 920 | } |
892 | 921 | |
893 | 922 | // Second, loop through the array to remove the files. |
894 | 923 | foreach ($lang_dirs as $curPath) |
895 | 924 | { |
896 | - foreach ($context['possible_files'][1]['files'] as $lang) |
|
897 | - if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
925 | + foreach ($context['possible_files'][1]['files'] as $lang) { |
|
926 | + if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
898 | 927 | unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); |
928 | + } |
|
899 | 929 | |
900 | 930 | // Check for the email template. |
901 | - if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) |
|
902 | - unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
931 | + if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { |
|
932 | + unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
933 | + } |
|
903 | 934 | } |
904 | 935 | |
905 | 936 | // Third, the agreement file. |
906 | - if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) |
|
907 | - unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
937 | + if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { |
|
938 | + unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
939 | + } |
|
908 | 940 | |
909 | 941 | // Fourth, a related images folder, if it exists... |
910 | - if (!empty($images_dirs)) |
|
911 | - foreach ($images_dirs as $curPath) |
|
942 | + if (!empty($images_dirs)) { |
|
943 | + foreach ($images_dirs as $curPath) |
|
912 | 944 | if (is_dir($curPath)) |
913 | 945 | deltree($curPath); |
946 | + } |
|
914 | 947 | |
915 | 948 | // Members can no longer use this language. |
916 | 949 | $smcFunc['db_query']('', ' |
@@ -995,8 +1028,9 @@ discard block |
||
995 | 1028 | foreach ($_POST['entry'] as $k => $v) |
996 | 1029 | { |
997 | 1030 | // Only try to save if it's changed! |
998 | - if ($_POST['entry'][$k] != $_POST['comp'][$k]) |
|
999 | - $save_strings[$k] = cleanLangString($v, false); |
|
1031 | + if ($_POST['entry'][$k] != $_POST['comp'][$k]) { |
|
1032 | + $save_strings[$k] = cleanLangString($v, false); |
|
1033 | + } |
|
1000 | 1034 | } |
1001 | 1035 | } |
1002 | 1036 | |
@@ -1030,12 +1064,13 @@ discard block |
||
1030 | 1064 | if ($multiline_cache) |
1031 | 1065 | { |
1032 | 1066 | preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches); |
1033 | - if (!empty($matches[3])) |
|
1034 | - $entries[$matches[2]] = array( |
|
1067 | + if (!empty($matches[3])) { |
|
1068 | + $entries[$matches[2]] = array( |
|
1035 | 1069 | 'type' => $matches[1], |
1036 | 1070 | 'full' => $matches[0], |
1037 | 1071 | 'entry' => $matches[3], |
1038 | 1072 | ); |
1073 | + } |
|
1039 | 1074 | } |
1040 | 1075 | |
1041 | 1076 | // These are the entries we can definitely save. |
@@ -1046,8 +1081,9 @@ discard block |
||
1046 | 1081 | { |
1047 | 1082 | // Ignore some things we set separately. |
1048 | 1083 | $ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl'); |
1049 | - if (in_array($entryKey, $ignore_files)) |
|
1050 | - continue; |
|
1084 | + if (in_array($entryKey, $ignore_files)) { |
|
1085 | + continue; |
|
1086 | + } |
|
1051 | 1087 | |
1052 | 1088 | // These are arrays that need breaking out. |
1053 | 1089 | $arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author'); |
@@ -1080,9 +1116,9 @@ discard block |
||
1080 | 1116 | { |
1081 | 1117 | $save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => '')); |
1082 | 1118 | $save_cache['enabled'] = true; |
1119 | + } else { |
|
1120 | + $save_cache['entries'][$cur_index] = $subValue; |
|
1083 | 1121 | } |
1084 | - else |
|
1085 | - $save_cache['entries'][$cur_index] = $subValue; |
|
1086 | 1122 | |
1087 | 1123 | $context['file_entries'][] = array( |
1088 | 1124 | 'key' => $entryKey . '-+- ' . $cur_index, |
@@ -1105,9 +1141,9 @@ discard block |
||
1105 | 1141 | { |
1106 | 1142 | $items[] = $k2 . ' => \'' . $v2 . '\''; |
1107 | 1143 | $cur_index = $k2; |
1144 | + } else { |
|
1145 | + $items[] = '\'' . $v2 . '\''; |
|
1108 | 1146 | } |
1109 | - else |
|
1110 | - $items[] = '\'' . $v2 . '\''; |
|
1111 | 1147 | |
1112 | 1148 | $cur_index++; |
1113 | 1149 | } |
@@ -1117,15 +1153,15 @@ discard block |
||
1117 | 1153 | 'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');', |
1118 | 1154 | ); |
1119 | 1155 | } |
1120 | - } |
|
1121 | - else |
|
1156 | + } else |
|
1122 | 1157 | { |
1123 | 1158 | // Saving? |
1124 | 1159 | if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry']) |
1125 | 1160 | { |
1126 | 1161 | // @todo Fix this properly. |
1127 | - if ($save_strings[$entryKey] == '') |
|
1128 | - $save_strings[$entryKey] = '\'\''; |
|
1162 | + if ($save_strings[$entryKey] == '') { |
|
1163 | + $save_strings[$entryKey] = '\'\''; |
|
1164 | + } |
|
1129 | 1165 | |
1130 | 1166 | // Set the new value. |
1131 | 1167 | $entryValue['entry'] = $save_strings[$entryKey]; |
@@ -1151,8 +1187,9 @@ discard block |
||
1151 | 1187 | checkSession(); |
1152 | 1188 | |
1153 | 1189 | $file_contents = implode('', file($current_file)); |
1154 | - foreach ($final_saves as $save) |
|
1155 | - $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
1190 | + foreach ($final_saves as $save) { |
|
1191 | + $file_contents = strtr($file_contents, array($save['find'] => $save['replace'])); |
|
1192 | + } |
|
1156 | 1193 | |
1157 | 1194 | // Save the actual changes. |
1158 | 1195 | $fp = fopen($current_file, 'w+'); |
@@ -1167,8 +1204,9 @@ discard block |
||
1167 | 1204 | } |
1168 | 1205 | |
1169 | 1206 | // If we saved, redirect. |
1170 | - if ($madeSave) |
|
1171 | - redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
1207 | + if ($madeSave) { |
|
1208 | + redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']); |
|
1209 | + } |
|
1172 | 1210 | |
1173 | 1211 | createToken('admin-mlang'); |
1174 | 1212 | } |
@@ -1200,8 +1238,9 @@ discard block |
||
1200 | 1238 | // Toggle the escape. |
1201 | 1239 | $is_escape = !$is_escape; |
1202 | 1240 | // If we're now escaped don't add this string. |
1203 | - if ($is_escape) |
|
1204 | - continue; |
|
1241 | + if ($is_escape) { |
|
1242 | + continue; |
|
1243 | + } |
|
1205 | 1244 | } |
1206 | 1245 | // Special case - parsed string with line break etc? |
1207 | 1246 | elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape) |
@@ -1218,11 +1257,13 @@ discard block |
||
1218 | 1257 | if ($in_string != 2 && ($in_string != 1 || !$is_escape)) |
1219 | 1258 | { |
1220 | 1259 | // Is it the end of a single quote string? |
1221 | - if ($in_string == 1) |
|
1222 | - $in_string = 0; |
|
1260 | + if ($in_string == 1) { |
|
1261 | + $in_string = 0; |
|
1262 | + } |
|
1223 | 1263 | // Otherwise it's the start! |
1224 | - else |
|
1225 | - $in_string = 1; |
|
1264 | + else { |
|
1265 | + $in_string = 1; |
|
1266 | + } |
|
1226 | 1267 | |
1227 | 1268 | // Don't actually include this character! |
1228 | 1269 | continue; |
@@ -1235,19 +1276,22 @@ discard block |
||
1235 | 1276 | if ($in_string != 1 && ($in_string != 2 || !$is_escape)) |
1236 | 1277 | { |
1237 | 1278 | // Is it the end of a double quote string? |
1238 | - if ($in_string == 2) |
|
1239 | - $in_string = 0; |
|
1279 | + if ($in_string == 2) { |
|
1280 | + $in_string = 0; |
|
1281 | + } |
|
1240 | 1282 | // Otherwise it's the start! |
1241 | - else |
|
1242 | - $in_string = 2; |
|
1283 | + else { |
|
1284 | + $in_string = 2; |
|
1285 | + } |
|
1243 | 1286 | |
1244 | 1287 | // Don't actually include this character! |
1245 | 1288 | continue; |
1246 | 1289 | } |
1247 | 1290 | } |
1248 | 1291 | // A join/space outside of a string is simply removed. |
1249 | - elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) |
|
1250 | - continue; |
|
1292 | + elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) { |
|
1293 | + continue; |
|
1294 | + } |
|
1251 | 1295 | // Start of a variable? |
1252 | 1296 | elseif ($in_string == 0 && $string{$i} == '$') |
1253 | 1297 | { |
@@ -1281,8 +1325,7 @@ discard block |
||
1281 | 1325 | |
1282 | 1326 | // Unhtml then rehtml the whole thing! |
1283 | 1327 | $new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string)); |
1284 | - } |
|
1285 | - else |
|
1328 | + } else |
|
1286 | 1329 | { |
1287 | 1330 | // Keep track of what we're doing... |
1288 | 1331 | $in_string = 0; |
@@ -1311,10 +1354,11 @@ discard block |
||
1311 | 1354 | preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches); |
1312 | 1355 | if (!empty($matches[1])) |
1313 | 1356 | { |
1314 | - if ($in_string == 1) |
|
1315 | - $new_string .= '\' . '; |
|
1316 | - elseif ($new_string) |
|
1317 | - $new_string .= ' . '; |
|
1357 | + if ($in_string == 1) { |
|
1358 | + $new_string .= '\' . '; |
|
1359 | + } elseif ($new_string) { |
|
1360 | + $new_string .= ' . '; |
|
1361 | + } |
|
1318 | 1362 | |
1319 | 1363 | $new_string .= $matches[1]; |
1320 | 1364 | $i += strlen($matches[1]) + 3; |
@@ -1327,8 +1371,9 @@ discard block |
||
1327 | 1371 | elseif ($string{$i} == '<') |
1328 | 1372 | { |
1329 | 1373 | // Probably HTML? |
1330 | - if ($string{$i + 1} != ' ') |
|
1331 | - $in_html = true; |
|
1374 | + if ($string{$i + 1} != ' ') { |
|
1375 | + $in_html = true; |
|
1376 | + } |
|
1332 | 1377 | // Assume we need an entity... |
1333 | 1378 | else |
1334 | 1379 | { |
@@ -1340,8 +1385,9 @@ discard block |
||
1340 | 1385 | elseif ($string{$i} == '>') |
1341 | 1386 | { |
1342 | 1387 | // Will it be HTML? |
1343 | - if ($in_html) |
|
1344 | - $in_html = false; |
|
1388 | + if ($in_html) { |
|
1389 | + $in_html = false; |
|
1390 | + } |
|
1345 | 1391 | // Otherwise we need an entity... |
1346 | 1392 | else |
1347 | 1393 | { |
@@ -1350,8 +1396,9 @@ discard block |
||
1350 | 1396 | } |
1351 | 1397 | } |
1352 | 1398 | // Is it a slash? If so escape it... |
1353 | - if ($string{$i} == '\\') |
|
1354 | - $new_string .= '\\'; |
|
1399 | + if ($string{$i} == '\\') { |
|
1400 | + $new_string .= '\\'; |
|
1401 | + } |
|
1355 | 1402 | // The infamous double quote? |
1356 | 1403 | elseif ($string{$i} == '"') |
1357 | 1404 | { |
@@ -1374,10 +1421,11 @@ discard block |
||
1374 | 1421 | } |
1375 | 1422 | |
1376 | 1423 | // If we ended as a string then close it off. |
1377 | - if ($in_string == 1) |
|
1378 | - $new_string .= '\''; |
|
1379 | - elseif ($in_string == 2) |
|
1380 | - $new_string .= '"'; |
|
1424 | + if ($in_string == 1) { |
|
1425 | + $new_string .= '\''; |
|
1426 | + } elseif ($in_string == 2) { |
|
1427 | + $new_string .= '"'; |
|
1428 | + } |
|
1381 | 1429 | } |
1382 | 1430 | |
1383 | 1431 | return $new_string; |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
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 | * This function allows to move a topic, making sure to ask the moderator |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | { |
33 | 34 | global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
34 | 35 | |
35 | - if (empty($topic)) |
|
36 | - fatal_lang_error('no_access', false); |
|
36 | + if (empty($topic)) { |
|
37 | + fatal_lang_error('no_access', false); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $request = $smcFunc['db_query']('', ' |
39 | 41 | SELECT t.id_member_started, ms.subject, t.approved |
@@ -49,8 +51,9 @@ discard block |
||
49 | 51 | $smcFunc['db_free_result']($request); |
50 | 52 | |
51 | 53 | // Can they see it - if not approved? |
52 | - if ($modSettings['postmod_active'] && !$context['is_approved']) |
|
53 | - isAllowedTo('approve_posts'); |
|
54 | + if ($modSettings['postmod_active'] && !$context['is_approved']) { |
|
55 | + isAllowedTo('approve_posts'); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | // Permission check! |
56 | 59 | // @todo |
@@ -59,9 +62,9 @@ discard block |
||
59 | 62 | if ($id_member_started == $user_info['id']) |
60 | 63 | { |
61 | 64 | isAllowedTo('move_own'); |
65 | + } else { |
|
66 | + isAllowedTo('move_any'); |
|
62 | 67 | } |
63 | - else |
|
64 | - isAllowedTo('move_any'); |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | $context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
@@ -83,11 +86,13 @@ discard block |
||
83 | 86 | 'not_redirection' => true, |
84 | 87 | ); |
85 | 88 | |
86 | - if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
|
87 | - $options['selected_board'] = $_SESSION['move_to_topic']; |
|
89 | + if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) { |
|
90 | + $options['selected_board'] = $_SESSION['move_to_topic']; |
|
91 | + } |
|
88 | 92 | |
89 | - if (!$context['move_any']) |
|
90 | - $options['included_boards'] = $boards; |
|
93 | + if (!$context['move_any']) { |
|
94 | + $options['included_boards'] = $boards; |
|
95 | + } |
|
91 | 96 | |
92 | 97 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
93 | 98 | $context['categories'] = getBoardList($options); |
@@ -138,12 +143,14 @@ discard block |
||
138 | 143 | global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context; |
139 | 144 | global $board, $language, $user_info, $smcFunc; |
140 | 145 | |
141 | - if (empty($topic)) |
|
142 | - fatal_lang_error('no_access', false); |
|
146 | + if (empty($topic)) { |
|
147 | + fatal_lang_error('no_access', false); |
|
148 | + } |
|
143 | 149 | |
144 | 150 | // You can't choose to have a redirection topic and use an empty reason. |
145 | - if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
|
146 | - fatal_lang_error('movetopic_no_reason', false); |
|
151 | + if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) { |
|
152 | + fatal_lang_error('movetopic_no_reason', false); |
|
153 | + } |
|
147 | 154 | |
148 | 155 | moveTopicConcurrence(); |
149 | 156 | |
@@ -163,16 +170,18 @@ discard block |
||
163 | 170 | $smcFunc['db_free_result']($request); |
164 | 171 | |
165 | 172 | // Can they see it? |
166 | - if (!$context['is_approved']) |
|
167 | - isAllowedTo('approve_posts'); |
|
173 | + if (!$context['is_approved']) { |
|
174 | + isAllowedTo('approve_posts'); |
|
175 | + } |
|
168 | 176 | |
169 | 177 | // Can they move topics on this board? |
170 | 178 | if (!allowedTo('move_any')) |
171 | 179 | { |
172 | - if ($id_member_started == $user_info['id']) |
|
173 | - isAllowedTo('move_own'); |
|
174 | - else |
|
175 | - isAllowedTo('move_any'); |
|
180 | + if ($id_member_started == $user_info['id']) { |
|
181 | + isAllowedTo('move_own'); |
|
182 | + } else { |
|
183 | + isAllowedTo('move_any'); |
|
184 | + } |
|
176 | 185 | } |
177 | 186 | |
178 | 187 | checkSession(); |
@@ -197,8 +206,9 @@ discard block |
||
197 | 206 | 'blank_redirect' => '', |
198 | 207 | ) |
199 | 208 | ); |
200 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
201 | - fatal_lang_error('no_board'); |
|
209 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
210 | + fatal_lang_error('no_board'); |
|
211 | + } |
|
202 | 212 | list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
203 | 213 | $smcFunc['db_free_result']($request); |
204 | 214 | |
@@ -210,8 +220,9 @@ discard block |
||
210 | 220 | { |
211 | 221 | $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
212 | 222 | // Keep checking the length. |
213 | - if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
|
214 | - $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
223 | + if ($smcFunc['strlen']($_POST['custom_subject']) > 100) { |
|
224 | + $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
225 | + } |
|
215 | 226 | |
216 | 227 | // If it's still valid move onwards and upwards. |
217 | 228 | if ($_POST['custom_subject'] != '') |
@@ -221,9 +232,9 @@ discard block |
||
221 | 232 | // Get a response prefix, but in the forum's default language. |
222 | 233 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
223 | 234 | { |
224 | - if ($language === $user_info['language']) |
|
225 | - $context['response_prefix'] = $txt['response_prefix']; |
|
226 | - else |
|
235 | + if ($language === $user_info['language']) { |
|
236 | + $context['response_prefix'] = $txt['response_prefix']; |
|
237 | + } else |
|
227 | 238 | { |
228 | 239 | loadLanguage('index', $language, false); |
229 | 240 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -263,8 +274,9 @@ discard block |
||
263 | 274 | if (isset($_POST['postRedirect'])) |
264 | 275 | { |
265 | 276 | // Should be in the boardwide language. |
266 | - if ($user_info['language'] != $language) |
|
267 | - loadLanguage('index', $language); |
|
277 | + if ($user_info['language'] != $language) { |
|
278 | + loadLanguage('index', $language); |
|
279 | + } |
|
268 | 280 | |
269 | 281 | $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
270 | 282 | preparsecode($_POST['reason']); |
@@ -328,8 +340,9 @@ discard block |
||
328 | 340 | $posters = array(); |
329 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
330 | 342 | { |
331 | - if (!isset($posters[$row['id_member']])) |
|
332 | - $posters[$row['id_member']] = 0; |
|
343 | + if (!isset($posters[$row['id_member']])) { |
|
344 | + $posters[$row['id_member']] = 0; |
|
345 | + } |
|
333 | 346 | |
334 | 347 | $posters[$row['id_member']]++; |
335 | 348 | } |
@@ -338,11 +351,13 @@ discard block |
||
338 | 351 | foreach ($posters as $id_member => $posts) |
339 | 352 | { |
340 | 353 | // The board we're moving from counted posts, but not to. |
341 | - if (empty($pcounter_from)) |
|
342 | - updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
354 | + if (empty($pcounter_from)) { |
|
355 | + updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
356 | + } |
|
343 | 357 | // The reverse: from didn't, to did. |
344 | - else |
|
345 | - updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
358 | + else { |
|
359 | + updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
360 | + } |
|
346 | 361 | } |
347 | 362 | } |
348 | 363 | |
@@ -350,17 +365,19 @@ discard block |
||
350 | 365 | moveTopics($topic, $_POST['toboard']); |
351 | 366 | |
352 | 367 | // Log that they moved this topic. |
353 | - if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
|
354 | - logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
368 | + if (!allowedTo('move_own') || $id_member_started != $user_info['id']) { |
|
369 | + logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
370 | + } |
|
355 | 371 | // Notify people that this topic has been moved? |
356 | 372 | sendNotifications($topic, 'move'); |
357 | 373 | |
358 | 374 | // Why not go back to the original board in case they want to keep moving? |
359 | - if (!isset($_REQUEST['goback'])) |
|
360 | - redirectexit('board=' . $board . '.0'); |
|
361 | - else |
|
362 | - redirectexit('topic=' . $topic . '.0'); |
|
363 | -} |
|
375 | + if (!isset($_REQUEST['goback'])) { |
|
376 | + redirectexit('board=' . $board . '.0'); |
|
377 | + } else { |
|
378 | + redirectexit('topic=' . $topic . '.0'); |
|
379 | + } |
|
380 | + } |
|
364 | 381 | |
365 | 382 | /** |
366 | 383 | * Moves one or more topics to a specific board. (doesn't check permissions.) |
@@ -376,18 +393,21 @@ discard block |
||
376 | 393 | global $sourcedir, $user_info, $modSettings, $smcFunc; |
377 | 394 | |
378 | 395 | // Empty array? |
379 | - if (empty($topics)) |
|
380 | - return; |
|
396 | + if (empty($topics)) { |
|
397 | + return; |
|
398 | + } |
|
381 | 399 | |
382 | 400 | // Only a single topic. |
383 | - if (is_numeric($topics)) |
|
384 | - $topics = array($topics); |
|
401 | + if (is_numeric($topics)) { |
|
402 | + $topics = array($topics); |
|
403 | + } |
|
385 | 404 | |
386 | 405 | $fromBoards = array(); |
387 | 406 | |
388 | 407 | // Destination board empty or equal to 0? |
389 | - if (empty($toBoard)) |
|
390 | - return; |
|
408 | + if (empty($toBoard)) { |
|
409 | + return; |
|
410 | + } |
|
391 | 411 | |
392 | 412 | // Are we moving to the recycle board? |
393 | 413 | $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
@@ -395,8 +415,9 @@ discard block |
||
395 | 415 | // Callback for search APIs to do their thing |
396 | 416 | require_once($sourcedir . '/Search.php'); |
397 | 417 | $searchAPI = findSearchAPI(); |
398 | - if ($searchAPI->supportsMethod('topicsMoved')) |
|
399 | - $searchAPI->topicsMoved($topics, $toBoard); |
|
418 | + if ($searchAPI->supportsMethod('topicsMoved')) { |
|
419 | + $searchAPI->topicsMoved($topics, $toBoard); |
|
420 | + } |
|
400 | 421 | |
401 | 422 | // Determine the source boards... |
402 | 423 | $request = $smcFunc['db_query']('', ' |
@@ -410,8 +431,9 @@ discard block |
||
410 | 431 | ) |
411 | 432 | ); |
412 | 433 | // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
413 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
414 | - return; |
|
434 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
435 | + return; |
|
436 | + } |
|
415 | 437 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
416 | 438 | { |
417 | 439 | if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
@@ -429,10 +451,11 @@ discard block |
||
429 | 451 | $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
430 | 452 | |
431 | 453 | // Add the topics to the right type. |
432 | - if ($row['approved']) |
|
433 | - $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
434 | - else |
|
435 | - $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
454 | + if ($row['approved']) { |
|
455 | + $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
456 | + } else { |
|
457 | + $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
458 | + } |
|
436 | 459 | } |
437 | 460 | $smcFunc['db_free_result']($request); |
438 | 461 | |
@@ -558,13 +581,14 @@ discard block |
||
558 | 581 | ) |
559 | 582 | ); |
560 | 583 | $approval_msgs = array(); |
561 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
562 | - $approval_msgs[] = $row['id_msg']; |
|
584 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
585 | + $approval_msgs[] = $row['id_msg']; |
|
586 | + } |
|
563 | 587 | $smcFunc['db_free_result']($request); |
564 | 588 | |
565 | 589 | // Empty the approval queue for these, as we're going to approve them next. |
566 | - if (!empty($approval_msgs)) |
|
567 | - $smcFunc['db_query']('', ' |
|
590 | + if (!empty($approval_msgs)) { |
|
591 | + $smcFunc['db_query']('', ' |
|
568 | 592 | DELETE FROM {db_prefix}approval_queue |
569 | 593 | WHERE id_msg IN ({array_int:message_list}) |
570 | 594 | AND id_attach = {int:id_attach}', |
@@ -573,6 +597,7 @@ discard block |
||
573 | 597 | 'id_attach' => 0, |
574 | 598 | ) |
575 | 599 | ); |
600 | + } |
|
576 | 601 | |
577 | 602 | // Get all the current max and mins. |
578 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -606,8 +631,8 @@ discard block |
||
606 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
607 | 632 | { |
608 | 633 | // If not, update. |
609 | - if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
|
610 | - $smcFunc['db_query']('', ' |
|
634 | + if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) { |
|
635 | + $smcFunc['db_query']('', ' |
|
611 | 636 | UPDATE {db_prefix}topics |
612 | 637 | SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
613 | 638 | WHERE id_topic = {int:selected_topic}', |
@@ -617,6 +642,7 @@ discard block |
||
617 | 642 | 'selected_topic' => $row['id_topic'], |
618 | 643 | ) |
619 | 644 | ); |
645 | + } |
|
620 | 646 | } |
621 | 647 | $smcFunc['db_free_result']($request); |
622 | 648 | } |
@@ -675,9 +701,10 @@ discard block |
||
675 | 701 | } |
676 | 702 | |
677 | 703 | // Update the cache? |
678 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
|
679 | - foreach ($topics as $topic_id) |
|
704 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) { |
|
705 | + foreach ($topics as $topic_id) |
|
680 | 706 | cache_put_data('topic_board-' . $topic_id, null, 120); |
707 | + } |
|
681 | 708 | |
682 | 709 | require_once($sourcedir . '/Subs-Post.php'); |
683 | 710 | |
@@ -701,15 +728,17 @@ discard block |
||
701 | 728 | { |
702 | 729 | global $board, $topic, $smcFunc, $scripturl; |
703 | 730 | |
704 | - if (isset($_GET['current_board'])) |
|
705 | - $move_from = (int) $_GET['current_board']; |
|
731 | + if (isset($_GET['current_board'])) { |
|
732 | + $move_from = (int) $_GET['current_board']; |
|
733 | + } |
|
706 | 734 | |
707 | - if (empty($move_from) || empty($board) || empty($topic)) |
|
708 | - return true; |
|
735 | + if (empty($move_from) || empty($board) || empty($topic)) { |
|
736 | + return true; |
|
737 | + } |
|
709 | 738 | |
710 | - if ($move_from == $board) |
|
711 | - return true; |
|
712 | - else |
|
739 | + if ($move_from == $board) { |
|
740 | + return true; |
|
741 | + } else |
|
713 | 742 | { |
714 | 743 | $request = $smcFunc['db_query']('', ' |
715 | 744 | SELECT m.subject, b.name |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | * @version 2.1 Beta 3 |
18 | 18 | */ |
19 | 19 | |
20 | -if (!defined('SMF')) |
|
20 | +if (!defined('SMF')) { |
|
21 | 21 | die('No direct access...'); |
22 | +} |
|
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Attempt to start the session, unless it already has been. |
@@ -38,8 +39,9 @@ discard block |
||
38 | 39 | { |
39 | 40 | $parsed_url = parse_url($boardurl); |
40 | 41 | |
41 | - if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
42 | - @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
42 | + if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
43 | + @ini_set('session.cookie_domain', '.' . $parts[1]); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | // @todo Set the session cookie path? |
45 | 47 | |
@@ -47,8 +49,9 @@ discard block |
||
47 | 49 | if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '') |
48 | 50 | { |
49 | 51 | // Attempt to end the already-started session. |
50 | - if (ini_get('session.auto_start') == 1) |
|
51 | - session_write_close(); |
|
52 | + if (ini_get('session.auto_start') == 1) { |
|
53 | + session_write_close(); |
|
54 | + } |
|
52 | 55 | |
53 | 56 | // This is here to stop people from using bad junky PHPSESSIDs. |
54 | 57 | if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()])) |
@@ -65,19 +68,21 @@ discard block |
||
65 | 68 | @ini_set('session.serialize_handler', 'php'); |
66 | 69 | session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC'); |
67 | 70 | @ini_set('session.gc_probability', '1'); |
71 | + } elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) { |
|
72 | + @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
68 | 73 | } |
69 | - elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) |
|
70 | - @ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60)); |
|
71 | 74 | |
72 | 75 | // Use cache setting sessions? |
73 | - if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') |
|
74 | - call_integration_hook('integrate_session_handlers'); |
|
76 | + if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') { |
|
77 | + call_integration_hook('integrate_session_handlers'); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | session_start(); |
77 | 81 | |
78 | 82 | // Change it so the cache settings are a little looser than default. |
79 | - if (!empty($modSettings['databaseSession_loose'])) |
|
80 | - header('Cache-Control: private'); |
|
83 | + if (!empty($modSettings['databaseSession_loose'])) { |
|
84 | + header('Cache-Control: private'); |
|
85 | + } |
|
81 | 86 | } |
82 | 87 | |
83 | 88 | // Set the randomly generated code. |
@@ -123,8 +128,9 @@ discard block |
||
123 | 128 | { |
124 | 129 | global $smcFunc; |
125 | 130 | |
126 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
127 | - return ''; |
|
131 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
132 | + return ''; |
|
133 | + } |
|
128 | 134 | |
129 | 135 | // Look for it in the database. |
130 | 136 | $result = $smcFunc['db_query']('', ' |
@@ -153,8 +159,9 @@ discard block |
||
153 | 159 | { |
154 | 160 | global $smcFunc; |
155 | 161 | |
156 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
157 | - return false; |
|
162 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
163 | + return false; |
|
164 | + } |
|
158 | 165 | |
159 | 166 | // First try to update an existing row... |
160 | 167 | $smcFunc['db_query']('', ' |
@@ -169,13 +176,14 @@ discard block |
||
169 | 176 | ); |
170 | 177 | |
171 | 178 | // If that didn't work, try inserting a new one. |
172 | - if ($smcFunc['db_affected_rows']() == 0) |
|
173 | - $smcFunc['db_insert']('ignore', |
|
179 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
180 | + $smcFunc['db_insert']('ignore', |
|
174 | 181 | '{db_prefix}sessions', |
175 | 182 | array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), |
176 | 183 | array($session_id, $data, time()), |
177 | 184 | array('session_id') |
178 | 185 | ); |
186 | + } |
|
179 | 187 | |
180 | 188 | return ($smcFunc['db_affected_rows']() == 0 ? false : true); |
181 | 189 | } |
@@ -190,8 +198,9 @@ discard block |
||
190 | 198 | { |
191 | 199 | global $smcFunc; |
192 | 200 | |
193 | - if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) |
|
194 | - return false; |
|
201 | + if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) { |
|
202 | + return false; |
|
203 | + } |
|
195 | 204 | |
196 | 205 | // Just delete the row... |
197 | 206 | $smcFunc['db_query']('', ' |
@@ -217,8 +226,9 @@ discard block |
||
217 | 226 | global $modSettings, $smcFunc; |
218 | 227 | |
219 | 228 | // Just set to the default or lower? Ignore it for a higher value. (hopefully) |
220 | - if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) |
|
221 | - $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
229 | + if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) { |
|
230 | + $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); |
|
231 | + } |
|
222 | 232 | |
223 | 233 | // Clean up after yerself ;). |
224 | 234 | $smcFunc['db_query']('', ' |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Shows an avatar based on $_GET['attach'] |
@@ -35,11 +36,11 @@ discard block |
||
35 | 36 | |
36 | 37 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
37 | 38 | { |
38 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
39 | - $modSettings['enableCompressedOutput'] = 0; |
|
40 | - |
|
41 | - else |
|
42 | - ob_start('ob_gzhandler'); |
|
39 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
40 | + $modSettings['enableCompressedOutput'] = 0; |
|
41 | + } else { |
|
42 | + ob_start('ob_gzhandler'); |
|
43 | + } |
|
43 | 44 | } |
44 | 45 | |
45 | 46 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -71,8 +72,9 @@ discard block |
||
71 | 72 | } |
72 | 73 | |
73 | 74 | // Use cache when possible. |
74 | - if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
75 | - list($file, $thumbFile) = $cache; |
|
75 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) { |
|
76 | + list($file, $thumbFile) = $cache; |
|
77 | + } |
|
76 | 78 | |
77 | 79 | // Get the info from the DB. |
78 | 80 | if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -80,10 +82,9 @@ discard block |
||
80 | 82 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
81 | 83 | $attachRequest = null; |
82 | 84 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
83 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
84 | - $request = $attachRequest; |
|
85 | - |
|
86 | - else |
|
85 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
86 | + $request = $attachRequest; |
|
87 | + } else |
|
87 | 88 | { |
88 | 89 | // Make sure this attachment is on this board and load its info while we are at it. |
89 | 90 | $request = $smcFunc['db_query']('', ' |
@@ -176,13 +177,14 @@ discard block |
||
176 | 177 | } |
177 | 178 | |
178 | 179 | // Cache it. |
179 | - if (!empty($file) || !empty($thumbFile)) |
|
180 | - cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
180 | + if (!empty($file) || !empty($thumbFile)) { |
|
181 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
182 | + } |
|
181 | 183 | } |
182 | 184 | |
183 | 185 | // Update the download counter (unless it's a thumbnail). |
184 | - if ($file['attachment_type'] != 3 && empty($showThumb)) |
|
185 | - $smcFunc['db_query']('attach_download_increase', ' |
|
186 | + if ($file['attachment_type'] != 3 && empty($showThumb)) { |
|
187 | + $smcFunc['db_query']('attach_download_increase', ' |
|
186 | 188 | UPDATE LOW_PRIORITY {db_prefix}attachments |
187 | 189 | SET downloads = downloads + 1 |
188 | 190 | WHERE id_attach = {int:id_attach}', |
@@ -190,10 +192,12 @@ discard block |
||
190 | 192 | 'id_attach' => $attachId, |
191 | 193 | ) |
192 | 194 | ); |
195 | + } |
|
193 | 196 | |
194 | 197 | // Replace the normal file with its thumbnail if it has one! |
195 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
196 | - $file = $thumbFile; |
|
198 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
199 | + $file = $thumbFile; |
|
200 | + } |
|
197 | 201 | |
198 | 202 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
199 | 203 | if (!file_exists($file['filePath'])) |
@@ -232,8 +236,9 @@ discard block |
||
232 | 236 | // Send the attachment headers. |
233 | 237 | header('Pragma: '); |
234 | 238 | |
235 | - if (!isBrowser('gecko')) |
|
236 | - header('Content-Transfer-Encoding: binary'); |
|
239 | + if (!isBrowser('gecko')) { |
|
240 | + header('Content-Transfer-Encoding: binary'); |
|
241 | + } |
|
237 | 242 | |
238 | 243 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
239 | 244 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -242,18 +247,19 @@ discard block |
||
242 | 247 | header('ETag: ' . $eTag); |
243 | 248 | |
244 | 249 | // Make sure the mime type warrants an inline display. |
245 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
246 | - unset($_REQUEST['image']); |
|
250 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
251 | + unset($_REQUEST['image']); |
|
252 | + } |
|
247 | 253 | |
248 | 254 | // Does this have a mime type? |
249 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
250 | - header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
251 | - |
|
252 | - else |
|
255 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
256 | + header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
257 | + } else |
|
253 | 258 | { |
254 | 259 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
255 | - if (isset($_REQUEST['image'])) |
|
256 | - unset($_REQUEST['image']); |
|
260 | + if (isset($_REQUEST['image'])) { |
|
261 | + unset($_REQUEST['image']); |
|
262 | + } |
|
257 | 263 | } |
258 | 264 | |
259 | 265 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -261,24 +267,22 @@ discard block |
||
261 | 267 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
262 | 268 | |
263 | 269 | // Different browsers like different standards... |
264 | - if (isBrowser('firefox')) |
|
265 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
266 | - |
|
267 | - elseif (isBrowser('opera')) |
|
268 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
269 | - |
|
270 | - elseif (isBrowser('ie')) |
|
271 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
272 | - |
|
273 | - else |
|
274 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
270 | + if (isBrowser('firefox')) { |
|
271 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
272 | + } elseif (isBrowser('opera')) { |
|
273 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
274 | + } elseif (isBrowser('ie')) { |
|
275 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
276 | + } else { |
|
277 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
278 | + } |
|
275 | 279 | |
276 | 280 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
277 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
278 | - header('Cache-Control: no-cache'); |
|
279 | - |
|
280 | - else |
|
281 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
281 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
282 | + header('Cache-Control: no-cache'); |
|
283 | + } else { |
|
284 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
285 | + } |
|
282 | 286 | |
283 | 287 | header('Content-Length: ' . filesize($file['filePath'])); |
284 | 288 | |
@@ -289,8 +293,9 @@ discard block |
||
289 | 293 | if (filesize($file['filePath']) > 4194304) |
290 | 294 | { |
291 | 295 | // Forcibly end any output buffering going on. |
292 | - while (@ob_get_level() > 0) |
|
293 | - @ob_end_clean(); |
|
296 | + while (@ob_get_level() > 0) { |
|
297 | + @ob_end_clean(); |
|
298 | + } |
|
294 | 299 | |
295 | 300 | $fp = fopen($file['filePath'], 'rb'); |
296 | 301 | while (!feof($fp)) |
@@ -302,8 +307,9 @@ discard block |
||
302 | 307 | } |
303 | 308 | |
304 | 309 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
305 | - elseif (@readfile($file['filePath']) === null) |
|
306 | - echo file_get_contents($file['filePath']); |
|
310 | + elseif (@readfile($file['filePath']) === null) { |
|
311 | + echo file_get_contents($file['filePath']); |
|
312 | + } |
|
307 | 313 | |
308 | 314 | die(); |
309 | 315 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
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 | * Mark a board or multiple boards read. |
@@ -28,14 +29,16 @@ discard block |
||
28 | 29 | global $user_info, $modSettings, $smcFunc; |
29 | 30 | |
30 | 31 | // Force $boards to be an array. |
31 | - if (!is_array($boards)) |
|
32 | - $boards = array($boards); |
|
33 | - else |
|
34 | - $boards = array_unique($boards); |
|
32 | + if (!is_array($boards)) { |
|
33 | + $boards = array($boards); |
|
34 | + } else { |
|
35 | + $boards = array_unique($boards); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // No boards, nothing to mark as read. |
37 | - if (empty($boards)) |
|
38 | - return; |
|
39 | + if (empty($boards)) { |
|
40 | + return; |
|
41 | + } |
|
39 | 42 | |
40 | 43 | // Allow the user to mark a board as unread. |
41 | 44 | if ($unread) |
@@ -65,8 +68,9 @@ discard block |
||
65 | 68 | else |
66 | 69 | { |
67 | 70 | $markRead = array(); |
68 | - foreach ($boards as $board) |
|
69 | - $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board); |
|
71 | + foreach ($boards as $board) { |
|
72 | + $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $board); |
|
73 | + } |
|
70 | 74 | |
71 | 75 | // Update log_mark_read and log_boards. |
72 | 76 | $smcFunc['db_insert']('replace', |
@@ -99,8 +103,9 @@ discard block |
||
99 | 103 | list ($lowest_topic) = $smcFunc['db_fetch_row']($result); |
100 | 104 | $smcFunc['db_free_result']($result); |
101 | 105 | |
102 | - if (empty($lowest_topic)) |
|
103 | - return; |
|
106 | + if (empty($lowest_topic)) { |
|
107 | + return; |
|
108 | + } |
|
104 | 109 | |
105 | 110 | // @todo SLOW This query seems to eat it sometimes. |
106 | 111 | $result = $smcFunc['db_query']('', ' |
@@ -118,12 +123,13 @@ discard block |
||
118 | 123 | ) |
119 | 124 | ); |
120 | 125 | $topics = array(); |
121 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
122 | - $topics[] = $row['id_topic']; |
|
126 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
127 | + $topics[] = $row['id_topic']; |
|
128 | + } |
|
123 | 129 | $smcFunc['db_free_result']($result); |
124 | 130 | |
125 | - if (!empty($topics)) |
|
126 | - $smcFunc['db_query']('', ' |
|
131 | + if (!empty($topics)) { |
|
132 | + $smcFunc['db_query']('', ' |
|
127 | 133 | DELETE FROM {db_prefix}log_topics |
128 | 134 | WHERE id_member = {int:current_member} |
129 | 135 | AND id_topic IN ({array_int:topic_list})', |
@@ -132,7 +138,8 @@ discard block |
||
132 | 138 | 'topic_list' => $topics, |
133 | 139 | ) |
134 | 140 | ); |
135 | -} |
|
141 | + } |
|
142 | + } |
|
136 | 143 | |
137 | 144 | /** |
138 | 145 | * Mark one or more boards as read. |
@@ -157,23 +164,26 @@ discard block |
||
157 | 164 | ) |
158 | 165 | ); |
159 | 166 | $boards = array(); |
160 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
161 | - $boards[] = $row['id_board']; |
|
167 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
168 | + $boards[] = $row['id_board']; |
|
169 | + } |
|
162 | 170 | $smcFunc['db_free_result']($result); |
163 | 171 | |
164 | - if (!empty($boards)) |
|
165 | - markBoardsRead($boards, isset($_REQUEST['unread'])); |
|
172 | + if (!empty($boards)) { |
|
173 | + markBoardsRead($boards, isset($_REQUEST['unread'])); |
|
174 | + } |
|
166 | 175 | |
167 | 176 | $_SESSION['id_msg_last_visit'] = $modSettings['maxMsgID']; |
168 | - if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) |
|
169 | - redirectexit('action=unread'); |
|
177 | + if (!empty($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'action=unread') !== false) { |
|
178 | + redirectexit('action=unread'); |
|
179 | + } |
|
170 | 180 | |
171 | - if (isset($_SESSION['topicseen_cache'])) |
|
172 | - $_SESSION['topicseen_cache'] = array(); |
|
181 | + if (isset($_SESSION['topicseen_cache'])) { |
|
182 | + $_SESSION['topicseen_cache'] = array(); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | redirectexit(); |
175 | - } |
|
176 | - elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies') |
|
186 | + } elseif (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'unreadreplies') |
|
177 | 187 | { |
178 | 188 | // Make sure all the topics are integers! |
179 | 189 | $topics = array_map('intval', explode('-', $_REQUEST['topics'])); |
@@ -189,13 +199,15 @@ discard block |
||
189 | 199 | ) |
190 | 200 | ); |
191 | 201 | $logged_topics = array(); |
192 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
193 | - $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
202 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
203 | + $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
204 | + } |
|
194 | 205 | $smcFunc['db_free_result']($request); |
195 | 206 | |
196 | 207 | $markRead = array(); |
197 | - foreach ($topics as $id_topic) |
|
198 | - $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
208 | + foreach ($topics as $id_topic) { |
|
209 | + $markRead[] = array($modSettings['maxMsgID'], $user_info['id'], $id_topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
210 | + } |
|
199 | 211 | |
200 | 212 | $smcFunc['db_insert']('replace', |
201 | 213 | '{db_prefix}log_topics', |
@@ -204,8 +216,9 @@ discard block |
||
204 | 216 | array('id_member', 'id_topic') |
205 | 217 | ); |
206 | 218 | |
207 | - if (isset($_SESSION['topicseen_cache'])) |
|
208 | - $_SESSION['topicseen_cache'] = array(); |
|
219 | + if (isset($_SESSION['topicseen_cache'])) { |
|
220 | + $_SESSION['topicseen_cache'] = array(); |
|
221 | + } |
|
209 | 222 | |
210 | 223 | redirectexit('action=unreadreplies'); |
211 | 224 | } |
@@ -230,11 +243,13 @@ discard block |
||
230 | 243 | if (!empty($_GET['t'])) |
231 | 244 | { |
232 | 245 | // If they read the whole topic, go back to the beginning. |
233 | - if ($_GET['t'] >= $topicinfo['id_last_msg']) |
|
234 | - $earlyMsg = 0; |
|
246 | + if ($_GET['t'] >= $topicinfo['id_last_msg']) { |
|
247 | + $earlyMsg = 0; |
|
248 | + } |
|
235 | 249 | // If they want to mark the whole thing read, same. |
236 | - elseif ($_GET['t'] <= $topicinfo['id_first_msg']) |
|
237 | - $earlyMsg = 0; |
|
250 | + elseif ($_GET['t'] <= $topicinfo['id_first_msg']) { |
|
251 | + $earlyMsg = 0; |
|
252 | + } |
|
238 | 253 | // Otherwise, get the latest message before the named one. |
239 | 254 | else |
240 | 255 | { |
@@ -255,9 +270,9 @@ discard block |
||
255 | 270 | } |
256 | 271 | } |
257 | 272 | // Marking read from first page? That's the whole topic. |
258 | - elseif ($_REQUEST['start'] == 0) |
|
259 | - $earlyMsg = 0; |
|
260 | - else |
|
273 | + elseif ($_REQUEST['start'] == 0) { |
|
274 | + $earlyMsg = 0; |
|
275 | + } else |
|
261 | 276 | { |
262 | 277 | $result = $smcFunc['db_query']('', ' |
263 | 278 | SELECT id_msg |
@@ -285,8 +300,7 @@ discard block |
||
285 | 300 | ); |
286 | 301 | |
287 | 302 | redirectexit('board=' . $board . '.0'); |
288 | - } |
|
289 | - else |
|
303 | + } else |
|
290 | 304 | { |
291 | 305 | $categories = array(); |
292 | 306 | $boards = array(); |
@@ -294,17 +308,20 @@ discard block |
||
294 | 308 | if (isset($_REQUEST['c'])) |
295 | 309 | { |
296 | 310 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
297 | - foreach ($_REQUEST['c'] as $c) |
|
298 | - $categories[] = (int) $c; |
|
311 | + foreach ($_REQUEST['c'] as $c) { |
|
312 | + $categories[] = (int) $c; |
|
313 | + } |
|
299 | 314 | } |
300 | 315 | if (isset($_REQUEST['boards'])) |
301 | 316 | { |
302 | 317 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
303 | - foreach ($_REQUEST['boards'] as $b) |
|
304 | - $boards[] = (int) $b; |
|
318 | + foreach ($_REQUEST['boards'] as $b) { |
|
319 | + $boards[] = (int) $b; |
|
320 | + } |
|
321 | + } |
|
322 | + if (!empty($board)) { |
|
323 | + $boards[] = (int) $board; |
|
305 | 324 | } |
306 | - if (!empty($board)) |
|
307 | - $boards[] = (int) $board; |
|
308 | 325 | |
309 | 326 | if (isset($_REQUEST['children']) && !empty($boards)) |
310 | 327 | { |
@@ -324,9 +341,10 @@ discard block |
||
324 | 341 | 'board_list' => $boards, |
325 | 342 | ) |
326 | 343 | ); |
327 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
328 | - if (in_array($row['id_parent'], $boards)) |
|
344 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
345 | + if (in_array($row['id_parent'], $boards)) |
|
329 | 346 | $boards[] = $row['id_board']; |
347 | + } |
|
330 | 348 | $smcFunc['db_free_result']($request); |
331 | 349 | } |
332 | 350 | |
@@ -343,8 +361,9 @@ discard block |
||
343 | 361 | $clauseParameters['board_list'] = $boards; |
344 | 362 | } |
345 | 363 | |
346 | - if (empty($clauses)) |
|
347 | - redirectexit(); |
|
364 | + if (empty($clauses)) { |
|
365 | + redirectexit(); |
|
366 | + } |
|
348 | 367 | |
349 | 368 | $request = $smcFunc['db_query']('', ' |
350 | 369 | SELECT b.id_board |
@@ -355,19 +374,22 @@ discard block |
||
355 | 374 | )) |
356 | 375 | ); |
357 | 376 | $boards = array(); |
358 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
359 | - $boards[] = $row['id_board']; |
|
377 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
378 | + $boards[] = $row['id_board']; |
|
379 | + } |
|
360 | 380 | $smcFunc['db_free_result']($request); |
361 | 381 | |
362 | - if (empty($boards)) |
|
363 | - redirectexit(); |
|
382 | + if (empty($boards)) { |
|
383 | + redirectexit(); |
|
384 | + } |
|
364 | 385 | |
365 | 386 | markBoardsRead($boards, isset($_REQUEST['unread'])); |
366 | 387 | |
367 | 388 | foreach ($boards as $b) |
368 | 389 | { |
369 | - if (isset($_SESSION['topicseen_cache'][$b])) |
|
370 | - $_SESSION['topicseen_cache'][$b] = array(); |
|
390 | + if (isset($_SESSION['topicseen_cache'][$b])) { |
|
391 | + $_SESSION['topicseen_cache'][$b] = array(); |
|
392 | + } |
|
371 | 393 | } |
372 | 394 | |
373 | 395 | if (!isset($_REQUEST['unread'])) |
@@ -385,8 +407,9 @@ discard block |
||
385 | 407 | if ($smcFunc['db_num_rows']($result) > 0) |
386 | 408 | { |
387 | 409 | $logBoardInserts = ''; |
388 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
389 | - $logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']); |
|
410 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
411 | + $logBoardInserts[] = array($modSettings['maxMsgID'], $user_info['id'], $row['id_board']); |
|
412 | + } |
|
390 | 413 | |
391 | 414 | $smcFunc['db_insert']('replace', |
392 | 415 | '{db_prefix}log_boards', |
@@ -397,17 +420,18 @@ discard block |
||
397 | 420 | } |
398 | 421 | $smcFunc['db_free_result']($result); |
399 | 422 | |
400 | - if (empty($board)) |
|
401 | - redirectexit(); |
|
402 | - else |
|
403 | - redirectexit('board=' . $board . '.0'); |
|
404 | - } |
|
405 | - else |
|
423 | + if (empty($board)) { |
|
424 | + redirectexit(); |
|
425 | + } else { |
|
426 | + redirectexit('board=' . $board . '.0'); |
|
427 | + } |
|
428 | + } else |
|
406 | 429 | { |
407 | - if (empty($board_info['parent'])) |
|
408 | - redirectexit(); |
|
409 | - else |
|
410 | - redirectexit('board=' . $board_info['parent'] . '.0'); |
|
430 | + if (empty($board_info['parent'])) { |
|
431 | + redirectexit(); |
|
432 | + } else { |
|
433 | + redirectexit('board=' . $board_info['parent'] . '.0'); |
|
434 | + } |
|
411 | 435 | } |
412 | 436 | } |
413 | 437 | } |
@@ -432,11 +456,13 @@ discard block |
||
432 | 456 | 'selected_message' => (int) $messageID, |
433 | 457 | ) |
434 | 458 | ); |
435 | - if ($smcFunc['db_num_rows']($result) > 0) |
|
436 | - list ($memberID) = $smcFunc['db_fetch_row']($result); |
|
459 | + if ($smcFunc['db_num_rows']($result) > 0) { |
|
460 | + list ($memberID) = $smcFunc['db_fetch_row']($result); |
|
461 | + } |
|
437 | 462 | // The message doesn't even exist. |
438 | - else |
|
439 | - $memberID = 0; |
|
463 | + else { |
|
464 | + $memberID = 0; |
|
465 | + } |
|
440 | 466 | $smcFunc['db_free_result']($result); |
441 | 467 | |
442 | 468 | return (int) $memberID; |
@@ -457,8 +483,9 @@ discard block |
||
457 | 483 | getBoardTree(); |
458 | 484 | |
459 | 485 | // Make sure given boards and categories exist. |
460 | - if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) |
|
461 | - fatal_lang_error('no_board'); |
|
486 | + if (!isset($boards[$board_id]) || (isset($boardOptions['target_board']) && !isset($boards[$boardOptions['target_board']])) || (isset($boardOptions['target_category']) && !isset($cat_tree[$boardOptions['target_category']]))) { |
|
487 | + fatal_lang_error('no_board'); |
|
488 | + } |
|
462 | 489 | |
463 | 490 | $id = $board_id; |
464 | 491 | call_integration_hook('integrate_pre_modify_board', array($id, &$boardOptions)); |
@@ -486,8 +513,9 @@ discard block |
||
486 | 513 | $child_level = 0; |
487 | 514 | $id_parent = 0; |
488 | 515 | $after = 0; |
489 | - foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) |
|
490 | - $after = max($after, $boards[$id_board]['order']); |
|
516 | + foreach ($cat_tree[$id_cat]['children'] as $id_board => $dummy) { |
|
517 | + $after = max($after, $boards[$id_board]['order']); |
|
518 | + } |
|
491 | 519 | } |
492 | 520 | |
493 | 521 | // Make the board a child of a given board. |
@@ -498,17 +526,19 @@ discard block |
||
498 | 526 | $id_parent = $boardOptions['target_board']; |
499 | 527 | |
500 | 528 | // People can be creative, in many ways... |
501 | - if (isChildOf($id_parent, $board_id)) |
|
502 | - fatal_lang_error('mboards_parent_own_child_error', false); |
|
503 | - elseif ($id_parent == $board_id) |
|
504 | - fatal_lang_error('mboards_board_own_child_error', false); |
|
529 | + if (isChildOf($id_parent, $board_id)) { |
|
530 | + fatal_lang_error('mboards_parent_own_child_error', false); |
|
531 | + } elseif ($id_parent == $board_id) { |
|
532 | + fatal_lang_error('mboards_board_own_child_error', false); |
|
533 | + } |
|
505 | 534 | |
506 | 535 | $after = $boards[$boardOptions['target_board']]['order']; |
507 | 536 | |
508 | 537 | // Check if there are already children and (if so) get the max board order. |
509 | - if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) |
|
510 | - foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy) |
|
538 | + if (!empty($boards[$id_parent]['tree']['children']) && empty($boardOptions['move_first_child'])) { |
|
539 | + foreach ($boards[$id_parent]['tree']['children'] as $childBoard_id => $dummy) |
|
511 | 540 | $after = max($after, $boards[$childBoard_id]['order']); |
541 | + } |
|
512 | 542 | } |
513 | 543 | |
514 | 544 | // Place a board before or after another board, on the same child level. |
@@ -521,8 +551,9 @@ discard block |
||
521 | 551 | } |
522 | 552 | |
523 | 553 | // Oops...? |
524 | - else |
|
525 | - trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR); |
|
554 | + else { |
|
555 | + trigger_error('modifyBoard(): The move_to value \'' . $boardOptions['move_to'] . '\' is incorrect', E_USER_ERROR); |
|
556 | + } |
|
526 | 557 | |
527 | 558 | // Get a list of children of this board. |
528 | 559 | $childList = array(); |
@@ -531,14 +562,16 @@ discard block |
||
531 | 562 | // See if there are changes that affect children. |
532 | 563 | $childUpdates = array(); |
533 | 564 | $levelDiff = $child_level - $boards[$board_id]['level']; |
534 | - if ($levelDiff != 0) |
|
535 | - $childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}'; |
|
536 | - if ($id_cat != $boards[$board_id]['category']) |
|
537 | - $childUpdates[] = 'id_cat = {int:category}'; |
|
565 | + if ($levelDiff != 0) { |
|
566 | + $childUpdates[] = 'child_level = child_level ' . ($levelDiff > 0 ? '+ ' : '') . '{int:level_diff}'; |
|
567 | + } |
|
568 | + if ($id_cat != $boards[$board_id]['category']) { |
|
569 | + $childUpdates[] = 'id_cat = {int:category}'; |
|
570 | + } |
|
538 | 571 | |
539 | 572 | // Fix the children of this board. |
540 | - if (!empty($childList) && !empty($childUpdates)) |
|
541 | - $smcFunc['db_query']('', ' |
|
573 | + if (!empty($childList) && !empty($childUpdates)) { |
|
574 | + $smcFunc['db_query']('', ' |
|
542 | 575 | UPDATE {db_prefix}boards |
543 | 576 | SET ' . implode(', |
544 | 577 | ', $childUpdates) . ' |
@@ -549,6 +582,7 @@ discard block |
||
549 | 582 | 'level_diff' => $levelDiff, |
550 | 583 | ) |
551 | 584 | ); |
585 | + } |
|
552 | 586 | |
553 | 587 | // Make some room for this spot. |
554 | 588 | $smcFunc['db_query']('', ' |
@@ -644,8 +678,8 @@ discard block |
||
644 | 678 | call_integration_hook('integrate_modify_board', array($id, &$boardUpdates, &$boardUpdateParameters)); |
645 | 679 | |
646 | 680 | // Do the updates (if any). |
647 | - if (!empty($boardUpdates)) |
|
648 | - $smcFunc['db_query']('', ' |
|
681 | + if (!empty($boardUpdates)) { |
|
682 | + $smcFunc['db_query']('', ' |
|
649 | 683 | UPDATE {db_prefix}boards |
650 | 684 | SET |
651 | 685 | ' . implode(', |
@@ -655,6 +689,7 @@ discard block |
||
655 | 689 | 'selected_board' => $board_id, |
656 | 690 | )) |
657 | 691 | ); |
692 | + } |
|
658 | 693 | |
659 | 694 | // Set moderators of this board. |
660 | 695 | if (isset($boardOptions['moderators']) || isset($boardOptions['moderator_string']) || isset($boardOptions['moderator_groups']) || isset($boardOptions['moderator_group_string'])) |
@@ -679,13 +714,15 @@ discard block |
||
679 | 714 | { |
680 | 715 | $moderators[$k] = trim($moderators[$k]); |
681 | 716 | |
682 | - if (strlen($moderators[$k]) == 0) |
|
683 | - unset($moderators[$k]); |
|
717 | + if (strlen($moderators[$k]) == 0) { |
|
718 | + unset($moderators[$k]); |
|
719 | + } |
|
684 | 720 | } |
685 | 721 | |
686 | 722 | // Find all the id_member's for the member_name's in the list. |
687 | - if (empty($boardOptions['moderators'])) |
|
688 | - $boardOptions['moderators'] = array(); |
|
723 | + if (empty($boardOptions['moderators'])) { |
|
724 | + $boardOptions['moderators'] = array(); |
|
725 | + } |
|
689 | 726 | if (!empty($moderators)) |
690 | 727 | { |
691 | 728 | $request = $smcFunc['db_query']('', ' |
@@ -698,8 +735,9 @@ discard block |
||
698 | 735 | 'limit' => count($moderators), |
699 | 736 | ) |
700 | 737 | ); |
701 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
702 | - $boardOptions['moderators'][] = $row['id_member']; |
|
738 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
739 | + $boardOptions['moderators'][] = $row['id_member']; |
|
740 | + } |
|
703 | 741 | $smcFunc['db_free_result']($request); |
704 | 742 | } |
705 | 743 | } |
@@ -708,8 +746,9 @@ discard block |
||
708 | 746 | if (!empty($boardOptions['moderators'])) |
709 | 747 | { |
710 | 748 | $inserts = array(); |
711 | - foreach ($boardOptions['moderators'] as $moderator) |
|
712 | - $inserts[] = array($board_id, $moderator); |
|
749 | + foreach ($boardOptions['moderators'] as $moderator) { |
|
750 | + $inserts[] = array($board_id, $moderator); |
|
751 | + } |
|
713 | 752 | |
714 | 753 | $smcFunc['db_insert']('insert', |
715 | 754 | '{db_prefix}moderators', |
@@ -739,14 +778,16 @@ discard block |
||
739 | 778 | { |
740 | 779 | $moderator_groups[$k] = trim($moderator_groups[$k]); |
741 | 780 | |
742 | - if (strlen($moderator_groups[$k]) == 0) |
|
743 | - unset($moderator_groups[$k]); |
|
781 | + if (strlen($moderator_groups[$k]) == 0) { |
|
782 | + unset($moderator_groups[$k]); |
|
783 | + } |
|
744 | 784 | } |
745 | 785 | |
746 | 786 | /* Find all the id_group's for all the group names in the list |
747 | 787 | But skip any invalid ones (invisible/post groups/Administrator/Moderator) */ |
748 | - if (empty($boardOptions['moderator_groups'])) |
|
749 | - $boardOptions['moderator_groups'] = array(); |
|
788 | + if (empty($boardOptions['moderator_groups'])) { |
|
789 | + $boardOptions['moderator_groups'] = array(); |
|
790 | + } |
|
750 | 791 | if (!empty($moderator_groups)) |
751 | 792 | { |
752 | 793 | $request = $smcFunc['db_query']('', ' |
@@ -777,8 +818,9 @@ discard block |
||
777 | 818 | if (!empty($boardOptions['moderator_groups'])) |
778 | 819 | { |
779 | 820 | $inserts = array(); |
780 | - foreach ($boardOptions['moderator_groups'] as $moderator_group) |
|
781 | - $inserts[] = array($board_id, $moderator_group); |
|
821 | + foreach ($boardOptions['moderator_groups'] as $moderator_group) { |
|
822 | + $inserts[] = array($board_id, $moderator_group); |
|
823 | + } |
|
782 | 824 | |
783 | 825 | $smcFunc['db_insert']('insert', |
784 | 826 | '{db_prefix}moderator_groups', |
@@ -792,14 +834,16 @@ discard block |
||
792 | 834 | updateSettings(array('settings_updated' => time())); |
793 | 835 | } |
794 | 836 | |
795 | - if (isset($boardOptions['move_to'])) |
|
796 | - reorderBoards(); |
|
837 | + if (isset($boardOptions['move_to'])) { |
|
838 | + reorderBoards(); |
|
839 | + } |
|
797 | 840 | |
798 | 841 | clean_cache('data'); |
799 | 842 | |
800 | - if (empty($boardOptions['dont_log'])) |
|
801 | - logAction('edit_board', array('board' => $board_id), 'admin'); |
|
802 | -} |
|
843 | + if (empty($boardOptions['dont_log'])) { |
|
844 | + logAction('edit_board', array('board' => $board_id), 'admin'); |
|
845 | + } |
|
846 | + } |
|
803 | 847 | |
804 | 848 | /** |
805 | 849 | * Create a new board and set its properties and position. |
@@ -815,11 +859,13 @@ discard block |
||
815 | 859 | global $boards, $smcFunc; |
816 | 860 | |
817 | 861 | // Trigger an error if one of the required values is not set. |
818 | - if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) |
|
819 | - trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR); |
|
862 | + if (!isset($boardOptions['board_name']) || trim($boardOptions['board_name']) == '' || !isset($boardOptions['move_to']) || !isset($boardOptions['target_category'])) { |
|
863 | + trigger_error('createBoard(): One or more of the required options is not set', E_USER_ERROR); |
|
864 | + } |
|
820 | 865 | |
821 | - if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) |
|
822 | - trigger_error('createBoard(): Target board is not set', E_USER_ERROR); |
|
866 | + if (in_array($boardOptions['move_to'], array('child', 'before', 'after')) && !isset($boardOptions['target_board'])) { |
|
867 | + trigger_error('createBoard(): Target board is not set', E_USER_ERROR); |
|
868 | + } |
|
823 | 869 | |
824 | 870 | // Set every optional value to its default value. |
825 | 871 | $boardOptions += array( |
@@ -853,8 +899,9 @@ discard block |
||
853 | 899 | ); |
854 | 900 | $board_id = $smcFunc['db_insert_id']('{db_prefix}boards', 'id_board'); |
855 | 901 | |
856 | - if (empty($board_id)) |
|
857 | - return 0; |
|
902 | + if (empty($board_id)) { |
|
903 | + return 0; |
|
904 | + } |
|
858 | 905 | |
859 | 906 | // Change the board according to the given specifications. |
860 | 907 | modifyBoard($board_id, $boardOptions); |
@@ -917,8 +964,9 @@ discard block |
||
917 | 964 | global $sourcedir, $boards, $smcFunc; |
918 | 965 | |
919 | 966 | // No boards to delete? Return! |
920 | - if (empty($boards_to_remove)) |
|
921 | - return; |
|
967 | + if (empty($boards_to_remove)) { |
|
968 | + return; |
|
969 | + } |
|
922 | 970 | |
923 | 971 | getBoardTree(); |
924 | 972 | |
@@ -929,12 +977,14 @@ discard block |
||
929 | 977 | { |
930 | 978 | // Get a list of the child boards that will also be removed. |
931 | 979 | $child_boards_to_remove = array(); |
932 | - foreach ($boards_to_remove as $board_to_remove) |
|
933 | - recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']); |
|
980 | + foreach ($boards_to_remove as $board_to_remove) { |
|
981 | + recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']); |
|
982 | + } |
|
934 | 983 | |
935 | 984 | // Merge the children with their parents. |
936 | - if (!empty($child_boards_to_remove)) |
|
937 | - $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove)); |
|
985 | + if (!empty($child_boards_to_remove)) { |
|
986 | + $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove)); |
|
987 | + } |
|
938 | 988 | } |
939 | 989 | // Move the children to a safe home. |
940 | 990 | else |
@@ -942,10 +992,11 @@ discard block |
||
942 | 992 | foreach ($boards_to_remove as $id_board) |
943 | 993 | { |
944 | 994 | // @todo Separate category? |
945 | - if ($moveChildrenTo === 0) |
|
946 | - fixChildren($id_board, 0, 0); |
|
947 | - else |
|
948 | - fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo); |
|
995 | + if ($moveChildrenTo === 0) { |
|
996 | + fixChildren($id_board, 0, 0); |
|
997 | + } else { |
|
998 | + fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo); |
|
999 | + } |
|
949 | 1000 | } |
950 | 1001 | } |
951 | 1002 | |
@@ -959,8 +1010,9 @@ discard block |
||
959 | 1010 | ) |
960 | 1011 | ); |
961 | 1012 | $topics = array(); |
962 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
963 | - $topics[] = $row['id_topic']; |
|
1013 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1014 | + $topics[] = $row['id_topic']; |
|
1015 | + } |
|
964 | 1016 | $smcFunc['db_free_result']($request); |
965 | 1017 | |
966 | 1018 | require_once($sourcedir . '/RemoveTopic.php'); |
@@ -1048,8 +1100,9 @@ discard block |
||
1048 | 1100 | clean_cache('data'); |
1049 | 1101 | |
1050 | 1102 | // Let's do some serious logging. |
1051 | - foreach ($boards_to_remove as $id_board) |
|
1052 | - logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin'); |
|
1103 | + foreach ($boards_to_remove as $id_board) { |
|
1104 | + logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin'); |
|
1105 | + } |
|
1053 | 1106 | |
1054 | 1107 | reorderBoards(); |
1055 | 1108 | } |
@@ -1068,8 +1121,8 @@ discard block |
||
1068 | 1121 | $board_order = 0; |
1069 | 1122 | foreach ($cat_tree as $catID => $dummy) |
1070 | 1123 | { |
1071 | - foreach ($boardList[$catID] as $boardID) |
|
1072 | - if ($boards[$boardID]['order'] != ++$board_order) |
|
1124 | + foreach ($boardList[$catID] as $boardID) { |
|
1125 | + if ($boards[$boardID]['order'] != ++$board_order) |
|
1073 | 1126 | $smcFunc['db_query']('', ' |
1074 | 1127 | UPDATE {db_prefix}boards |
1075 | 1128 | SET board_order = {int:new_order} |
@@ -1079,6 +1132,7 @@ discard block |
||
1079 | 1132 | 'selected_board' => $boardID, |
1080 | 1133 | ) |
1081 | 1134 | ); |
1135 | + } |
|
1082 | 1136 | } |
1083 | 1137 | |
1084 | 1138 | // Empty the board order cache |
@@ -1107,8 +1161,9 @@ discard block |
||
1107 | 1161 | ) |
1108 | 1162 | ); |
1109 | 1163 | $children = array(); |
1110 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1111 | - $children[] = $row['id_board']; |
|
1164 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1165 | + $children[] = $row['id_board']; |
|
1166 | + } |
|
1112 | 1167 | $smcFunc['db_free_result']($result); |
1113 | 1168 | |
1114 | 1169 | // ...and set it to a new parent and child_level. |
@@ -1124,9 +1179,10 @@ discard block |
||
1124 | 1179 | ); |
1125 | 1180 | |
1126 | 1181 | // Recursively fix the children of the children. |
1127 | - foreach ($children as $child) |
|
1128 | - fixChildren($child, $newLevel + 1, $child); |
|
1129 | -} |
|
1182 | + foreach ($children as $child) { |
|
1183 | + fixChildren($child, $newLevel + 1, $child); |
|
1184 | + } |
|
1185 | + } |
|
1130 | 1186 | |
1131 | 1187 | /** |
1132 | 1188 | * Tries to load up the entire board order and category very very quickly |
@@ -1143,8 +1199,9 @@ discard block |
||
1143 | 1199 | 'boards' => array(), |
1144 | 1200 | ); |
1145 | 1201 | |
1146 | - if (!empty($tree_order['boards'])) |
|
1147 | - return $tree_order; |
|
1202 | + if (!empty($tree_order['boards'])) { |
|
1203 | + return $tree_order; |
|
1204 | + } |
|
1148 | 1205 | |
1149 | 1206 | if (($cached = cache_get_data('board_order', 86400)) !== null) |
1150 | 1207 | { |
@@ -1160,8 +1217,9 @@ discard block |
||
1160 | 1217 | ); |
1161 | 1218 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1162 | 1219 | { |
1163 | - if (!in_array($row['id_cat'], $tree_order['cats'])) |
|
1164 | - $tree_order['cats'][] = $row['id_cat']; |
|
1220 | + if (!in_array($row['id_cat'], $tree_order['cats'])) { |
|
1221 | + $tree_order['cats'][] = $row['id_cat']; |
|
1222 | + } |
|
1165 | 1223 | $tree_order['boards'][] = $row['id_board']; |
1166 | 1224 | } |
1167 | 1225 | $smcFunc['db_free_result']($request); |
@@ -1181,16 +1239,19 @@ discard block |
||
1181 | 1239 | $tree = getTreeOrder(); |
1182 | 1240 | |
1183 | 1241 | $ordered = array(); |
1184 | - foreach ($tree['boards'] as $board) |
|
1185 | - if (!empty($boards[$board])) |
|
1242 | + foreach ($tree['boards'] as $board) { |
|
1243 | + if (!empty($boards[$board])) |
|
1186 | 1244 | { |
1187 | 1245 | $ordered[$board] = $boards[$board]; |
1246 | + } |
|
1188 | 1247 | |
1189 | - if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) |
|
1190 | - sortBoards($ordered[$board]['boards']); |
|
1248 | + if (is_array($ordered[$board]) && !empty($ordered[$board]['boards'])) { |
|
1249 | + sortBoards($ordered[$board]['boards']); |
|
1250 | + } |
|
1191 | 1251 | |
1192 | - if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) |
|
1193 | - sortBoards($ordered[$board]['children']); |
|
1252 | + if (is_array($ordered[$board]) && !empty($ordered[$board]['children'])) { |
|
1253 | + sortBoards($ordered[$board]['children']); |
|
1254 | + } |
|
1194 | 1255 | } |
1195 | 1256 | |
1196 | 1257 | $boards = $ordered; |
@@ -1206,12 +1267,14 @@ discard block |
||
1206 | 1267 | $tree = getTreeOrder(); |
1207 | 1268 | |
1208 | 1269 | $ordered = array(); |
1209 | - foreach ($tree['cats'] as $cat) |
|
1210 | - if (!empty($categories[$cat])) |
|
1270 | + foreach ($tree['cats'] as $cat) { |
|
1271 | + if (!empty($categories[$cat])) |
|
1211 | 1272 | { |
1212 | 1273 | $ordered[$cat] = $categories[$cat]; |
1213 | - if (!empty($ordered[$cat]['boards'])) |
|
1214 | - sortBoards($ordered[$cat]['boards']); |
|
1274 | + } |
|
1275 | + if (!empty($ordered[$cat]['boards'])) { |
|
1276 | + sortBoards($ordered[$cat]['boards']); |
|
1277 | + } |
|
1215 | 1278 | } |
1216 | 1279 | |
1217 | 1280 | $categories = $ordered; |
@@ -1227,8 +1290,9 @@ discard block |
||
1227 | 1290 | { |
1228 | 1291 | global $smcFunc, $scripturl, $txt; |
1229 | 1292 | |
1230 | - if (empty($boards)) |
|
1231 | - return array(); |
|
1293 | + if (empty($boards)) { |
|
1294 | + return array(); |
|
1295 | + } |
|
1232 | 1296 | |
1233 | 1297 | $request = $smcFunc['db_query']('', ' |
1234 | 1298 | SELECT mem.id_member, mem.real_name, mo.id_board |
@@ -1242,8 +1306,9 @@ discard block |
||
1242 | 1306 | $moderators = array(); |
1243 | 1307 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1244 | 1308 | { |
1245 | - if (empty($moderators[$row['id_board']])) |
|
1246 | - $moderators[$row['id_board']] = array(); |
|
1309 | + if (empty($moderators[$row['id_board']])) { |
|
1310 | + $moderators[$row['id_board']] = array(); |
|
1311 | + } |
|
1247 | 1312 | |
1248 | 1313 | $moderators[$row['id_board']][] = array( |
1249 | 1314 | 'id' => $row['id_member'], |
@@ -1267,8 +1332,9 @@ discard block |
||
1267 | 1332 | { |
1268 | 1333 | global $smcFunc, $scripturl, $txt; |
1269 | 1334 | |
1270 | - if (empty($boards)) |
|
1271 | - return array(); |
|
1335 | + if (empty($boards)) { |
|
1336 | + return array(); |
|
1337 | + } |
|
1272 | 1338 | |
1273 | 1339 | $request = $smcFunc['db_query']('', ' |
1274 | 1340 | SELECT mg.id_group, mg.group_name, bg.id_board |
@@ -1282,8 +1348,9 @@ discard block |
||
1282 | 1348 | $groups = array(); |
1283 | 1349 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1284 | 1350 | { |
1285 | - if (empty($groups[$row['id_board']])) |
|
1286 | - $groups[$row['id_board']] = array(); |
|
1351 | + if (empty($groups[$row['id_board']])) { |
|
1352 | + $groups[$row['id_board']] = array(); |
|
1353 | + } |
|
1287 | 1354 | |
1288 | 1355 | $groups[$row['id_board']][] = array( |
1289 | 1356 | 'id' => $row['id_group'], |
@@ -1345,8 +1412,9 @@ discard block |
||
1345 | 1412 | |
1346 | 1413 | if (!empty($row['id_board'])) |
1347 | 1414 | { |
1348 | - if ($row['child_level'] != $curLevel) |
|
1349 | - $prevBoard = 0; |
|
1415 | + if ($row['child_level'] != $curLevel) { |
|
1416 | + $prevBoard = 0; |
|
1417 | + } |
|
1350 | 1418 | |
1351 | 1419 | $boards[$row['id_board']] = array( |
1352 | 1420 | 'id' => $row['id_board'], |
@@ -1378,16 +1446,16 @@ discard block |
||
1378 | 1446 | 'children' => array() |
1379 | 1447 | ); |
1380 | 1448 | $boards[$row['id_board']]['tree'] = &$cat_tree[$row['id_cat']]['children'][$row['id_board']]; |
1381 | - } |
|
1382 | - else |
|
1449 | + } else |
|
1383 | 1450 | { |
1384 | 1451 | // Parent doesn't exist! |
1385 | - if (!isset($boards[$row['id_parent']]['tree'])) |
|
1386 | - fatal_lang_error('no_valid_parent', false, array($row['board_name'])); |
|
1452 | + if (!isset($boards[$row['id_parent']]['tree'])) { |
|
1453 | + fatal_lang_error('no_valid_parent', false, array($row['board_name'])); |
|
1454 | + } |
|
1387 | 1455 | |
1388 | 1456 | // Wrong childlevel...we can silently fix this... |
1389 | - if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) |
|
1390 | - $smcFunc['db_query']('', ' |
|
1457 | + if ($boards[$row['id_parent']]['tree']['node']['level'] != $row['child_level'] - 1) { |
|
1458 | + $smcFunc['db_query']('', ' |
|
1391 | 1459 | UPDATE {db_prefix}boards |
1392 | 1460 | SET child_level = {int:new_child_level} |
1393 | 1461 | WHERE id_board = {int:selected_board}', |
@@ -1396,6 +1464,7 @@ discard block |
||
1396 | 1464 | 'selected_board' => $row['id_board'], |
1397 | 1465 | ) |
1398 | 1466 | ); |
1467 | + } |
|
1399 | 1468 | |
1400 | 1469 | $boards[$row['id_parent']]['tree']['children'][$row['id_board']] = array( |
1401 | 1470 | 'node' => &$boards[$row['id_board']], |
@@ -1426,8 +1495,9 @@ discard block |
||
1426 | 1495 | */ |
1427 | 1496 | function recursiveBoards(&$_boardList, &$_tree) |
1428 | 1497 | { |
1429 | - if (empty($_tree['children'])) |
|
1430 | - return; |
|
1498 | + if (empty($_tree['children'])) { |
|
1499 | + return; |
|
1500 | + } |
|
1431 | 1501 | |
1432 | 1502 | foreach ($_tree['children'] as $id => $node) |
1433 | 1503 | { |
@@ -1446,11 +1516,13 @@ discard block |
||
1446 | 1516 | { |
1447 | 1517 | global $boards; |
1448 | 1518 | |
1449 | - if (empty($boards[$child]['parent'])) |
|
1450 | - return false; |
|
1519 | + if (empty($boards[$child]['parent'])) { |
|
1520 | + return false; |
|
1521 | + } |
|
1451 | 1522 | |
1452 | - if ($boards[$child]['parent'] == $parent) |
|
1453 | - return true; |
|
1523 | + if ($boards[$child]['parent'] == $parent) { |
|
1524 | + return true; |
|
1525 | + } |
|
1454 | 1526 | |
1455 | 1527 | return isChildOf($boards[$child]['parent'], $parent); |
1456 | 1528 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | ); |
92 | 93 | |
93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
94 | - if (empty($modSettings['messageIcons_enable'])) |
|
95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
97 | + } |
|
96 | 98 | if (empty($modSettings['smiley_enable'])) |
97 | 99 | { |
98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
126 | 128 | |
127 | 129 | $smiley_context = array(); |
128 | - foreach ($smiley_sets as $i => $set) |
|
129 | - $smiley_context[$set] = $set_names[$i]; |
|
130 | + foreach ($smiley_sets as $i => $set) { |
|
131 | + $smiley_context[$set] = $set_names[$i]; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | // All the settings for the page... |
132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
147 | 150 | |
148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
149 | 152 | |
150 | - if ($return_config) |
|
151 | - return $config_vars; |
|
153 | + if ($return_config) { |
|
154 | + return $config_vars; |
|
155 | + } |
|
152 | 156 | |
153 | 157 | // Setup the basics of the settings template. |
154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
208 | 212 | { |
209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
211 | - unset($set_paths[$id], $set_names[$id]); |
|
214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
215 | + unset($set_paths[$id], $set_names[$id]); |
|
216 | + } |
|
212 | 217 | } |
213 | 218 | |
214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
222 | 227 | )); |
223 | 228 | } |
224 | 229 | // Add a new smiley set. |
225 | - elseif (!empty($_POST['add'])) |
|
226 | - $context['sub_action'] = 'modifyset'; |
|
230 | + elseif (!empty($_POST['add'])) { |
|
231 | + $context['sub_action'] = 'modifyset'; |
|
232 | + } |
|
227 | 233 | // Create or modify a smiley set. |
228 | 234 | elseif (isset($_POST['set'])) |
229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
233 | 239 | // Create a new smiley set. |
234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
235 | 241 | { |
236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
237 | - fatal_lang_error('smiley_set_already_exists'); |
|
242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
243 | + fatal_lang_error('smiley_set_already_exists'); |
|
244 | + } |
|
238 | 245 | |
239 | 246 | updateSettings(array( |
240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
246 | 253 | else |
247 | 254 | { |
248 | 255 | // Make sure the smiley set exists. |
249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
250 | - fatal_lang_error('smiley_set_not_found'); |
|
256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
257 | + fatal_lang_error('smiley_set_not_found'); |
|
258 | + } |
|
251 | 259 | |
252 | 260 | // Make sure the path is not yet used by another smileyset. |
253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
263 | + } |
|
255 | 264 | |
256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
263 | 272 | } |
264 | 273 | |
265 | 274 | // The user might have checked to also import smileys. |
266 | - if (!empty($_POST['smiley_sets_import'])) |
|
267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
277 | + } |
|
268 | 278 | } |
269 | 279 | cache_put_data('parsing_smileys', null, 480); |
270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
273 | 283 | // Load all available smileysets... |
274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
277 | - $context['smiley_sets'][$i] = array( |
|
286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
287 | + $context['smiley_sets'][$i] = array( |
|
278 | 288 | 'id' => $i, |
279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
282 | 292 | ); |
293 | + } |
|
283 | 294 | |
284 | 295 | // Importing any smileys from an existing set? |
285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
290 | 301 | $_GET['set'] = (int) $_GET['set']; |
291 | 302 | |
292 | 303 | // Sanity check - then import. |
293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
306 | + } |
|
295 | 307 | |
296 | 308 | // Force the process to continue. |
297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
301 | 313 | if ($context['sub_action'] == 'modifyset') |
302 | 314 | { |
303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
305 | - $context['current_set'] = array( |
|
316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
317 | + $context['current_set'] = array( |
|
306 | 318 | 'id' => '-1', |
307 | 319 | 'path' => '', |
308 | 320 | 'name' => '', |
309 | 321 | 'selected' => false, |
310 | 322 | 'is_new' => true, |
311 | 323 | ); |
312 | - else |
|
324 | + } else |
|
313 | 325 | { |
314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
322 | 334 | while ($entry = $dir->read()) |
323 | 335 | { |
324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
325 | - $smileys[strtolower($entry)] = $entry; |
|
336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
337 | + $smileys[strtolower($entry)] = $entry; |
|
338 | + } |
|
326 | 339 | } |
327 | 340 | $dir->close(); |
328 | 341 | |
329 | - if (empty($smileys)) |
|
330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
342 | + if (empty($smileys)) { |
|
343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
344 | + } |
|
331 | 345 | |
332 | 346 | // Exclude the smileys that are already in the database. |
333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
338 | 352 | 'smiley_list' => $smileys, |
339 | 353 | ) |
340 | 354 | ); |
341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
343 | 357 | unset($smileys[strtolower($row['filename'])]); |
358 | + } |
|
344 | 359 | $smcFunc['db_free_result']($request); |
345 | 360 | |
346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
355 | 370 | $dir = dir($modSettings['smileys_dir']); |
356 | 371 | while ($entry = $dir->read()) |
357 | 372 | { |
358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
359 | - $context['smiley_set_dirs'][] = array( |
|
373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
374 | + $context['smiley_set_dirs'][] = array( |
|
360 | 375 | 'id' => $entry, |
361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
363 | 378 | 'current' => $entry == $context['current_set']['path'], |
364 | 379 | ); |
380 | + } |
|
365 | 381 | } |
366 | 382 | $dir->close(); |
367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
371 | 387 | createToken('admin-mss', 'request'); |
372 | 388 | |
373 | 389 | // In case we need to import smileys, we need to add the token in now. |
374 | - if (isset($context['current_set']['import_url'])) |
|
375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
390 | + if (isset($context['current_set']['import_url'])) { |
|
391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
392 | + } |
|
376 | 393 | |
377 | 394 | $listOptions = array( |
378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
510 | 527 | $cols['name'][] = $set_names[$i]; |
511 | 528 | } |
512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
513 | - if (substr($sort, 0, 4) === 'name') |
|
514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
515 | - elseif (substr($sort, 0, 4) === 'path') |
|
516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
517 | - else |
|
518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
530 | + if (substr($sort, 0, 4) === 'name') { |
|
531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
534 | + } else { |
|
535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
536 | + } |
|
519 | 537 | |
520 | 538 | $smiley_sets = array(); |
521 | - foreach ($cols['id'] as $i => $id) |
|
522 | - $smiley_sets[] = array( |
|
539 | + foreach ($cols['id'] as $i => $id) { |
|
540 | + $smiley_sets[] = array( |
|
523 | 541 | 'id' => $id, |
524 | 542 | 'path' => $cols['path'][$i], |
525 | 543 | 'name' => $cols['name'][$i], |
526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
527 | 545 | ); |
546 | + } |
|
528 | 547 | |
529 | 548 | return $smiley_sets; |
530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
557 | - $context['smiley_sets'][$i] = array( |
|
575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
576 | + $context['smiley_sets'][$i] = array( |
|
558 | 577 | 'id' => $i, |
559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
562 | 581 | ); |
582 | + } |
|
563 | 583 | |
564 | 584 | // Submitting a form? |
565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
576 | 596 | |
577 | 597 | // Make sure some code was entered. |
578 | - if (empty($_POST['smiley_code'])) |
|
579 | - fatal_lang_error('smiley_has_no_code'); |
|
598 | + if (empty($_POST['smiley_code'])) { |
|
599 | + fatal_lang_error('smiley_has_no_code'); |
|
600 | + } |
|
580 | 601 | |
581 | 602 | // Check whether the new code has duplicates. It should be unique. |
582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
589 | 610 | ) |
590 | 611 | ); |
591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
592 | - fatal_lang_error('smiley_not_unique'); |
|
612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
613 | + fatal_lang_error('smiley_not_unique'); |
|
614 | + } |
|
593 | 615 | $smcFunc['db_free_result']($request); |
594 | 616 | |
595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
598 | 620 | $writeErrors = array(); |
599 | 621 | foreach ($context['smiley_sets'] as $set) |
600 | 622 | { |
601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
602 | - $writeErrors[] = $set['path']; |
|
623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
624 | + $writeErrors[] = $set['path']; |
|
625 | + } |
|
626 | + } |
|
627 | + if (!empty($writeErrors)) { |
|
628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
603 | 629 | } |
604 | - if (!empty($writeErrors)) |
|
605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
606 | 630 | } |
607 | 631 | |
608 | 632 | // Uploading just one smiley for all of them? |
609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
610 | 634 | { |
611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
612 | - fatal_lang_error('smileys_upload_error'); |
|
635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
636 | + fatal_lang_error('smileys_upload_error'); |
|
637 | + } |
|
613 | 638 | |
614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
616 | 641 | |
617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
645 | + } |
|
620 | 646 | |
621 | 647 | // We only need the filename... |
622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
623 | 649 | |
624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
653 | + } |
|
627 | 654 | |
628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
629 | 656 | $i = 0; |
630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
632 | - $i++; |
|
658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
659 | + $i++; |
|
660 | + } |
|
633 | 661 | |
634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
645 | 673 | |
646 | 674 | // The file is already there! Don't overwrite it! |
647 | - if (file_exists($currentPath)) |
|
648 | - continue; |
|
675 | + if (file_exists($currentPath)) { |
|
676 | + continue; |
|
677 | + } |
|
649 | 678 | |
650 | 679 | // Okay, so copy the first one we made to here. |
651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
662 | 691 | $newName = ''; |
663 | 692 | foreach ($_FILES as $name => $data) |
664 | 693 | { |
665 | - if ($_FILES[$name]['name'] == '') |
|
666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
694 | + if ($_FILES[$name]['name'] == '') { |
|
695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
696 | + } |
|
667 | 697 | |
668 | - if (empty($newName)) |
|
669 | - $newName = basename($_FILES[$name]['name']); |
|
670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
671 | - fatal_lang_error('smileys_upload_error_name'); |
|
698 | + if (empty($newName)) { |
|
699 | + $newName = basename($_FILES[$name]['name']); |
|
700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
701 | + fatal_lang_error('smileys_upload_error_name'); |
|
702 | + } |
|
672 | 703 | } |
673 | 704 | |
674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
678 | 709 | |
679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
680 | - continue; |
|
710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
711 | + continue; |
|
712 | + } |
|
681 | 713 | |
682 | 714 | // Got one... |
683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
684 | - fatal_lang_error('smileys_upload_error'); |
|
715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
716 | + fatal_lang_error('smileys_upload_error'); |
|
717 | + } |
|
685 | 718 | |
686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
688 | 721 | |
689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
725 | + } |
|
692 | 726 | |
693 | 727 | // We only need the filename... |
694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
695 | 729 | |
696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
733 | + } |
|
699 | 734 | |
700 | 735 | // If the file exists - ignore it. |
701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
702 | - if (file_exists($smileyLocation)) |
|
703 | - continue; |
|
737 | + if (file_exists($smileyLocation)) { |
|
738 | + continue; |
|
739 | + } |
|
704 | 740 | |
705 | 741 | // Finally - move the image! |
706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
712 | 748 | } |
713 | 749 | |
714 | 750 | // Also make sure a filename was given. |
715 | - if (empty($_POST['smiley_filename'])) |
|
716 | - fatal_lang_error('smiley_has_no_filename'); |
|
751 | + if (empty($_POST['smiley_filename'])) { |
|
752 | + fatal_lang_error('smiley_has_no_filename'); |
|
753 | + } |
|
717 | 754 | |
718 | 755 | // Find the position on the right. |
719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
733 | 770 | $smcFunc['db_free_result']($request); |
734 | 771 | |
735 | - if (empty($smiley_order)) |
|
736 | - $smiley_order = '0'; |
|
772 | + if (empty($smiley_order)) { |
|
773 | + $smiley_order = '0'; |
|
774 | + } |
|
737 | 775 | } |
738 | 776 | $smcFunc['db_insert']('', |
739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
761 | 799 | { |
762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
763 | 801 | { |
764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
765 | - continue; |
|
802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
803 | + continue; |
|
804 | + } |
|
766 | 805 | |
767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
768 | 807 | while ($entry = $dir->read()) |
769 | 808 | { |
770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
771 | - $context['filenames'][strtolower($entry)] = array( |
|
809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
810 | + $context['filenames'][strtolower($entry)] = array( |
|
772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
773 | 812 | 'selected' => false, |
774 | 813 | ); |
814 | + } |
|
775 | 815 | } |
776 | 816 | $dir->close(); |
777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
809 | 849 | // Changing the selected smileys? |
810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
811 | 851 | { |
812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
854 | + } |
|
814 | 855 | |
815 | - if ($_POST['smiley_action'] == 'delete') |
|
816 | - $smcFunc['db_query']('', ' |
|
856 | + if ($_POST['smiley_action'] == 'delete') { |
|
857 | + $smcFunc['db_query']('', ' |
|
817 | 858 | DELETE FROM {db_prefix}smileys |
818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
819 | 860 | array( |
820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
821 | 862 | ) |
822 | 863 | ); |
864 | + } |
|
823 | 865 | // Changing the status of the smiley? |
824 | 866 | else |
825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
829 | 871 | 'hidden' => 1, |
830 | 872 | 'popup' => 2 |
831 | 873 | ); |
832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
833 | - $smcFunc['db_query']('', ' |
|
874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
875 | + $smcFunc['db_query']('', ' |
|
834 | 876 | UPDATE {db_prefix}smileys |
835 | 877 | SET hidden = {int:display_type} |
836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
840 | 882 | ) |
841 | 883 | ); |
884 | + } |
|
842 | 885 | } |
843 | 886 | } |
844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
865 | 908 | |
866 | 909 | // Make sure some code was entered. |
867 | - if (empty($_POST['smiley_code'])) |
|
868 | - fatal_lang_error('smiley_has_no_code'); |
|
910 | + if (empty($_POST['smiley_code'])) { |
|
911 | + fatal_lang_error('smiley_has_no_code'); |
|
912 | + } |
|
869 | 913 | |
870 | 914 | // Also make sure a filename was given. |
871 | - if (empty($_POST['smiley_filename'])) |
|
872 | - fatal_lang_error('smiley_has_no_filename'); |
|
915 | + if (empty($_POST['smiley_filename'])) { |
|
916 | + fatal_lang_error('smiley_has_no_filename'); |
|
917 | + } |
|
873 | 918 | |
874 | 919 | // Check whether the new code has duplicates. It should be unique. |
875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
884 | 929 | ) |
885 | 930 | ); |
886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
887 | - fatal_lang_error('smiley_not_unique'); |
|
931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
932 | + fatal_lang_error('smiley_not_unique'); |
|
933 | + } |
|
888 | 934 | $smcFunc['db_free_result']($request); |
889 | 935 | |
890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
913 | 959 | // Load all known smiley sets. |
914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
917 | - $context['smiley_sets'][$i] = array( |
|
962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
963 | + $context['smiley_sets'][$i] = array( |
|
918 | 964 | 'id' => $i, |
919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
922 | 968 | ); |
969 | + } |
|
923 | 970 | |
924 | 971 | // Prepare overview of all (custom) smileys. |
925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
935 | 982 | // Create a list of options for selecting smiley sets. |
936 | 983 | $smileyset_option_list = ' |
937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
939 | - $smileyset_option_list .= ' |
|
985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
986 | + $smileyset_option_list .= ' |
|
940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
988 | + } |
|
941 | 989 | $smileyset_option_list .= ' |
942 | 990 | </select>'; |
943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
999 | 1047 | 'data' => array( |
1000 | 1048 | 'function' => function ($rowData) use ($txt) |
1001 | 1049 | { |
1002 | - if (empty($rowData['hidden'])) |
|
1003 | - return $txt['smileys_location_form']; |
|
1004 | - elseif ($rowData['hidden'] == 1) |
|
1005 | - return $txt['smileys_location_hidden']; |
|
1006 | - else |
|
1007 | - return $txt['smileys_location_popup']; |
|
1050 | + if (empty($rowData['hidden'])) { |
|
1051 | + return $txt['smileys_location_form']; |
|
1052 | + } elseif ($rowData['hidden'] == 1) { |
|
1053 | + return $txt['smileys_location_hidden']; |
|
1054 | + } else { |
|
1055 | + return $txt['smileys_location_popup']; |
|
1056 | + } |
|
1008 | 1057 | }, |
1009 | 1058 | ), |
1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
1019 | 1068 | 'data' => array( |
1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
1021 | 1070 | { |
1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1073 | + } |
|
1024 | 1074 | |
1025 | 1075 | // Check if there are smileys missing in some sets. |
1026 | 1076 | $missing_sets = array(); |
1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
1080 | + } |
|
1030 | 1081 | |
1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
1032 | 1083 | |
1033 | - if (!empty($missing_sets)) |
|
1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1084 | + if (!empty($missing_sets)) { |
|
1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1086 | + } |
|
1035 | 1087 | |
1036 | 1088 | return $description; |
1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
1151 | - $context['smiley_sets'][$i] = array( |
|
1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
1203 | + $context['smiley_sets'][$i] = array( |
|
1152 | 1204 | 'id' => $i, |
1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
1156 | 1208 | ); |
1209 | + } |
|
1157 | 1210 | |
1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
1163 | 1216 | { |
1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
1165 | 1218 | { |
1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
1167 | - continue; |
|
1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
1220 | + continue; |
|
1221 | + } |
|
1168 | 1222 | |
1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
1170 | 1224 | while ($entry = $dir->read()) |
1171 | 1225 | { |
1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1173 | - $context['filenames'][strtolower($entry)] = array( |
|
1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1227 | + $context['filenames'][strtolower($entry)] = array( |
|
1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
1175 | 1229 | 'selected' => false, |
1176 | 1230 | ); |
1231 | + } |
|
1177 | 1232 | } |
1178 | 1233 | $dir->close(); |
1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
1189 | 1244 | ) |
1190 | 1245 | ); |
1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1192 | - fatal_lang_error('smiley_not_found'); |
|
1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1247 | + fatal_lang_error('smiley_not_found'); |
|
1248 | + } |
|
1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
1194 | 1250 | $smcFunc['db_free_result']($request); |
1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
1199 | 1255 | |
1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1258 | + } |
|
1202 | 1259 | } |
1203 | 1260 | } |
1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
1223 | 1280 | ) |
1224 | 1281 | ); |
1225 | 1282 | $smileys = array(); |
1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1227 | - $smileys[] = $row; |
|
1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1284 | + $smileys[] = $row; |
|
1285 | + } |
|
1228 | 1286 | $smcFunc['db_free_result']($request); |
1229 | 1287 | |
1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
1266 | 1324 | |
1267 | - if (empty($_GET['source'])) |
|
1268 | - fatal_lang_error('smiley_not_found'); |
|
1325 | + if (empty($_GET['source'])) { |
|
1326 | + fatal_lang_error('smiley_not_found'); |
|
1327 | + } |
|
1269 | 1328 | |
1270 | 1329 | if (!empty($_GET['after'])) |
1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
1281 | 1340 | 'after_smiley' => $_GET['after'], |
1282 | 1341 | ) |
1283 | 1342 | ); |
1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1285 | - fatal_lang_error('smiley_not_found'); |
|
1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1344 | + fatal_lang_error('smiley_not_found'); |
|
1345 | + } |
|
1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
1287 | 1347 | $smcFunc['db_free_result']($request); |
1288 | - } |
|
1289 | - else |
|
1348 | + } else |
|
1290 | 1349 | { |
1291 | 1350 | $smiley_row = (int) $_GET['row']; |
1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
1361 | 1420 | |
1362 | 1421 | // Make sure all rows are sequential. |
1363 | - foreach (array_keys($context['smileys']) as $location) |
|
1364 | - $context['smileys'][$location] = array( |
|
1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
1423 | + $context['smileys'][$location] = array( |
|
1365 | 1424 | 'id' => $location, |
1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
1370 | 1429 | ); |
1430 | + } |
|
1371 | 1431 | |
1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
1393 | 1453 | } |
1394 | 1454 | // Make sure the smiley order is always sequential. |
1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
1396 | - if ($order_id != $smiley['order']) |
|
1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
1456 | + if ($order_id != $smiley['order']) |
|
1397 | 1457 | $smcFunc['db_query']('', ' |
1398 | 1458 | UPDATE {db_prefix}smileys |
1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
1403 | 1463 | 'current_smiley' => $smiley['id'], |
1404 | 1464 | ) |
1405 | 1465 | ); |
1466 | + } |
|
1406 | 1467 | } |
1407 | 1468 | } |
1408 | 1469 | |
@@ -1435,19 +1496,20 @@ discard block |
||
1435 | 1496 | $context['filename'] = $base_name; |
1436 | 1497 | |
1437 | 1498 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
1438 | - if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
1439 | - fatal_lang_error('not_on_simplemachines'); |
|
1499 | + if (preg_match('~^http://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
1500 | + fatal_lang_error('not_on_simplemachines'); |
|
1501 | + } |
|
1440 | 1502 | |
1441 | 1503 | $destination = $packagesdir . '/' . $base_name; |
1442 | 1504 | |
1443 | - if (file_exists($destination)) |
|
1444 | - fatal_lang_error('package_upload_error_exists'); |
|
1505 | + if (file_exists($destination)) { |
|
1506 | + fatal_lang_error('package_upload_error_exists'); |
|
1507 | + } |
|
1445 | 1508 | |
1446 | 1509 | // Let's copy it to the Packages directory |
1447 | 1510 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
1448 | 1511 | $testing = true; |
1449 | - } |
|
1450 | - elseif (isset($_REQUEST['package'])) |
|
1512 | + } elseif (isset($_REQUEST['package'])) |
|
1451 | 1513 | { |
1452 | 1514 | $base_name = basename($_REQUEST['package']); |
1453 | 1515 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1456,12 +1518,14 @@ discard block |
||
1456 | 1518 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
1457 | 1519 | } |
1458 | 1520 | |
1459 | - if (empty($destination) || !file_exists($destination)) |
|
1460 | - fatal_lang_error('package_no_file', false); |
|
1521 | + if (empty($destination) || !file_exists($destination)) { |
|
1522 | + fatal_lang_error('package_no_file', false); |
|
1523 | + } |
|
1461 | 1524 | |
1462 | 1525 | // Make sure temp directory exists and is empty. |
1463 | - if (file_exists($packagesdir . '/temp')) |
|
1464 | - deltree($packagesdir . '/temp', false); |
|
1526 | + if (file_exists($packagesdir . '/temp')) { |
|
1527 | + deltree($packagesdir . '/temp', false); |
|
1528 | + } |
|
1465 | 1529 | |
1466 | 1530 | if (!mktree($packagesdir . '/temp', 0755)) |
1467 | 1531 | { |
@@ -1473,31 +1537,37 @@ discard block |
||
1473 | 1537 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
1474 | 1538 | |
1475 | 1539 | deltree($packagesdir . '/temp', false); |
1476 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
1477 | - fatal_lang_error('package_cant_download', false); |
|
1540 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
1541 | + fatal_lang_error('package_cant_download', false); |
|
1542 | + } |
|
1478 | 1543 | } |
1479 | 1544 | } |
1480 | 1545 | |
1481 | 1546 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
1482 | - if (!$extracted) |
|
1483 | - fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1484 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1485 | - foreach ($extracted as $file) |
|
1547 | + if (!$extracted) { |
|
1548 | + fatal_lang_error('packageget_unable', false, array('http://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1549 | + } |
|
1550 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1551 | + foreach ($extracted as $file) |
|
1486 | 1552 | if (basename($file['filename']) == 'package-info.xml') |
1487 | 1553 | { |
1488 | 1554 | $base_path = dirname($file['filename']) . '/'; |
1555 | + } |
|
1489 | 1556 | break; |
1490 | 1557 | } |
1491 | 1558 | |
1492 | - if (!isset($base_path)) |
|
1493 | - $base_path = ''; |
|
1559 | + if (!isset($base_path)) { |
|
1560 | + $base_path = ''; |
|
1561 | + } |
|
1494 | 1562 | |
1495 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
1496 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
1563 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
1564 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
1565 | + } |
|
1497 | 1566 | |
1498 | 1567 | $smileyInfo = getPackageInfo($context['filename']); |
1499 | - if (!is_array($smileyInfo)) |
|
1500 | - fatal_lang_error($smileyInfo); |
|
1568 | + if (!is_array($smileyInfo)) { |
|
1569 | + fatal_lang_error($smileyInfo); |
|
1570 | + } |
|
1501 | 1571 | |
1502 | 1572 | // See if it is installed? |
1503 | 1573 | $request = $smcFunc['db_query']('', ' |
@@ -1513,8 +1583,9 @@ discard block |
||
1513 | 1583 | ) |
1514 | 1584 | ); |
1515 | 1585 | |
1516 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1517 | - fata_lang_error('package_installed_warning1'); |
|
1586 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1587 | + fata_lang_error('package_installed_warning1'); |
|
1588 | + } |
|
1518 | 1589 | |
1519 | 1590 | // Everything is fine, now it's time to do something |
1520 | 1591 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1531,23 +1602,23 @@ discard block |
||
1531 | 1602 | { |
1532 | 1603 | $has_readme = true; |
1533 | 1604 | $type = 'package_' . $action['type']; |
1534 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
1535 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1536 | - elseif (file_exists($action['filename'])) |
|
1537 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1605 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
1606 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1607 | + } elseif (file_exists($action['filename'])) { |
|
1608 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1609 | + } |
|
1538 | 1610 | |
1539 | 1611 | if (!empty($action['parse_bbc'])) |
1540 | 1612 | { |
1541 | 1613 | require_once($sourcedir . '/Subs-Post.php'); |
1542 | 1614 | preparsecode($context[$type]); |
1543 | 1615 | $context[$type] = parse_bbc($context[$type]); |
1616 | + } else { |
|
1617 | + $context[$type] = nl2br($context[$type]); |
|
1544 | 1618 | } |
1545 | - else |
|
1546 | - $context[$type] = nl2br($context[$type]); |
|
1547 | 1619 | |
1548 | 1620 | continue; |
1549 | - } |
|
1550 | - elseif ($action['type'] == 'require-dir') |
|
1621 | + } elseif ($action['type'] == 'require-dir') |
|
1551 | 1622 | { |
1552 | 1623 | // Do this one... |
1553 | 1624 | $thisAction = array( |
@@ -1566,12 +1637,12 @@ discard block |
||
1566 | 1637 | ); |
1567 | 1638 | } |
1568 | 1639 | // @todo None given? |
1569 | - if (empty($thisAction['description'])) |
|
1570 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1640 | + if (empty($thisAction['description'])) { |
|
1641 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1642 | + } |
|
1571 | 1643 | |
1572 | 1644 | $context['actions'][] = $thisAction; |
1573 | - } |
|
1574 | - elseif ($action['type'] == 'credits') |
|
1645 | + } elseif ($action['type'] == 'credits') |
|
1575 | 1646 | { |
1576 | 1647 | // Time to build the billboard |
1577 | 1648 | $credits_tag = array( |
@@ -1630,12 +1701,14 @@ discard block |
||
1630 | 1701 | cache_put_data('posting_smileys', null, 480); |
1631 | 1702 | } |
1632 | 1703 | |
1633 | - if (file_exists($packagesdir . '/temp')) |
|
1634 | - deltree($packagesdir . '/temp'); |
|
1704 | + if (file_exists($packagesdir . '/temp')) { |
|
1705 | + deltree($packagesdir . '/temp'); |
|
1706 | + } |
|
1635 | 1707 | |
1636 | - if (!$testing) |
|
1637 | - redirectexit('action=admin;area=smileys'); |
|
1638 | -} |
|
1708 | + if (!$testing) { |
|
1709 | + redirectexit('action=admin;area=smileys'); |
|
1710 | + } |
|
1711 | + } |
|
1639 | 1712 | |
1640 | 1713 | /** |
1641 | 1714 | * A function to import new smileys from an existing directory into the database. |
@@ -1646,15 +1719,17 @@ discard block |
||
1646 | 1719 | { |
1647 | 1720 | global $modSettings, $smcFunc; |
1648 | 1721 | |
1649 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
1650 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
1722 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
1723 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
1724 | + } |
|
1651 | 1725 | |
1652 | 1726 | $smileys = array(); |
1653 | 1727 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
1654 | 1728 | while ($entry = $dir->read()) |
1655 | 1729 | { |
1656 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1657 | - $smileys[strtolower($entry)] = $entry; |
|
1730 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1731 | + $smileys[strtolower($entry)] = $entry; |
|
1732 | + } |
|
1658 | 1733 | } |
1659 | 1734 | $dir->close(); |
1660 | 1735 | |
@@ -1667,9 +1742,10 @@ discard block |
||
1667 | 1742 | 'smiley_list' => $smileys, |
1668 | 1743 | ) |
1669 | 1744 | ); |
1670 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1671 | - if (isset($smileys[strtolower($row['filename'])])) |
|
1745 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1746 | + if (isset($smileys[strtolower($row['filename'])])) |
|
1672 | 1747 | unset($smileys[strtolower($row['filename'])]); |
1748 | + } |
|
1673 | 1749 | $smcFunc['db_free_result']($request); |
1674 | 1750 | |
1675 | 1751 | $request = $smcFunc['db_query']('', ' |
@@ -1686,9 +1762,10 @@ discard block |
||
1686 | 1762 | $smcFunc['db_free_result']($request); |
1687 | 1763 | |
1688 | 1764 | $new_smileys = array(); |
1689 | - foreach ($smileys as $smiley) |
|
1690 | - if (strlen($smiley) <= 48) |
|
1765 | + foreach ($smileys as $smiley) { |
|
1766 | + if (strlen($smiley) <= 48) |
|
1691 | 1767 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
1768 | + } |
|
1692 | 1769 | |
1693 | 1770 | if (!empty($new_smileys)) |
1694 | 1771 | { |
@@ -1753,8 +1830,9 @@ discard block |
||
1753 | 1830 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
1754 | 1831 | { |
1755 | 1832 | $deleteIcons = array(); |
1756 | - foreach ($_POST['checked_icons'] as $icon) |
|
1757 | - $deleteIcons[] = (int) $icon; |
|
1833 | + foreach ($_POST['checked_icons'] as $icon) { |
|
1834 | + $deleteIcons[] = (int) $icon; |
|
1835 | + } |
|
1758 | 1836 | |
1759 | 1837 | // Do the actual delete! |
1760 | 1838 | $smcFunc['db_query']('', ' |
@@ -1771,35 +1849,41 @@ discard block |
||
1771 | 1849 | $_GET['icon'] = (int) $_GET['icon']; |
1772 | 1850 | |
1773 | 1851 | // Do some preperation with the data... like check the icon exists *somewhere* |
1774 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
1775 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1776 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
1777 | - fatal_lang_error('icon_not_found'); |
|
1852 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
1853 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1854 | + } |
|
1855 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
1856 | + fatal_lang_error('icon_not_found'); |
|
1857 | + } |
|
1778 | 1858 | // There is a 16 character limit on message icons... |
1779 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
1780 | - fatal_lang_error('icon_name_too_long'); |
|
1781 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
1782 | - fatal_lang_error('icon_after_itself'); |
|
1859 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
1860 | + fatal_lang_error('icon_name_too_long'); |
|
1861 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
1862 | + fatal_lang_error('icon_after_itself'); |
|
1863 | + } |
|
1783 | 1864 | |
1784 | 1865 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
1785 | 1866 | if ($_GET['icon'] != 0) |
1786 | 1867 | { |
1787 | 1868 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
1788 | - foreach ($context['icons'] as $id => $data) |
|
1789 | - if ($data['true_order'] > $oldOrder) |
|
1869 | + foreach ($context['icons'] as $id => $data) { |
|
1870 | + if ($data['true_order'] > $oldOrder) |
|
1790 | 1871 | $context['icons'][$id]['true_order']--; |
1872 | + } |
|
1791 | 1873 | } |
1792 | 1874 | |
1793 | 1875 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
1794 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
1795 | - $_GET['icon'] = 1; |
|
1876 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
1877 | + $_GET['icon'] = 1; |
|
1878 | + } |
|
1796 | 1879 | |
1797 | 1880 | // Get the new order. |
1798 | 1881 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
1799 | 1882 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
1800 | - foreach ($context['icons'] as $id => $data) |
|
1801 | - if ($data['true_order'] >= $newOrder) |
|
1883 | + foreach ($context['icons'] as $id => $data) { |
|
1884 | + if ($data['true_order'] >= $newOrder) |
|
1802 | 1885 | $context['icons'][$id]['true_order']++; |
1886 | + } |
|
1803 | 1887 | |
1804 | 1888 | // Finally set the current icon's position! |
1805 | 1889 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1817,8 +1901,7 @@ discard block |
||
1817 | 1901 | if ($id != 0) |
1818 | 1902 | { |
1819 | 1903 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1820 | - } |
|
1821 | - else |
|
1904 | + } else |
|
1822 | 1905 | { |
1823 | 1906 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1824 | 1907 | } |
@@ -1843,8 +1926,9 @@ discard block |
||
1843 | 1926 | } |
1844 | 1927 | |
1845 | 1928 | // Unless we're adding a new thing, we'll escape |
1846 | - if (!isset($_POST['add'])) |
|
1847 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1929 | + if (!isset($_POST['add'])) { |
|
1930 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1931 | + } |
|
1848 | 1932 | } |
1849 | 1933 | |
1850 | 1934 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1954,8 +2038,9 @@ discard block |
||
1954 | 2038 | $context['new_icon'] = !isset($_GET['icon']); |
1955 | 2039 | |
1956 | 2040 | // Get the properties of the current icon from the icon list. |
1957 | - if (!$context['new_icon']) |
|
1958 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2041 | + if (!$context['new_icon']) { |
|
2042 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2043 | + } |
|
1959 | 2044 | |
1960 | 2045 | // Get a list of boards needed for assigning this icon to a specific board. |
1961 | 2046 | $boardListOptions = array( |
@@ -1989,8 +2074,9 @@ discard block |
||
1989 | 2074 | ); |
1990 | 2075 | |
1991 | 2076 | $message_icons = array(); |
1992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1993 | - $message_icons[] = $row; |
|
2077 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2078 | + $message_icons[] = $row; |
|
2079 | + } |
|
1994 | 2080 | $smcFunc['db_free_result']($request); |
1995 | 2081 | |
1996 | 2082 | return $message_icons; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
54 | 55 | 'themes', 'topics'); |
55 | - foreach ($reservedTables as $k => $table_name) |
|
56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
56 | + foreach ($reservedTables as $k => $table_name) { |
|
57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | // We in turn may need the extra stuff. |
59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
106 | 108 | |
107 | 109 | // First - no way do we touch SMF tables. |
108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
109 | - return false; |
|
110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
111 | + return false; |
|
112 | + } |
|
110 | 113 | |
111 | 114 | // Log that we'll want to remove this on uninstall. |
112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
116 | 119 | if (in_array($full_table_name, $tables)) |
117 | 120 | { |
118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
119 | - if ($if_exists == 'overwrite') |
|
120 | - $smcFunc['db_drop_table']($table_name); |
|
121 | - else |
|
122 | - return $if_exists == 'ignore'; |
|
122 | + if ($if_exists == 'overwrite') { |
|
123 | + $smcFunc['db_drop_table']($table_name); |
|
124 | + } else { |
|
125 | + return $if_exists == 'ignore'; |
|
126 | + } |
|
123 | 127 | } |
124 | 128 | |
125 | 129 | // Righty - let's do the damn thing! |
126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
127 | - foreach ($columns as $column) |
|
128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
131 | + foreach ($columns as $column) { |
|
132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
133 | + } |
|
129 | 134 | |
130 | 135 | // Loop through the indexes next... |
131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
133 | 138 | $columns = implode(',', $index['columns']); |
134 | 139 | |
135 | 140 | // Is it the primary? |
136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
138 | - else |
|
141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
143 | + } else |
|
139 | 144 | { |
140 | - if (empty($index['name'])) |
|
141 | - $index['name'] = implode('_', $index['columns']); |
|
145 | + if (empty($index['name'])) { |
|
146 | + $index['name'] = implode('_', $index['columns']); |
|
147 | + } |
|
142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
143 | 149 | } |
144 | 150 | } |
145 | 151 | |
146 | 152 | // No trailing commas! |
147 | - if (substr($table_query, -1) == ',') |
|
148 | - $table_query = substr($table_query, 0, -1); |
|
153 | + if (substr($table_query, -1) == ',') { |
|
154 | + $table_query = substr($table_query, 0, -1); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // Which engine do we want here? |
151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | |
156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
157 | 164 | { |
158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
159 | - $engines[] = $row['Engine']; |
|
165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
166 | + $engines[] = $row['Engine']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
170 | 178 | } |
171 | 179 | |
172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | // Create the table! |
177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
204 | 213 | |
205 | 214 | // God no - dropping one of these = bad. |
206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
207 | - return false; |
|
215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
216 | + return false; |
|
217 | + } |
|
208 | 218 | |
209 | 219 | // Does it exist? |
210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
245 | 255 | |
246 | 256 | // Does it exist - if so don't add it again! |
247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
248 | - foreach ($columns as $column) |
|
249 | - if ($column == $column_info['name']) |
|
258 | + foreach ($columns as $column) { |
|
259 | + if ($column == $column_info['name']) |
|
250 | 260 | { |
251 | 261 | // If we're going to overwrite then use change column. |
252 | 262 | if ($if_exists == 'update') |
253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
254 | - else |
|
255 | - return false; |
|
264 | + } |
|
265 | + else { |
|
266 | + return false; |
|
267 | + } |
|
256 | 268 | } |
257 | 269 | |
258 | 270 | // Get the specifics... |
@@ -288,8 +300,8 @@ discard block |
||
288 | 300 | |
289 | 301 | // Does it exist? |
290 | 302 | $columns = $smcFunc['db_list_columns']($table_name, true); |
291 | - foreach ($columns as $column) |
|
292 | - if ($column['name'] == $column_name) |
|
303 | + foreach ($columns as $column) { |
|
304 | + if ($column['name'] == $column_name) |
|
293 | 305 | { |
294 | 306 | $smcFunc['db_query']('', ' |
295 | 307 | ALTER TABLE ' . $table_name . ' |
@@ -298,6 +310,7 @@ discard block |
||
298 | 310 | 'security_override' => true, |
299 | 311 | ) |
300 | 312 | ); |
313 | + } |
|
301 | 314 | |
302 | 315 | return true; |
303 | 316 | } |
@@ -324,37 +337,47 @@ discard block |
||
324 | 337 | // Check it does exist! |
325 | 338 | $columns = $smcFunc['db_list_columns']($table_name, true); |
326 | 339 | $old_info = null; |
327 | - foreach ($columns as $column) |
|
328 | - if ($column['name'] == $old_column) |
|
340 | + foreach ($columns as $column) { |
|
341 | + if ($column['name'] == $old_column) |
|
329 | 342 | $old_info = $column; |
343 | + } |
|
330 | 344 | |
331 | 345 | // Nothing? |
332 | - if ($old_info == null) |
|
333 | - return false; |
|
346 | + if ($old_info == null) { |
|
347 | + return false; |
|
348 | + } |
|
334 | 349 | |
335 | 350 | // Get the right bits. |
336 | - if (!isset($column_info['name'])) |
|
337 | - $column_info['name'] = $old_column; |
|
338 | - if (!isset($column_info['default'])) |
|
339 | - $column_info['default'] = $old_info['default']; |
|
340 | - if (!isset($column_info['null'])) |
|
341 | - $column_info['null'] = $old_info['null']; |
|
342 | - if (!isset($column_info['auto'])) |
|
343 | - $column_info['auto'] = $old_info['auto']; |
|
344 | - if (!isset($column_info['type'])) |
|
345 | - $column_info['type'] = $old_info['type']; |
|
346 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
347 | - $column_info['size'] = $old_info['size']; |
|
348 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
349 | - $column_info['unsigned'] = ''; |
|
351 | + if (!isset($column_info['name'])) { |
|
352 | + $column_info['name'] = $old_column; |
|
353 | + } |
|
354 | + if (!isset($column_info['default'])) { |
|
355 | + $column_info['default'] = $old_info['default']; |
|
356 | + } |
|
357 | + if (!isset($column_info['null'])) { |
|
358 | + $column_info['null'] = $old_info['null']; |
|
359 | + } |
|
360 | + if (!isset($column_info['auto'])) { |
|
361 | + $column_info['auto'] = $old_info['auto']; |
|
362 | + } |
|
363 | + if (!isset($column_info['type'])) { |
|
364 | + $column_info['type'] = $old_info['type']; |
|
365 | + } |
|
366 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
367 | + $column_info['size'] = $old_info['size']; |
|
368 | + } |
|
369 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
370 | + $column_info['unsigned'] = ''; |
|
371 | + } |
|
350 | 372 | |
351 | 373 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
352 | 374 | |
353 | 375 | // Allow for unsigned integers (mysql only) |
354 | 376 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
355 | 377 | |
356 | - if ($size !== null) |
|
357 | - $type = $type . '(' . $size . ')'; |
|
378 | + if ($size !== null) { |
|
379 | + $type = $type . '(' . $size . ')'; |
|
380 | + } |
|
358 | 381 | |
359 | 382 | $smcFunc['db_query']('', ' |
360 | 383 | ALTER TABLE ' . $table_name . ' |
@@ -384,21 +407,23 @@ discard block |
||
384 | 407 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
385 | 408 | |
386 | 409 | // No columns = no index. |
387 | - if (empty($index_info['columns'])) |
|
388 | - return false; |
|
410 | + if (empty($index_info['columns'])) { |
|
411 | + return false; |
|
412 | + } |
|
389 | 413 | $columns = implode(',', $index_info['columns']); |
390 | 414 | |
391 | 415 | // No name - make it up! |
392 | 416 | if (empty($index_info['name'])) |
393 | 417 | { |
394 | 418 | // No need for primary. |
395 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
396 | - $index_info['name'] = ''; |
|
397 | - else |
|
398 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
419 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
420 | + $index_info['name'] = ''; |
|
421 | + } else { |
|
422 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
423 | + } |
|
424 | + } else { |
|
425 | + $index_info['name'] = $index_info['name']; |
|
399 | 426 | } |
400 | - else |
|
401 | - $index_info['name'] = $index_info['name']; |
|
402 | 427 | |
403 | 428 | // Log that we are going to want to remove this! |
404 | 429 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -411,10 +436,11 @@ discard block |
||
411 | 436 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
412 | 437 | { |
413 | 438 | // If we want to overwrite simply remove the current one then continue. |
414 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
415 | - return false; |
|
416 | - else |
|
417 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
439 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
440 | + return false; |
|
441 | + } else { |
|
442 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
443 | + } |
|
418 | 444 | } |
419 | 445 | } |
420 | 446 | |
@@ -428,8 +454,7 @@ discard block |
||
428 | 454 | 'security_override' => true, |
429 | 455 | ) |
430 | 456 | ); |
431 | - } |
|
432 | - else |
|
457 | + } else |
|
433 | 458 | { |
434 | 459 | $smcFunc['db_query']('', ' |
435 | 460 | ALTER TABLE ' . $table_name . ' |
@@ -513,8 +538,7 @@ discard block |
||
513 | 538 | $types = array( |
514 | 539 | 'inet' => 'varbinary', |
515 | 540 | ); |
516 | - } |
|
517 | - else |
|
541 | + } else |
|
518 | 542 | { |
519 | 543 | $types = array( |
520 | 544 | 'varbinary' => 'inet', |
@@ -528,16 +552,15 @@ discard block |
||
528 | 552 | { |
529 | 553 | $type_size = 16; |
530 | 554 | $type_name = 'varbinary'; |
531 | - } |
|
532 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
555 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
533 | 556 | { |
534 | 557 | $type_name = 'inet'; |
535 | 558 | $type_size = null; |
559 | + } elseif ($type_name == 'varbinary') { |
|
560 | + $type_name = 'varbinary'; |
|
561 | + } else { |
|
562 | + $type_name = $types[$type_name]; |
|
536 | 563 | } |
537 | - elseif ($type_name == 'varbinary') |
|
538 | - $type_name = 'varbinary'; |
|
539 | - else |
|
540 | - $type_name = $types[$type_name]; |
|
541 | 564 | } |
542 | 565 | |
543 | 566 | return array($type_name, $type_size); |
@@ -605,8 +628,7 @@ discard block |
||
605 | 628 | if (!$detail) |
606 | 629 | { |
607 | 630 | $columns[] = $row['Field']; |
608 | - } |
|
609 | - else |
|
631 | + } else |
|
610 | 632 | { |
611 | 633 | // Is there an auto_increment? |
612 | 634 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -616,10 +638,10 @@ discard block |
||
616 | 638 | { |
617 | 639 | $type = $matches[1]; |
618 | 640 | $size = $matches[2]; |
619 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
620 | - $unsigned = true; |
|
621 | - } |
|
622 | - else |
|
641 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
642 | + $unsigned = true; |
|
643 | + } |
|
644 | + } else |
|
623 | 645 | { |
624 | 646 | $type = $row['Type']; |
625 | 647 | $size = null; |
@@ -670,19 +692,20 @@ discard block |
||
670 | 692 | $indexes = array(); |
671 | 693 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
672 | 694 | { |
673 | - if (!$detail) |
|
674 | - $indexes[] = $row['Key_name']; |
|
675 | - else |
|
695 | + if (!$detail) { |
|
696 | + $indexes[] = $row['Key_name']; |
|
697 | + } else |
|
676 | 698 | { |
677 | 699 | // What is the type? |
678 | - if ($row['Key_name'] == 'PRIMARY') |
|
679 | - $type = 'primary'; |
|
680 | - elseif (empty($row['Non_unique'])) |
|
681 | - $type = 'unique'; |
|
682 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
683 | - $type = 'fulltext'; |
|
684 | - else |
|
685 | - $type = 'index'; |
|
700 | + if ($row['Key_name'] == 'PRIMARY') { |
|
701 | + $type = 'primary'; |
|
702 | + } elseif (empty($row['Non_unique'])) { |
|
703 | + $type = 'unique'; |
|
704 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
705 | + $type = 'fulltext'; |
|
706 | + } else { |
|
707 | + $type = 'index'; |
|
708 | + } |
|
686 | 709 | |
687 | 710 | // This is the first column we've seen? |
688 | 711 | if (empty($indexes[$row['Key_name']])) |
@@ -695,10 +718,11 @@ discard block |
||
695 | 718 | } |
696 | 719 | |
697 | 720 | // Is it a partial index? |
698 | - if (!empty($row['Sub_part'])) |
|
699 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
700 | - else |
|
701 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
721 | + if (!empty($row['Sub_part'])) { |
|
722 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
723 | + } else { |
|
724 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
725 | + } |
|
702 | 726 | } |
703 | 727 | } |
704 | 728 | $smcFunc['db_free_result']($result); |
@@ -720,11 +744,11 @@ discard block |
||
720 | 744 | if (!empty($column['auto'])) |
721 | 745 | { |
722 | 746 | $default = 'auto_increment'; |
747 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
748 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
749 | + } else { |
|
750 | + $default = ''; |
|
723 | 751 | } |
724 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
725 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
726 | - else |
|
727 | - $default = ''; |
|
728 | 752 | |
729 | 753 | // Sort out the size... and stuff... |
730 | 754 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -733,8 +757,9 @@ discard block |
||
733 | 757 | // Allow unsigned integers (mysql only) |
734 | 758 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
735 | 759 | |
736 | - if ($size !== null) |
|
737 | - $type = $type . '(' . $size . ')'; |
|
760 | + if ($size !== null) { |
|
761 | + $type = $type . '(' . $size . ')'; |
|
762 | + } |
|
738 | 763 | |
739 | 764 | // Now just put it together! |
740 | 765 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | /** |
@@ -44,8 +45,9 @@ discard block |
||
44 | 45 | $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings'); |
45 | 46 | |
46 | 47 | // Is it elsewhere? |
47 | - if (isset($subActions[$_REQUEST['sa']][2])) |
|
48 | - require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
48 | + if (isset($subActions[$_REQUEST['sa']][2])) { |
|
49 | + require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | // Do the permission check, you might not be allowed her. |
51 | 53 | isAllowedTo($subActions[$_REQUEST['sa']][1]); |
@@ -104,19 +106,20 @@ discard block |
||
104 | 106 | 'function' => function($rowData) use ($scripturl) |
105 | 107 | { |
106 | 108 | // Since the moderator group has no explicit members, no link is needed. |
107 | - if ($rowData['id_group'] == 3) |
|
108 | - $group_name = $rowData['group_name']; |
|
109 | - else |
|
109 | + if ($rowData['id_group'] == 3) { |
|
110 | + $group_name = $rowData['group_name']; |
|
111 | + } else |
|
110 | 112 | { |
111 | 113 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
112 | 114 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
113 | 115 | } |
114 | 116 | |
115 | 117 | // Add a help option for moderator and administrator. |
116 | - if ($rowData['id_group'] == 1) |
|
117 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | - elseif ($rowData['id_group'] == 3) |
|
119 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
118 | + if ($rowData['id_group'] == 1) { |
|
119 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
120 | + } elseif ($rowData['id_group'] == 3) { |
|
121 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
122 | + } |
|
120 | 123 | |
121 | 124 | return $group_name; |
122 | 125 | }, |
@@ -330,12 +333,14 @@ discard block |
||
330 | 333 | call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup)); |
331 | 334 | |
332 | 335 | // Update the post groups now, if this is a post group! |
333 | - if (isset($_POST['min_posts'])) |
|
334 | - updateStats('postgroups'); |
|
336 | + if (isset($_POST['min_posts'])) { |
|
337 | + updateStats('postgroups'); |
|
338 | + } |
|
335 | 339 | |
336 | 340 | // You cannot set permissions for post groups if they are disabled. |
337 | - if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) |
|
338 | - $_POST['perm_type'] = ''; |
|
341 | + if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups'])) { |
|
342 | + $_POST['perm_type'] = ''; |
|
343 | + } |
|
339 | 344 | |
340 | 345 | if ($_POST['perm_type'] == 'predefined') |
341 | 346 | { |
@@ -365,8 +370,9 @@ discard block |
||
365 | 370 | $smcFunc['db_free_result']($request); |
366 | 371 | |
367 | 372 | // Protected groups are... well, protected! |
368 | - if ($copy_type == 1) |
|
369 | - fatal_lang_error('membergroup_does_not_exist'); |
|
373 | + if ($copy_type == 1) { |
|
374 | + fatal_lang_error('membergroup_does_not_exist'); |
|
375 | + } |
|
370 | 376 | } |
371 | 377 | |
372 | 378 | // Don't allow copying of a real priviledged person! |
@@ -384,18 +390,20 @@ discard block |
||
384 | 390 | $inserts = array(); |
385 | 391 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
386 | 392 | { |
387 | - if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) |
|
388 | - $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
393 | + if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions'])) { |
|
394 | + $inserts[] = array($id_group, $row['permission'], $row['add_deny']); |
|
395 | + } |
|
389 | 396 | } |
390 | 397 | $smcFunc['db_free_result']($request); |
391 | 398 | |
392 | - if (!empty($inserts)) |
|
393 | - $smcFunc['db_insert']('insert', |
|
399 | + if (!empty($inserts)) { |
|
400 | + $smcFunc['db_insert']('insert', |
|
394 | 401 | '{db_prefix}permissions', |
395 | 402 | array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
396 | 403 | $inserts, |
397 | 404 | array('id_group', 'permission') |
398 | 405 | ); |
406 | + } |
|
399 | 407 | |
400 | 408 | $request = $smcFunc['db_query']('', ' |
401 | 409 | SELECT id_profile, permission, add_deny |
@@ -406,17 +414,19 @@ discard block |
||
406 | 414 | ) |
407 | 415 | ); |
408 | 416 | $inserts = array(); |
409 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
410 | - $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
417 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
418 | + $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']); |
|
419 | + } |
|
411 | 420 | $smcFunc['db_free_result']($request); |
412 | 421 | |
413 | - if (!empty($inserts)) |
|
414 | - $smcFunc['db_insert']('insert', |
|
422 | + if (!empty($inserts)) { |
|
423 | + $smcFunc['db_insert']('insert', |
|
415 | 424 | '{db_prefix}board_permissions', |
416 | 425 | array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), |
417 | 426 | $inserts, |
418 | 427 | array('id_group', 'id_profile', 'permission') |
419 | 428 | ); |
429 | + } |
|
420 | 430 | |
421 | 431 | // Also get some membergroup information if we're copying and not copying from guests... |
422 | 432 | if ($copy_id > 0 && $_POST['perm_type'] == 'copy') |
@@ -469,14 +479,15 @@ discard block |
||
469 | 479 | $changed_boards['allow'] = array(); |
470 | 480 | $changed_boards['deny'] = array(); |
471 | 481 | $changed_boards['ignore'] = array(); |
472 | - foreach ($accesses as $group_id => $action) |
|
473 | - $changed_boards[$action][] = (int) $group_id; |
|
482 | + foreach ($accesses as $group_id => $action) { |
|
483 | + $changed_boards[$action][] = (int) $group_id; |
|
484 | + } |
|
474 | 485 | |
475 | 486 | foreach (array('allow', 'deny') as $board_action) |
476 | 487 | { |
477 | 488 | // Only do this if they have special access requirements. |
478 | - if (!empty($changed_boards[$board_action])) |
|
479 | - $smcFunc['db_query']('', ' |
|
489 | + if (!empty($changed_boards[$board_action])) { |
|
490 | + $smcFunc['db_query']('', ' |
|
480 | 491 | UPDATE {db_prefix}boards |
481 | 492 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
482 | 493 | WHERE id_board IN ({array_int:board_list})', |
@@ -488,11 +499,13 @@ discard block |
||
488 | 499 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
489 | 500 | ) |
490 | 501 | ); |
502 | + } |
|
491 | 503 | } |
492 | 504 | |
493 | 505 | // If this is joinable then set it to show group membership in people's profiles. |
494 | - if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) |
|
495 | - updateSettings(array('show_group_membership' => 1)); |
|
506 | + if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1) { |
|
507 | + updateSettings(array('show_group_membership' => 1)); |
|
508 | + } |
|
496 | 509 | |
497 | 510 | // Rebuild the group cache. |
498 | 511 | updateSettings(array( |
@@ -513,8 +526,9 @@ discard block |
||
513 | 526 | $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']); |
514 | 527 | $context['allow_protected'] = allowedTo('admin_forum'); |
515 | 528 | |
516 | - if (!empty($modSettings['deny_boards_access'])) |
|
517 | - loadLanguage('ManagePermissions'); |
|
529 | + if (!empty($modSettings['deny_boards_access'])) { |
|
530 | + loadLanguage('ManagePermissions'); |
|
531 | + } |
|
518 | 532 | |
519 | 533 | $result = $smcFunc['db_query']('', ' |
520 | 534 | SELECT id_group, group_name |
@@ -531,11 +545,12 @@ discard block |
||
531 | 545 | ) |
532 | 546 | ); |
533 | 547 | $context['groups'] = array(); |
534 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
535 | - $context['groups'][] = array( |
|
548 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
549 | + $context['groups'][] = array( |
|
536 | 550 | 'id' => $row['id_group'], |
537 | 551 | 'name' => $row['group_name'] |
538 | 552 | ); |
553 | + } |
|
539 | 554 | $smcFunc['db_free_result']($result); |
540 | 555 | |
541 | 556 | $request = $smcFunc['db_query']('', ' |
@@ -552,12 +567,13 @@ discard block |
||
552 | 567 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
553 | 568 | { |
554 | 569 | // This category hasn't been set up yet.. |
555 | - if (!isset($context['categories'][$row['id_cat']])) |
|
556 | - $context['categories'][$row['id_cat']] = array( |
|
570 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
571 | + $context['categories'][$row['id_cat']] = array( |
|
557 | 572 | 'id' => $row['id_cat'], |
558 | 573 | 'name' => $row['cat_name'], |
559 | 574 | 'boards' => array() |
560 | 575 | ); |
576 | + } |
|
561 | 577 | |
562 | 578 | // Set this board up, and let the template know when it's a child. (indent them..) |
563 | 579 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -605,8 +621,9 @@ discard block |
||
605 | 621 | require_once($sourcedir . '/Subs-Membergroups.php'); |
606 | 622 | $result = deleteMembergroups((int) $_REQUEST['group']); |
607 | 623 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
608 | - if ($result === 'group_cannot_delete_sub') |
|
609 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
624 | + if ($result === 'group_cannot_delete_sub') { |
|
625 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
626 | + } |
|
610 | 627 | |
611 | 628 | // Go back to the membergroup index. |
612 | 629 | redirectexit('action=admin;area=membergroups;'); |
@@ -628,8 +645,9 @@ discard block |
||
628 | 645 | |
629 | 646 | $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0; |
630 | 647 | |
631 | - if (!empty($modSettings['deny_boards_access'])) |
|
632 | - loadLanguage('ManagePermissions'); |
|
648 | + if (!empty($modSettings['deny_boards_access'])) { |
|
649 | + loadLanguage('ManagePermissions'); |
|
650 | + } |
|
633 | 651 | |
634 | 652 | // Make sure this group is editable. |
635 | 653 | if (!empty($_REQUEST['group'])) |
@@ -651,8 +669,9 @@ discard block |
||
651 | 669 | } |
652 | 670 | |
653 | 671 | // Now, do we have a valid id? |
654 | - if (empty($_REQUEST['group'])) |
|
655 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
672 | + if (empty($_REQUEST['group'])) { |
|
673 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
674 | + } |
|
656 | 675 | |
657 | 676 | // People who can manage boards are a bit special. |
658 | 677 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -683,8 +702,9 @@ discard block |
||
683 | 702 | require_once($sourcedir . '/Subs-Membergroups.php'); |
684 | 703 | $result = deleteMembergroups($_REQUEST['group']); |
685 | 704 | // Need to throw a warning if it went wrong, but this is the only one we have a message for... |
686 | - if ($result === 'group_cannot_delete_sub') |
|
687 | - fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
705 | + if ($result === 'group_cannot_delete_sub') { |
|
706 | + fatal_lang_error('membergroups_cannot_delete_paid', false); |
|
707 | + } |
|
688 | 708 | |
689 | 709 | redirectexit('action=admin;area=membergroups;'); |
690 | 710 | } |
@@ -761,16 +781,18 @@ discard block |
||
761 | 781 | $request = $smcFunc['db_query']('', ' |
762 | 782 | SELECT id_board |
763 | 783 | FROM {db_prefix}boards'); |
764 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
765 | - $accesses[(int) $row['id_board']] = 'allow'; |
|
784 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
785 | + $accesses[(int) $row['id_board']] = 'allow'; |
|
786 | + } |
|
766 | 787 | $smcFunc['db_free_result']($request); |
767 | 788 | } |
768 | 789 | |
769 | 790 | $changed_boards['allow'] = array(); |
770 | 791 | $changed_boards['deny'] = array(); |
771 | 792 | $changed_boards['ignore'] = array(); |
772 | - foreach ($accesses as $group_id => $action) |
|
773 | - $changed_boards[$action][] = (int) $group_id; |
|
793 | + foreach ($accesses as $group_id => $action) { |
|
794 | + $changed_boards[$action][] = (int) $group_id; |
|
795 | + } |
|
774 | 796 | |
775 | 797 | foreach (array('allow', 'deny') as $board_action) |
776 | 798 | { |
@@ -786,8 +808,8 @@ discard block |
||
786 | 808 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
787 | 809 | ) |
788 | 810 | ); |
789 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
790 | - $smcFunc['db_query']('', ' |
|
811 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
812 | + $smcFunc['db_query']('', ' |
|
791 | 813 | UPDATE {db_prefix}boards |
792 | 814 | SET {raw:column} = {string:member_group_access} |
793 | 815 | WHERE id_board = {int:current_board}', |
@@ -797,11 +819,12 @@ discard block |
||
797 | 819 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
798 | 820 | ) |
799 | 821 | ); |
822 | + } |
|
800 | 823 | $smcFunc['db_free_result']($request); |
801 | 824 | |
802 | 825 | // Add the membergroup to all boards that hadn't been set yet. |
803 | - if (!empty($changed_boards[$board_action])) |
|
804 | - $smcFunc['db_query']('', ' |
|
826 | + if (!empty($changed_boards[$board_action])) { |
|
827 | + $smcFunc['db_query']('', ' |
|
805 | 828 | UPDATE {db_prefix}boards |
806 | 829 | SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END |
807 | 830 | WHERE id_board IN ({array_int:board_list}) |
@@ -815,6 +838,7 @@ discard block |
||
815 | 838 | 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups', |
816 | 839 | ) |
817 | 840 | ); |
841 | + } |
|
818 | 842 | } |
819 | 843 | } |
820 | 844 | |
@@ -840,12 +864,14 @@ discard block |
||
840 | 864 | ) |
841 | 865 | ); |
842 | 866 | $updates = array(); |
843 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
844 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
867 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
868 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
869 | + } |
|
845 | 870 | $smcFunc['db_free_result']($request); |
846 | 871 | |
847 | - foreach ($updates as $additional_groups => $memberArray) |
|
848 | - updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
872 | + foreach ($updates as $additional_groups => $memberArray) { |
|
873 | + updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group']))))); |
|
874 | + } |
|
849 | 875 | |
850 | 876 | // Sorry, but post groups can't moderate boards |
851 | 877 | $smcFunc['db_query']('', ' |
@@ -855,8 +881,7 @@ discard block |
||
855 | 881 | 'current_group' => (int) $_REQUEST['group'], |
856 | 882 | ) |
857 | 883 | ); |
858 | - } |
|
859 | - elseif ($_REQUEST['group'] != 3) |
|
884 | + } elseif ($_REQUEST['group'] != 3) |
|
860 | 885 | { |
861 | 886 | // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional). |
862 | 887 | if ($_POST['group_hidden'] == 2) |
@@ -871,8 +896,9 @@ discard block |
||
871 | 896 | ) |
872 | 897 | ); |
873 | 898 | $updates = array(); |
874 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
875 | - $updates[$row['additional_groups']][] = $row['id_member']; |
|
899 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
900 | + $updates[$row['additional_groups']][] = $row['id_member']; |
|
901 | + } |
|
876 | 902 | $smcFunc['db_free_result']($request); |
877 | 903 | |
878 | 904 | foreach ($updates as $additional_groups => $memberArray) |
@@ -914,8 +940,9 @@ discard block |
||
914 | 940 | $smcFunc['db_free_result']($request); |
915 | 941 | |
916 | 942 | // Do we need to update the setting? |
917 | - if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) |
|
918 | - updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
943 | + if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable)) { |
|
944 | + updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0)); |
|
945 | + } |
|
919 | 946 | } |
920 | 947 | |
921 | 948 | // Do we need to set inherited permissions? |
@@ -948,8 +975,9 @@ discard block |
||
948 | 975 | { |
949 | 976 | $moderators[$k] = trim($moderators[$k]); |
950 | 977 | |
951 | - if (strlen($moderators[$k]) == 0) |
|
952 | - unset($moderators[$k]); |
|
978 | + if (strlen($moderators[$k]) == 0) { |
|
979 | + unset($moderators[$k]); |
|
980 | + } |
|
953 | 981 | } |
954 | 982 | |
955 | 983 | // Find all the id_member's for the member_name's in the list. |
@@ -965,8 +993,9 @@ discard block |
||
965 | 993 | 'count' => count($moderators), |
966 | 994 | ) |
967 | 995 | ); |
968 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
969 | - $group_moderators[] = $row['id_member']; |
|
996 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
997 | + $group_moderators[] = $row['id_member']; |
|
998 | + } |
|
970 | 999 | $smcFunc['db_free_result']($request); |
971 | 1000 | } |
972 | 1001 | } |
@@ -974,8 +1003,9 @@ discard block |
||
974 | 1003 | if (!empty($_POST['moderator_list'])) |
975 | 1004 | { |
976 | 1005 | $moderators = array(); |
977 | - foreach ($_POST['moderator_list'] as $moderator) |
|
978 | - $moderators[] = (int) $moderator; |
|
1006 | + foreach ($_POST['moderator_list'] as $moderator) { |
|
1007 | + $moderators[] = (int) $moderator; |
|
1008 | + } |
|
979 | 1009 | |
980 | 1010 | if (!empty($moderators)) |
981 | 1011 | { |
@@ -989,8 +1019,9 @@ discard block |
||
989 | 1019 | 'num_moderators' => count($moderators), |
990 | 1020 | ) |
991 | 1021 | ); |
992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
993 | - $group_moderators[] = $row['id_member']; |
|
1022 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1023 | + $group_moderators[] = $row['id_member']; |
|
1024 | + } |
|
994 | 1025 | $smcFunc['db_free_result']($request); |
995 | 1026 | } |
996 | 1027 | } |
@@ -1002,8 +1033,9 @@ discard block |
||
1002 | 1033 | if (!empty($group_moderators)) |
1003 | 1034 | { |
1004 | 1035 | $mod_insert = array(); |
1005 | - foreach ($group_moderators as $moderator) |
|
1006 | - $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1036 | + foreach ($group_moderators as $moderator) { |
|
1037 | + $mod_insert[] = array($_REQUEST['group'], $moderator); |
|
1038 | + } |
|
1007 | 1039 | |
1008 | 1040 | $smcFunc['db_insert']('insert', |
1009 | 1041 | '{db_prefix}group_moderators', |
@@ -1037,8 +1069,9 @@ discard block |
||
1037 | 1069 | 'current_group' => (int) $_REQUEST['group'], |
1038 | 1070 | ) |
1039 | 1071 | ); |
1040 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1041 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
1072 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1073 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
1074 | + } |
|
1042 | 1075 | $row = $smcFunc['db_fetch_assoc']($request); |
1043 | 1076 | $smcFunc['db_free_result']($request); |
1044 | 1077 | |
@@ -1075,14 +1108,16 @@ discard block |
||
1075 | 1108 | ) |
1076 | 1109 | ); |
1077 | 1110 | $context['group']['moderators'] = array(); |
1078 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1079 | - $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1111 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1112 | + $context['group']['moderators'][$row['id_member']] = $row['real_name']; |
|
1113 | + } |
|
1080 | 1114 | $smcFunc['db_free_result']($request); |
1081 | 1115 | |
1082 | 1116 | $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '"' . implode('", "', $context['group']['moderators']) . '"'; |
1083 | 1117 | |
1084 | - if (!empty($context['group']['moderators'])) |
|
1085 | - list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1118 | + if (!empty($context['group']['moderators'])) { |
|
1119 | + list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1); |
|
1120 | + } |
|
1086 | 1121 | |
1087 | 1122 | // Get a list of boards this membergroup is allowed to see. |
1088 | 1123 | $context['boards'] = array(); |
@@ -1102,12 +1137,13 @@ discard block |
||
1102 | 1137 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1103 | 1138 | { |
1104 | 1139 | // This category hasn't been set up yet.. |
1105 | - if (!isset($context['categories'][$row['id_cat']])) |
|
1106 | - $context['categories'][$row['id_cat']] = array( |
|
1140 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
1141 | + $context['categories'][$row['id_cat']] = array( |
|
1107 | 1142 | 'id' => $row['id_cat'], |
1108 | 1143 | 'name' => $row['cat_name'], |
1109 | 1144 | 'boards' => array() |
1110 | 1145 | ); |
1146 | + } |
|
1111 | 1147 | |
1112 | 1148 | // Set this board up, and let the template know when it's a child. (indent them..) |
1113 | 1149 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -1155,19 +1191,22 @@ discard block |
||
1155 | 1191 | $image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value); |
1156 | 1192 | |
1157 | 1193 | // If this is bigger than 128 in width or 32 in height, skip this one. |
1158 | - if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) |
|
1159 | - continue; |
|
1194 | + if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32) { |
|
1195 | + continue; |
|
1196 | + } |
|
1160 | 1197 | |
1161 | 1198 | // Else it's valid. Add it in. |
1162 | - else |
|
1163 | - $context['possible_icons'][] = $value; |
|
1199 | + else { |
|
1200 | + $context['possible_icons'][] = $value; |
|
1201 | + } |
|
1164 | 1202 | } |
1165 | 1203 | } |
1166 | 1204 | } |
1167 | 1205 | |
1168 | 1206 | // Insert our JS, if we have possible icons. |
1169 | - if (!empty($context['possible_icons'])) |
|
1170 | - loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
1207 | + if (!empty($context['possible_icons'])) { |
|
1208 | + loadJavaScriptFile('icondropdown.js', array('validate' => true), 'smf_icondropdown'); |
|
1209 | + } |
|
1171 | 1210 | |
1172 | 1211 | loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
1173 | 1212 | |
@@ -1189,8 +1228,9 @@ discard block |
||
1189 | 1228 | ) |
1190 | 1229 | ); |
1191 | 1230 | $context['inheritable_groups'] = array(); |
1192 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1193 | - $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1231 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1232 | + $context['inheritable_groups'][$row['id_group']] = $row['group_name']; |
|
1233 | + } |
|
1194 | 1234 | $smcFunc['db_free_result']($request); |
1195 | 1235 | |
1196 | 1236 | call_integration_hook('integrate_view_membergroup'); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Update some basic statistics. |
@@ -122,10 +123,11 @@ discard block |
||
122 | 123 | $smcFunc['db_free_result']($result); |
123 | 124 | |
124 | 125 | // Add this to the number of unapproved members |
125 | - if (!empty($changes['unapprovedMembers'])) |
|
126 | - $changes['unapprovedMembers'] += $coppa_approvals; |
|
127 | - else |
|
128 | - $changes['unapprovedMembers'] = $coppa_approvals; |
|
126 | + if (!empty($changes['unapprovedMembers'])) { |
|
127 | + $changes['unapprovedMembers'] += $coppa_approvals; |
|
128 | + } else { |
|
129 | + $changes['unapprovedMembers'] = $coppa_approvals; |
|
130 | + } |
|
129 | 131 | } |
130 | 132 | } |
131 | 133 | } |
@@ -133,9 +135,9 @@ discard block |
||
133 | 135 | break; |
134 | 136 | |
135 | 137 | case 'message': |
136 | - if ($parameter1 === true && $parameter2 !== null) |
|
137 | - updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
138 | - else |
|
138 | + if ($parameter1 === true && $parameter2 !== null) { |
|
139 | + updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true); |
|
140 | + } else |
|
139 | 141 | { |
140 | 142 | // SUM and MAX on a smaller table is better for InnoDB tables. |
141 | 143 | $result = $smcFunc['db_query']('', ' |
@@ -175,23 +177,25 @@ discard block |
||
175 | 177 | $parameter2 = text2words($parameter2); |
176 | 178 | |
177 | 179 | $inserts = array(); |
178 | - foreach ($parameter2 as $word) |
|
179 | - $inserts[] = array($word, $parameter1); |
|
180 | + foreach ($parameter2 as $word) { |
|
181 | + $inserts[] = array($word, $parameter1); |
|
182 | + } |
|
180 | 183 | |
181 | - if (!empty($inserts)) |
|
182 | - $smcFunc['db_insert']('ignore', |
|
184 | + if (!empty($inserts)) { |
|
185 | + $smcFunc['db_insert']('ignore', |
|
183 | 186 | '{db_prefix}log_search_subjects', |
184 | 187 | array('word' => 'string', 'id_topic' => 'int'), |
185 | 188 | $inserts, |
186 | 189 | array('word', 'id_topic') |
187 | 190 | ); |
191 | + } |
|
188 | 192 | } |
189 | 193 | break; |
190 | 194 | |
191 | 195 | case 'topic': |
192 | - if ($parameter1 === true) |
|
193 | - updateSettings(array('totalTopics' => true), true); |
|
194 | - else |
|
196 | + if ($parameter1 === true) { |
|
197 | + updateSettings(array('totalTopics' => true), true); |
|
198 | + } else |
|
195 | 199 | { |
196 | 200 | // Get the number of topics - a SUM is better for InnoDB tables. |
197 | 201 | // We also ignore the recycle bin here because there will probably be a bunch of one-post topics there. |
@@ -212,8 +216,9 @@ discard block |
||
212 | 216 | |
213 | 217 | case 'postgroups': |
214 | 218 | // Parameter two is the updated columns: we should check to see if we base groups off any of these. |
215 | - if ($parameter2 !== null && !in_array('posts', $parameter2)) |
|
216 | - return; |
|
219 | + if ($parameter2 !== null && !in_array('posts', $parameter2)) { |
|
220 | + return; |
|
221 | + } |
|
217 | 222 | |
218 | 223 | $postgroups = cache_get_data('updateStats:postgroups', 360); |
219 | 224 | if ($postgroups == null || $parameter1 == null) |
@@ -228,8 +233,9 @@ discard block |
||
228 | 233 | ) |
229 | 234 | ); |
230 | 235 | $postgroups = array(); |
231 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
232 | - $postgroups[$row['id_group']] = $row['min_posts']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
237 | + $postgroups[$row['id_group']] = $row['min_posts']; |
|
238 | + } |
|
233 | 239 | $smcFunc['db_free_result']($request); |
234 | 240 | |
235 | 241 | // Sort them this way because if it's done with MySQL it causes a filesort :(. |
@@ -239,8 +245,9 @@ discard block |
||
239 | 245 | } |
240 | 246 | |
241 | 247 | // Oh great, they've screwed their post groups. |
242 | - if (empty($postgroups)) |
|
243 | - return; |
|
248 | + if (empty($postgroups)) { |
|
249 | + return; |
|
250 | + } |
|
244 | 251 | |
245 | 252 | // Set all membergroups from most posts to least posts. |
246 | 253 | $conditions = ''; |
@@ -298,10 +305,9 @@ discard block |
||
298 | 305 | { |
299 | 306 | $condition = 'id_member IN ({array_int:members})'; |
300 | 307 | $parameters['members'] = $members; |
301 | - } |
|
302 | - elseif ($members === null) |
|
303 | - $condition = '1=1'; |
|
304 | - else |
|
308 | + } elseif ($members === null) { |
|
309 | + $condition = '1=1'; |
|
310 | + } else |
|
305 | 311 | { |
306 | 312 | $condition = 'id_member = {int:member}'; |
307 | 313 | $parameters['member'] = $members; |
@@ -341,9 +347,9 @@ discard block |
||
341 | 347 | if (count($vars_to_integrate) != 0) |
342 | 348 | { |
343 | 349 | // Fetch a list of member_names if necessary |
344 | - if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) |
|
345 | - $member_names = array($user_info['username']); |
|
346 | - else |
|
350 | + if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) { |
|
351 | + $member_names = array($user_info['username']); |
|
352 | + } else |
|
347 | 353 | { |
348 | 354 | $member_names = array(); |
349 | 355 | $request = $smcFunc['db_query']('', ' |
@@ -352,14 +358,16 @@ discard block |
||
352 | 358 | WHERE ' . $condition, |
353 | 359 | $parameters |
354 | 360 | ); |
355 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
356 | - $member_names[] = $row['member_name']; |
|
361 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
362 | + $member_names[] = $row['member_name']; |
|
363 | + } |
|
357 | 364 | $smcFunc['db_free_result']($request); |
358 | 365 | } |
359 | 366 | |
360 | - if (!empty($member_names)) |
|
361 | - foreach ($vars_to_integrate as $var) |
|
367 | + if (!empty($member_names)) { |
|
368 | + foreach ($vars_to_integrate as $var) |
|
362 | 369 | call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats)); |
370 | + } |
|
363 | 371 | } |
364 | 372 | } |
365 | 373 | |
@@ -367,16 +375,17 @@ discard block |
||
367 | 375 | foreach ($data as $var => $val) |
368 | 376 | { |
369 | 377 | $type = 'string'; |
370 | - if (in_array($var, $knownInts)) |
|
371 | - $type = 'int'; |
|
372 | - elseif (in_array($var, $knownFloats)) |
|
373 | - $type = 'float'; |
|
374 | - elseif ($var == 'birthdate') |
|
375 | - $type = 'date'; |
|
376 | - elseif ($var == 'member_ip') |
|
377 | - $type = 'inet'; |
|
378 | - elseif ($var == 'member_ip2') |
|
379 | - $type = 'inet'; |
|
378 | + if (in_array($var, $knownInts)) { |
|
379 | + $type = 'int'; |
|
380 | + } elseif (in_array($var, $knownFloats)) { |
|
381 | + $type = 'float'; |
|
382 | + } elseif ($var == 'birthdate') { |
|
383 | + $type = 'date'; |
|
384 | + } elseif ($var == 'member_ip') { |
|
385 | + $type = 'inet'; |
|
386 | + } elseif ($var == 'member_ip2') { |
|
387 | + $type = 'inet'; |
|
388 | + } |
|
380 | 389 | |
381 | 390 | // Doing an increment? |
382 | 391 | if ($type == 'int' && ($val === '+' || $val === '-')) |
@@ -390,8 +399,9 @@ discard block |
||
390 | 399 | { |
391 | 400 | if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match)) |
392 | 401 | { |
393 | - if ($match[1] != '+ ') |
|
394 | - $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
402 | + if ($match[1] != '+ ') { |
|
403 | + $val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END'; |
|
404 | + } |
|
395 | 405 | $type = 'raw'; |
396 | 406 | } |
397 | 407 | } |
@@ -412,8 +422,9 @@ discard block |
||
412 | 422 | // Clear any caching? |
413 | 423 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members)) |
414 | 424 | { |
415 | - if (!is_array($members)) |
|
416 | - $members = array($members); |
|
425 | + if (!is_array($members)) { |
|
426 | + $members = array($members); |
|
427 | + } |
|
417 | 428 | |
418 | 429 | foreach ($members as $member) |
419 | 430 | { |
@@ -446,29 +457,32 @@ discard block |
||
446 | 457 | { |
447 | 458 | global $modSettings, $smcFunc; |
448 | 459 | |
449 | - if (empty($changeArray) || !is_array($changeArray)) |
|
450 | - return; |
|
460 | + if (empty($changeArray) || !is_array($changeArray)) { |
|
461 | + return; |
|
462 | + } |
|
451 | 463 | |
452 | 464 | $toRemove = array(); |
453 | 465 | |
454 | 466 | // Go check if there is any setting to be removed. |
455 | - foreach ($changeArray as $k => $v) |
|
456 | - if ($v === null) |
|
467 | + foreach ($changeArray as $k => $v) { |
|
468 | + if ($v === null) |
|
457 | 469 | { |
458 | 470 | // Found some, remove them from the original array and add them to ours. |
459 | 471 | unset($changeArray[$k]); |
472 | + } |
|
460 | 473 | $toRemove[] = $k; |
461 | 474 | } |
462 | 475 | |
463 | 476 | // Proceed with the deletion. |
464 | - if (!empty($toRemove)) |
|
465 | - $smcFunc['db_query']('', ' |
|
477 | + if (!empty($toRemove)) { |
|
478 | + $smcFunc['db_query']('', ' |
|
466 | 479 | DELETE FROM {db_prefix}settings |
467 | 480 | WHERE variable IN ({array_string:remove})', |
468 | 481 | array( |
469 | 482 | 'remove' => $toRemove, |
470 | 483 | ) |
471 | 484 | ); |
485 | + } |
|
472 | 486 | |
473 | 487 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
474 | 488 | if ($update) |
@@ -497,19 +511,22 @@ discard block |
||
497 | 511 | foreach ($changeArray as $variable => $value) |
498 | 512 | { |
499 | 513 | // Don't bother if it's already like that ;). |
500 | - if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
|
501 | - continue; |
|
514 | + if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) { |
|
515 | + continue; |
|
516 | + } |
|
502 | 517 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
503 | - elseif (!isset($modSettings[$variable]) && empty($value)) |
|
504 | - continue; |
|
518 | + elseif (!isset($modSettings[$variable]) && empty($value)) { |
|
519 | + continue; |
|
520 | + } |
|
505 | 521 | |
506 | 522 | $replaceArray[] = array($variable, $value); |
507 | 523 | |
508 | 524 | $modSettings[$variable] = $value; |
509 | 525 | } |
510 | 526 | |
511 | - if (empty($replaceArray)) |
|
512 | - return; |
|
527 | + if (empty($replaceArray)) { |
|
528 | + return; |
|
529 | + } |
|
513 | 530 | |
514 | 531 | $smcFunc['db_insert']('replace', |
515 | 532 | '{db_prefix}settings', |
@@ -555,14 +572,17 @@ discard block |
||
555 | 572 | $start_invalid = $start < 0; |
556 | 573 | |
557 | 574 | // Make sure $start is a proper variable - not less than 0. |
558 | - if ($start_invalid) |
|
559 | - $start = 0; |
|
575 | + if ($start_invalid) { |
|
576 | + $start = 0; |
|
577 | + } |
|
560 | 578 | // Not greater than the upper bound. |
561 | - elseif ($start >= $max_value) |
|
562 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
579 | + elseif ($start >= $max_value) { |
|
580 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
581 | + } |
|
563 | 582 | // And it has to be a multiple of $num_per_page! |
564 | - else |
|
565 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
583 | + else { |
|
584 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
585 | + } |
|
566 | 586 | |
567 | 587 | $context['current_page'] = $start / $num_per_page; |
568 | 588 | |
@@ -592,77 +612,87 @@ discard block |
||
592 | 612 | |
593 | 613 | // Show all the pages. |
594 | 614 | $display_page = 1; |
595 | - for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
|
596 | - $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
615 | + for ($counter = 0; $counter < $max_value; $counter += $num_per_page) { |
|
616 | + $pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
617 | + } |
|
597 | 618 | |
598 | 619 | // Show the right arrow. |
599 | 620 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
600 | - if ($start != $counter - $max_value && !$start_invalid) |
|
601 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
602 | - } |
|
603 | - else |
|
621 | + if ($start != $counter - $max_value && !$start_invalid) { |
|
622 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']); |
|
623 | + } |
|
624 | + } else |
|
604 | 625 | { |
605 | 626 | // If they didn't enter an odd value, pretend they did. |
606 | 627 | $PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2; |
607 | 628 | |
608 | 629 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
609 | - if (!empty($start) && $show_prevnext) |
|
610 | - $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
611 | - else |
|
612 | - $pageindex .= ''; |
|
630 | + if (!empty($start) && $show_prevnext) { |
|
631 | + $pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']); |
|
632 | + } else { |
|
633 | + $pageindex .= ''; |
|
634 | + } |
|
613 | 635 | |
614 | 636 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
615 | - if ($start > $num_per_page * $PageContiguous) |
|
616 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
637 | + if ($start > $num_per_page * $PageContiguous) { |
|
638 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
639 | + } |
|
617 | 640 | |
618 | 641 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
619 | - if ($start > $num_per_page * ($PageContiguous + 1)) |
|
620 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
642 | + if ($start > $num_per_page * ($PageContiguous + 1)) { |
|
643 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
621 | 644 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
622 | 645 | '{FIRST_PAGE}' => $num_per_page, |
623 | 646 | '{LAST_PAGE}' => $start - $num_per_page * $PageContiguous, |
624 | 647 | '{PER_PAGE}' => $num_per_page, |
625 | 648 | )); |
649 | + } |
|
626 | 650 | |
627 | 651 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
628 | - for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
|
629 | - if ($start >= $num_per_page * $nCont) |
|
652 | + for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) { |
|
653 | + if ($start >= $num_per_page * $nCont) |
|
630 | 654 | { |
631 | 655 | $tmpStart = $start - $num_per_page * $nCont; |
656 | + } |
|
632 | 657 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
633 | 658 | } |
634 | 659 | |
635 | 660 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
636 | - if (!$start_invalid) |
|
637 | - $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
638 | - else |
|
639 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
661 | + if (!$start_invalid) { |
|
662 | + $pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1); |
|
663 | + } else { |
|
664 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
665 | + } |
|
640 | 666 | |
641 | 667 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
642 | 668 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
643 | - for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
|
644 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
669 | + for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) { |
|
670 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
645 | 671 | { |
646 | 672 | $tmpStart = $start + $num_per_page * $nCont; |
673 | + } |
|
647 | 674 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
648 | 675 | } |
649 | 676 | |
650 | 677 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
651 | - if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
|
652 | - $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
678 | + if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) { |
|
679 | + $pageindex .= strtr($settings['page_index']['expand_pages'], array( |
|
653 | 680 | '{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)), |
654 | 681 | '{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1), |
655 | 682 | '{LAST_PAGE}' => $tmpMaxPages, |
656 | 683 | '{PER_PAGE}' => $num_per_page, |
657 | 684 | )); |
685 | + } |
|
658 | 686 | |
659 | 687 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
660 | - if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
|
661 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
688 | + if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) { |
|
689 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
690 | + } |
|
662 | 691 | |
663 | 692 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
664 | - if ($start != $tmpMaxPages && $show_prevnext) |
|
665 | - $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
693 | + if ($start != $tmpMaxPages && $show_prevnext) { |
|
694 | + $pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']); |
|
695 | + } |
|
666 | 696 | } |
667 | 697 | $pageindex .= $settings['page_index']['extra_after']; |
668 | 698 | |
@@ -688,8 +718,9 @@ discard block |
||
688 | 718 | if ($decimal_separator === null) |
689 | 719 | { |
690 | 720 | // Not set for whatever reason? |
691 | - if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
|
692 | - return $number; |
|
721 | + if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) { |
|
722 | + return $number; |
|
723 | + } |
|
693 | 724 | |
694 | 725 | // Cache these each load... |
695 | 726 | $thousands_separator = $matches[1]; |
@@ -721,17 +752,20 @@ discard block |
||
721 | 752 | static $non_twelve_hour; |
722 | 753 | |
723 | 754 | // Offset the time. |
724 | - if (!$offset_type) |
|
725 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
755 | + if (!$offset_type) { |
|
756 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
757 | + } |
|
726 | 758 | // Just the forum offset? |
727 | - elseif ($offset_type == 'forum') |
|
728 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
729 | - else |
|
730 | - $time = $log_time; |
|
759 | + elseif ($offset_type == 'forum') { |
|
760 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
761 | + } else { |
|
762 | + $time = $log_time; |
|
763 | + } |
|
731 | 764 | |
732 | 765 | // We can't have a negative date (on Windows, at least.) |
733 | - if ($log_time < 0) |
|
734 | - $log_time = 0; |
|
766 | + if ($log_time < 0) { |
|
767 | + $log_time = 0; |
|
768 | + } |
|
735 | 769 | |
736 | 770 | // Today and Yesterday? |
737 | 771 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -748,46 +782,53 @@ discard block |
||
748 | 782 | { |
749 | 783 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
750 | 784 | $today_fmt = $h . ':%M' . $s . ' %p'; |
785 | + } else { |
|
786 | + $today_fmt = '%H:%M' . $s; |
|
751 | 787 | } |
752 | - else |
|
753 | - $today_fmt = '%H:%M' . $s; |
|
754 | 788 | |
755 | 789 | // Same day of the year, same year.... Today! |
756 | - if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
|
757 | - return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
790 | + if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) { |
|
791 | + return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type); |
|
792 | + } |
|
758 | 793 | |
759 | 794 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
760 | - if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
|
761 | - return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
795 | + if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) { |
|
796 | + return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type); |
|
797 | + } |
|
762 | 798 | } |
763 | 799 | |
764 | 800 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
765 | 801 | |
766 | 802 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
767 | 803 | { |
768 | - if (!isset($non_twelve_hour)) |
|
769 | - $non_twelve_hour = trim(strftime('%p')) === ''; |
|
770 | - if ($non_twelve_hour && strpos($str, '%p') !== false) |
|
771 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
804 | + if (!isset($non_twelve_hour)) { |
|
805 | + $non_twelve_hour = trim(strftime('%p')) === ''; |
|
806 | + } |
|
807 | + if ($non_twelve_hour && strpos($str, '%p') !== false) { |
|
808 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
809 | + } |
|
772 | 810 | |
773 | - foreach (array('%a', '%A', '%b', '%B') as $token) |
|
774 | - if (strpos($str, $token) !== false) |
|
811 | + foreach (array('%a', '%A', '%b', '%B') as $token) { |
|
812 | + if (strpos($str, $token) !== false) |
|
775 | 813 | $str = str_replace($token, strftime($token, $time), $str); |
776 | - } |
|
777 | - else |
|
814 | + } |
|
815 | + } else |
|
778 | 816 | { |
779 | 817 | // Do-it-yourself time localization. Fun. |
780 | - foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
|
781 | - if (strpos($str, $token) !== false) |
|
818 | + foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) { |
|
819 | + if (strpos($str, $token) !== false) |
|
782 | 820 | $str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
821 | + } |
|
783 | 822 | |
784 | - if (strpos($str, '%p') !== false) |
|
785 | - $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
823 | + if (strpos($str, '%p') !== false) { |
|
824 | + $str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
825 | + } |
|
786 | 826 | } |
787 | 827 | |
788 | 828 | // Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that. |
789 | - if ($context['server']['is_windows'] && strpos($str, '%e') !== false) |
|
790 | - $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
829 | + if ($context['server']['is_windows'] && strpos($str, '%e') !== false) { |
|
830 | + $str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str); |
|
831 | + } |
|
791 | 832 | |
792 | 833 | // Format any other characters.. |
793 | 834 | return strftime($str, $time); |
@@ -809,16 +850,19 @@ discard block |
||
809 | 850 | static $translation = array(); |
810 | 851 | |
811 | 852 | // Determine the character set... Default to UTF-8 |
812 | - if (empty($context['character_set'])) |
|
813 | - $charset = 'UTF-8'; |
|
853 | + if (empty($context['character_set'])) { |
|
854 | + $charset = 'UTF-8'; |
|
855 | + } |
|
814 | 856 | // Use ISO-8859-1 in place of non-supported ISO-8859 charsets... |
815 | - elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) |
|
816 | - $charset = 'ISO-8859-1'; |
|
817 | - else |
|
818 | - $charset = $context['character_set']; |
|
857 | + elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) { |
|
858 | + $charset = 'ISO-8859-1'; |
|
859 | + } else { |
|
860 | + $charset = $context['character_set']; |
|
861 | + } |
|
819 | 862 | |
820 | - if (empty($translation)) |
|
821 | - $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
863 | + if (empty($translation)) { |
|
864 | + $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array(''' => '\'', ''' => '\'', ' ' => ' '); |
|
865 | + } |
|
822 | 866 | |
823 | 867 | return strtr($string, $translation); |
824 | 868 | } |
@@ -840,8 +884,9 @@ discard block |
||
840 | 884 | global $smcFunc; |
841 | 885 | |
842 | 886 | // It was already short enough! |
843 | - if ($smcFunc['strlen']($subject) <= $len) |
|
844 | - return $subject; |
|
887 | + if ($smcFunc['strlen']($subject) <= $len) { |
|
888 | + return $subject; |
|
889 | + } |
|
845 | 890 | |
846 | 891 | // Shorten it by the length it was too long, and strip off junk from the end. |
847 | 892 | return $smcFunc['substr']($subject, 0, $len) . '...'; |
@@ -860,10 +905,11 @@ discard block |
||
860 | 905 | { |
861 | 906 | global $user_info, $modSettings; |
862 | 907 | |
863 | - if ($timestamp === null) |
|
864 | - $timestamp = time(); |
|
865 | - elseif ($timestamp == 0) |
|
866 | - return 0; |
|
908 | + if ($timestamp === null) { |
|
909 | + $timestamp = time(); |
|
910 | + } elseif ($timestamp == 0) { |
|
911 | + return 0; |
|
912 | + } |
|
867 | 913 | |
868 | 914 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
869 | 915 | } |
@@ -892,8 +938,9 @@ discard block |
||
892 | 938 | $array[$i] = $array[$j]; |
893 | 939 | $array[$j] = $temp; |
894 | 940 | |
895 | - for ($i = 1; $p[$i] == 0; $i++) |
|
896 | - $p[$i] = 1; |
|
941 | + for ($i = 1; $p[$i] == 0; $i++) { |
|
942 | + $p[$i] = 1; |
|
943 | + } |
|
897 | 944 | |
898 | 945 | $orders[] = $array; |
899 | 946 | } |
@@ -925,12 +972,14 @@ discard block |
||
925 | 972 | static $disabled; |
926 | 973 | |
927 | 974 | // Don't waste cycles |
928 | - if ($message === '') |
|
929 | - return ''; |
|
975 | + if ($message === '') { |
|
976 | + return ''; |
|
977 | + } |
|
930 | 978 | |
931 | 979 | // Just in case it wasn't determined yet whether UTF-8 is enabled. |
932 | - if (!isset($context['utf8'])) |
|
933 | - $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
980 | + if (!isset($context['utf8'])) { |
|
981 | + $context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8'; |
|
982 | + } |
|
934 | 983 | |
935 | 984 | // Clean up any cut/paste issues we may have |
936 | 985 | $message = sanitizeMSCutPaste($message); |
@@ -942,13 +991,15 @@ discard block |
||
942 | 991 | return $message; |
943 | 992 | } |
944 | 993 | |
945 | - if ($smileys !== null && ($smileys == '1' || $smileys == '0')) |
|
946 | - $smileys = (bool) $smileys; |
|
994 | + if ($smileys !== null && ($smileys == '1' || $smileys == '0')) { |
|
995 | + $smileys = (bool) $smileys; |
|
996 | + } |
|
947 | 997 | |
948 | 998 | if (empty($modSettings['enableBBC']) && $message !== false) |
949 | 999 | { |
950 | - if ($smileys === true) |
|
951 | - parsesmileys($message); |
|
1000 | + if ($smileys === true) { |
|
1001 | + parsesmileys($message); |
|
1002 | + } |
|
952 | 1003 | |
953 | 1004 | return $message; |
954 | 1005 | } |
@@ -961,8 +1012,9 @@ discard block |
||
961 | 1012 | } |
962 | 1013 | |
963 | 1014 | // Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker |
964 | - if (!empty($modSettings['autoLinkUrls'])) |
|
965 | - set_tld_regex(); |
|
1015 | + if (!empty($modSettings['autoLinkUrls'])) { |
|
1016 | + set_tld_regex(); |
|
1017 | + } |
|
966 | 1018 | |
967 | 1019 | // Allow mods access before entering the main parse_bbc loop |
968 | 1020 | call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
@@ -976,12 +1028,14 @@ discard block |
||
976 | 1028 | |
977 | 1029 | $temp = explode(',', strtolower($modSettings['disabledBBC'])); |
978 | 1030 | |
979 | - foreach ($temp as $tag) |
|
980 | - $disabled[trim($tag)] = true; |
|
1031 | + foreach ($temp as $tag) { |
|
1032 | + $disabled[trim($tag)] = true; |
|
1033 | + } |
|
981 | 1034 | } |
982 | 1035 | |
983 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
984 | - $disabled['flash'] = true; |
|
1036 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1037 | + $disabled['flash'] = true; |
|
1038 | + } |
|
985 | 1039 | |
986 | 1040 | /* The following bbc are formatted as an array, with keys as follows: |
987 | 1041 | |
@@ -1102,8 +1156,9 @@ discard block |
||
1102 | 1156 | $returnContext = ''; |
1103 | 1157 | |
1104 | 1158 | // BBC or the entire attachments feature is disabled |
1105 | - if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) |
|
1106 | - return $data; |
|
1159 | + if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) { |
|
1160 | + return $data; |
|
1161 | + } |
|
1107 | 1162 | |
1108 | 1163 | // Save the attach ID. |
1109 | 1164 | $attachID = $data; |
@@ -1114,8 +1169,9 @@ discard block |
||
1114 | 1169 | $currentAttachment = parseAttachBBC($attachID); |
1115 | 1170 | |
1116 | 1171 | // parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do. |
1117 | - if (is_string($currentAttachment)) |
|
1118 | - return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1172 | + if (is_string($currentAttachment)) { |
|
1173 | + return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment; |
|
1174 | + } |
|
1119 | 1175 | |
1120 | 1176 | if (!empty($currentAttachment['is_image'])) |
1121 | 1177 | { |
@@ -1131,15 +1187,17 @@ discard block |
||
1131 | 1187 | $height = ' height="' . $currentAttachment['height'] . '"'; |
1132 | 1188 | } |
1133 | 1189 | |
1134 | - if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) |
|
1135 | - $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1136 | - else |
|
1137 | - $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
1190 | + if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) { |
|
1191 | + $returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>'; |
|
1192 | + } else { |
|
1193 | + $returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>'; |
|
1194 | + } |
|
1138 | 1195 | } |
1139 | 1196 | |
1140 | 1197 | // No image. Show a link. |
1141 | - else |
|
1142 | - $returnContext .= $currentAttachment['link']; |
|
1198 | + else { |
|
1199 | + $returnContext .= $currentAttachment['link']; |
|
1200 | + } |
|
1143 | 1201 | |
1144 | 1202 | // Gotta append what we just did. |
1145 | 1203 | $data = $returnContext; |
@@ -1170,8 +1228,9 @@ discard block |
||
1170 | 1228 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1171 | 1229 | { |
1172 | 1230 | // Do PHP code coloring? |
1173 | - if ($php_parts[$php_i] != '<?php') |
|
1174 | - continue; |
|
1231 | + if ($php_parts[$php_i] != '<?php') { |
|
1232 | + continue; |
|
1233 | + } |
|
1175 | 1234 | |
1176 | 1235 | $php_string = ''; |
1177 | 1236 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1187,8 +1246,9 @@ discard block |
||
1187 | 1246 | $data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data); |
1188 | 1247 | |
1189 | 1248 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1190 | - if ($context['browser']['is_opera']) |
|
1191 | - $data .= ' '; |
|
1249 | + if ($context['browser']['is_opera']) { |
|
1250 | + $data .= ' '; |
|
1251 | + } |
|
1192 | 1252 | } |
1193 | 1253 | }, |
1194 | 1254 | 'block_level' => true, |
@@ -1207,8 +1267,9 @@ discard block |
||
1207 | 1267 | for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++) |
1208 | 1268 | { |
1209 | 1269 | // Do PHP code coloring? |
1210 | - if ($php_parts[$php_i] != '<?php') |
|
1211 | - continue; |
|
1270 | + if ($php_parts[$php_i] != '<?php') { |
|
1271 | + continue; |
|
1272 | + } |
|
1212 | 1273 | |
1213 | 1274 | $php_string = ''; |
1214 | 1275 | while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?>') |
@@ -1224,8 +1285,9 @@ discard block |
||
1224 | 1285 | $data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]); |
1225 | 1286 | |
1226 | 1287 | // Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection. |
1227 | - if ($context['browser']['is_opera']) |
|
1228 | - $data[0] .= ' '; |
|
1288 | + if ($context['browser']['is_opera']) { |
|
1289 | + $data[0] .= ' '; |
|
1290 | + } |
|
1229 | 1291 | } |
1230 | 1292 | }, |
1231 | 1293 | 'block_level' => true, |
@@ -1263,11 +1325,13 @@ discard block |
||
1263 | 1325 | 'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">', |
1264 | 1326 | 'validate' => function (&$tag, &$data, $disabled) |
1265 | 1327 | { |
1266 | - if (isset($disabled['url'])) |
|
1267 | - $tag['content'] = '$1'; |
|
1328 | + if (isset($disabled['url'])) { |
|
1329 | + $tag['content'] = '$1'; |
|
1330 | + } |
|
1268 | 1331 | $scheme = parse_url($data[0], PHP_URL_SCHEME); |
1269 | - if (empty($scheme)) |
|
1270 | - $data[0] = '//' . ltrim($data[0], ':/'); |
|
1332 | + if (empty($scheme)) { |
|
1333 | + $data[0] = '//' . ltrim($data[0], ':/'); |
|
1334 | + } |
|
1271 | 1335 | }, |
1272 | 1336 | 'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>', |
1273 | 1337 | ), |
@@ -1314,14 +1378,16 @@ discard block |
||
1314 | 1378 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1315 | 1379 | if ($image_proxy_enabled) |
1316 | 1380 | { |
1317 | - if (empty($scheme)) |
|
1318 | - $data = 'http://' . ltrim($data, ':/'); |
|
1381 | + if (empty($scheme)) { |
|
1382 | + $data = 'http://' . ltrim($data, ':/'); |
|
1383 | + } |
|
1319 | 1384 | |
1320 | - if ($scheme != 'https') |
|
1321 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1385 | + if ($scheme != 'https') { |
|
1386 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1387 | + } |
|
1388 | + } elseif (empty($scheme)) { |
|
1389 | + $data = '//' . ltrim($data, ':/'); |
|
1322 | 1390 | } |
1323 | - elseif (empty($scheme)) |
|
1324 | - $data = '//' . ltrim($data, ':/'); |
|
1325 | 1391 | }, |
1326 | 1392 | 'disabled_content' => '($1)', |
1327 | 1393 | ), |
@@ -1337,14 +1403,16 @@ discard block |
||
1337 | 1403 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1338 | 1404 | if ($image_proxy_enabled) |
1339 | 1405 | { |
1340 | - if (empty($scheme)) |
|
1341 | - $data = 'http://' . ltrim($data, ':/'); |
|
1406 | + if (empty($scheme)) { |
|
1407 | + $data = 'http://' . ltrim($data, ':/'); |
|
1408 | + } |
|
1342 | 1409 | |
1343 | - if ($scheme != 'https') |
|
1344 | - $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1410 | + if ($scheme != 'https') { |
|
1411 | + $data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret); |
|
1412 | + } |
|
1413 | + } elseif (empty($scheme)) { |
|
1414 | + $data = '//' . ltrim($data, ':/'); |
|
1345 | 1415 | } |
1346 | - elseif (empty($scheme)) |
|
1347 | - $data = '//' . ltrim($data, ':/'); |
|
1348 | 1416 | }, |
1349 | 1417 | 'disabled_content' => '($1)', |
1350 | 1418 | ), |
@@ -1356,8 +1424,9 @@ discard block |
||
1356 | 1424 | { |
1357 | 1425 | $data = strtr($data, array('<br>' => '')); |
1358 | 1426 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1359 | - if (empty($scheme)) |
|
1360 | - $data = '//' . ltrim($data, ':/'); |
|
1427 | + if (empty($scheme)) { |
|
1428 | + $data = '//' . ltrim($data, ':/'); |
|
1429 | + } |
|
1361 | 1430 | }, |
1362 | 1431 | ), |
1363 | 1432 | array( |
@@ -1368,13 +1437,14 @@ discard block |
||
1368 | 1437 | 'after' => '</a>', |
1369 | 1438 | 'validate' => function (&$tag, &$data, $disabled) |
1370 | 1439 | { |
1371 | - if (substr($data, 0, 1) == '#') |
|
1372 | - $data = '#post_' . substr($data, 1); |
|
1373 | - else |
|
1440 | + if (substr($data, 0, 1) == '#') { |
|
1441 | + $data = '#post_' . substr($data, 1); |
|
1442 | + } else |
|
1374 | 1443 | { |
1375 | 1444 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1376 | - if (empty($scheme)) |
|
1377 | - $data = '//' . ltrim($data, ':/'); |
|
1445 | + if (empty($scheme)) { |
|
1446 | + $data = '//' . ltrim($data, ':/'); |
|
1447 | + } |
|
1378 | 1448 | } |
1379 | 1449 | }, |
1380 | 1450 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
@@ -1452,8 +1522,9 @@ discard block |
||
1452 | 1522 | { |
1453 | 1523 | $add_begin = substr(trim($data), 0, 5) != '<?'; |
1454 | 1524 | $data = highlight_php_code($add_begin ? '<?php ' . $data . '?>' : $data); |
1455 | - if ($add_begin) |
|
1456 | - $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1525 | + if ($add_begin) { |
|
1526 | + $data = preg_replace(array('~^(.+?)<\?.{0,40}?php(?: |\s)~', '~\?>((?:</(font|span)>)*)$~'), '$1', $data, 2); |
|
1527 | + } |
|
1457 | 1528 | } |
1458 | 1529 | }, |
1459 | 1530 | 'block_level' => false, |
@@ -1584,10 +1655,11 @@ discard block |
||
1584 | 1655 | 'content' => '$1', |
1585 | 1656 | 'validate' => function (&$tag, &$data, $disabled) |
1586 | 1657 | { |
1587 | - if (is_numeric($data)) |
|
1588 | - $data = timeformat($data); |
|
1589 | - else |
|
1590 | - $tag['content'] = '[time]$1[/time]'; |
|
1658 | + if (is_numeric($data)) { |
|
1659 | + $data = timeformat($data); |
|
1660 | + } else { |
|
1661 | + $tag['content'] = '[time]$1[/time]'; |
|
1662 | + } |
|
1591 | 1663 | }, |
1592 | 1664 | ), |
1593 | 1665 | array( |
@@ -1614,8 +1686,9 @@ discard block |
||
1614 | 1686 | { |
1615 | 1687 | $data = strtr($data, array('<br>' => '')); |
1616 | 1688 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1617 | - if (empty($scheme)) |
|
1618 | - $data = '//' . ltrim($data, ':/'); |
|
1689 | + if (empty($scheme)) { |
|
1690 | + $data = '//' . ltrim($data, ':/'); |
|
1691 | + } |
|
1619 | 1692 | }, |
1620 | 1693 | ), |
1621 | 1694 | array( |
@@ -1627,8 +1700,9 @@ discard block |
||
1627 | 1700 | 'validate' => function (&$tag, &$data, $disabled) |
1628 | 1701 | { |
1629 | 1702 | $scheme = parse_url($data, PHP_URL_SCHEME); |
1630 | - if (empty($scheme)) |
|
1631 | - $data = '//' . ltrim($data, ':/'); |
|
1703 | + if (empty($scheme)) { |
|
1704 | + $data = '//' . ltrim($data, ':/'); |
|
1705 | + } |
|
1632 | 1706 | }, |
1633 | 1707 | 'disallow_children' => array('email', 'ftp', 'url', 'iurl'), |
1634 | 1708 | 'disabled_after' => ' ($1)', |
@@ -1648,8 +1722,9 @@ discard block |
||
1648 | 1722 | // This is mainly for the bbc manager, so it's easy to add tags above. Custom BBC should be added above this line. |
1649 | 1723 | if ($message === false) |
1650 | 1724 | { |
1651 | - if (isset($temp_bbc)) |
|
1652 | - $bbc_codes = $temp_bbc; |
|
1725 | + if (isset($temp_bbc)) { |
|
1726 | + $bbc_codes = $temp_bbc; |
|
1727 | + } |
|
1653 | 1728 | usort($codes, function ($a, $b) { |
1654 | 1729 | return strcmp($a['tag'], $b['tag']); |
1655 | 1730 | }); |
@@ -1669,8 +1744,9 @@ discard block |
||
1669 | 1744 | ); |
1670 | 1745 | if (!isset($disabled['li']) && !isset($disabled['list'])) |
1671 | 1746 | { |
1672 | - foreach ($itemcodes as $c => $dummy) |
|
1673 | - $bbc_codes[$c] = array(); |
|
1747 | + foreach ($itemcodes as $c => $dummy) { |
|
1748 | + $bbc_codes[$c] = array(); |
|
1749 | + } |
|
1674 | 1750 | } |
1675 | 1751 | |
1676 | 1752 | // Shhhh! |
@@ -1691,12 +1767,14 @@ discard block |
||
1691 | 1767 | foreach ($codes as $code) |
1692 | 1768 | { |
1693 | 1769 | // Make it easier to process parameters later |
1694 | - if (!empty($code['parameters'])) |
|
1695 | - ksort($code['parameters'], SORT_STRING); |
|
1770 | + if (!empty($code['parameters'])) { |
|
1771 | + ksort($code['parameters'], SORT_STRING); |
|
1772 | + } |
|
1696 | 1773 | |
1697 | 1774 | // If we are not doing every tag only do ones we are interested in. |
1698 | - if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) |
|
1699 | - $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1775 | + if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) { |
|
1776 | + $bbc_codes[substr($code['tag'], 0, 1)][] = $code; |
|
1777 | + } |
|
1700 | 1778 | } |
1701 | 1779 | $codes = null; |
1702 | 1780 | } |
@@ -1707,8 +1785,9 @@ discard block |
||
1707 | 1785 | // It's likely this will change if the message is modified. |
1708 | 1786 | $cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']); |
1709 | 1787 | |
1710 | - if (($temp = cache_get_data($cache_key, 240)) != null) |
|
1711 | - return $temp; |
|
1788 | + if (($temp = cache_get_data($cache_key, 240)) != null) { |
|
1789 | + return $temp; |
|
1790 | + } |
|
1712 | 1791 | |
1713 | 1792 | $cache_t = microtime(); |
1714 | 1793 | } |
@@ -1740,8 +1819,9 @@ discard block |
||
1740 | 1819 | $disabled['flash'] = true; |
1741 | 1820 | |
1742 | 1821 | // @todo Change maybe? |
1743 | - if (!isset($_GET['images'])) |
|
1744 | - $disabled['img'] = true; |
|
1822 | + if (!isset($_GET['images'])) { |
|
1823 | + $disabled['img'] = true; |
|
1824 | + } |
|
1745 | 1825 | |
1746 | 1826 | // @todo Interface/setting to add more? |
1747 | 1827 | } |
@@ -1765,8 +1845,9 @@ discard block |
||
1765 | 1845 | $pos = isset($matches[0][1]) ? $matches[0][1] : false; |
1766 | 1846 | |
1767 | 1847 | // Failsafe. |
1768 | - if ($pos === false || $last_pos > $pos) |
|
1769 | - $pos = strlen($message) + 1; |
|
1848 | + if ($pos === false || $last_pos > $pos) { |
|
1849 | + $pos = strlen($message) + 1; |
|
1850 | + } |
|
1770 | 1851 | |
1771 | 1852 | // Can't have a one letter smiley, URL, or email! (sorry.) |
1772 | 1853 | if ($last_pos < $pos - 1) |
@@ -1785,8 +1866,9 @@ discard block |
||
1785 | 1866 | |
1786 | 1867 | // <br> should be empty. |
1787 | 1868 | $empty_tags = array('br', 'hr'); |
1788 | - foreach ($empty_tags as $tag) |
|
1789 | - $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1869 | + foreach ($empty_tags as $tag) { |
|
1870 | + $data = str_replace(array('<' . $tag . '>', '<' . $tag . '/>', '<' . $tag . ' />'), '[' . $tag . ' /]', $data); |
|
1871 | + } |
|
1790 | 1872 | |
1791 | 1873 | // b, u, i, s, pre... basic tags. |
1792 | 1874 | $closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote'); |
@@ -1795,8 +1877,9 @@ discard block |
||
1795 | 1877 | $diff = substr_count($data, '<' . $tag . '>') - substr_count($data, '</' . $tag . '>'); |
1796 | 1878 | $data = strtr($data, array('<' . $tag . '>' => '<' . $tag . '>', '</' . $tag . '>' => '</' . $tag . '>')); |
1797 | 1879 | |
1798 | - if ($diff > 0) |
|
1799 | - $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1880 | + if ($diff > 0) { |
|
1881 | + $data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1); |
|
1882 | + } |
|
1800 | 1883 | } |
1801 | 1884 | |
1802 | 1885 | // Do <img ...> - with security... action= -> action-. |
@@ -1809,8 +1892,9 @@ discard block |
||
1809 | 1892 | $alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^"|"$~', '', $matches[3][$match]); |
1810 | 1893 | |
1811 | 1894 | // Remove action= from the URL - no funny business, now. |
1812 | - if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) |
|
1813 | - $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1895 | + if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) { |
|
1896 | + $imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag); |
|
1897 | + } |
|
1814 | 1898 | |
1815 | 1899 | // Check if the image is larger than allowed. |
1816 | 1900 | if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height'])) |
@@ -1831,9 +1915,9 @@ discard block |
||
1831 | 1915 | |
1832 | 1916 | // Set the new image tag. |
1833 | 1917 | $replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]'; |
1918 | + } else { |
|
1919 | + $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1834 | 1920 | } |
1835 | - else |
|
1836 | - $replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]'; |
|
1837 | 1921 | } |
1838 | 1922 | |
1839 | 1923 | $data = strtr($data, $replaces); |
@@ -1846,16 +1930,18 @@ discard block |
||
1846 | 1930 | $no_autolink_area = false; |
1847 | 1931 | if (!empty($open_tags)) |
1848 | 1932 | { |
1849 | - foreach ($open_tags as $open_tag) |
|
1850 | - if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1933 | + foreach ($open_tags as $open_tag) { |
|
1934 | + if (in_array($open_tag['tag'], $no_autolink_tags)) |
|
1851 | 1935 | $no_autolink_area = true; |
1936 | + } |
|
1852 | 1937 | } |
1853 | 1938 | |
1854 | 1939 | // Don't go backwards. |
1855 | 1940 | // @todo Don't think is the real solution.... |
1856 | 1941 | $lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0; |
1857 | - if ($pos < $lastAutoPos) |
|
1858 | - $no_autolink_area = true; |
|
1942 | + if ($pos < $lastAutoPos) { |
|
1943 | + $no_autolink_area = true; |
|
1944 | + } |
|
1859 | 1945 | $lastAutoPos = $pos; |
1860 | 1946 | |
1861 | 1947 | if (!$no_autolink_area) |
@@ -1964,17 +2050,19 @@ discard block |
||
1964 | 2050 | if ($scheme == 'mailto') |
1965 | 2051 | { |
1966 | 2052 | $email_address = str_replace('mailto:', '', $url); |
1967 | - if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) |
|
1968 | - return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
1969 | - else |
|
1970 | - return $url; |
|
2053 | + if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) { |
|
2054 | + return '[email=' . $email_address . ']' . $url . '[/email]'; |
|
2055 | + } else { |
|
2056 | + return $url; |
|
2057 | + } |
|
1971 | 2058 | } |
1972 | 2059 | |
1973 | 2060 | // Are we linking a schemeless URL or naked domain name (e.g. "example.com")? |
1974 | - if (empty($scheme)) |
|
1975 | - $fullUrl = '//' . ltrim($url, ':/'); |
|
1976 | - else |
|
1977 | - $fullUrl = $url; |
|
2061 | + if (empty($scheme)) { |
|
2062 | + $fullUrl = '//' . ltrim($url, ':/'); |
|
2063 | + } else { |
|
2064 | + $fullUrl = $url; |
|
2065 | + } |
|
1978 | 2066 | |
1979 | 2067 | return '[url="' . str_replace(array('[', ']'), array('[', ']'), $fullUrl) . '"]' . $url . '[/url]'; |
1980 | 2068 | }, $data); |
@@ -2023,16 +2111,18 @@ discard block |
||
2023 | 2111 | } |
2024 | 2112 | |
2025 | 2113 | // Are we there yet? Are we there yet? |
2026 | - if ($pos >= strlen($message) - 1) |
|
2027 | - break; |
|
2114 | + if ($pos >= strlen($message) - 1) { |
|
2115 | + break; |
|
2116 | + } |
|
2028 | 2117 | |
2029 | 2118 | $tags = strtolower($message[$pos + 1]); |
2030 | 2119 | |
2031 | 2120 | if ($tags == '/' && !empty($open_tags)) |
2032 | 2121 | { |
2033 | 2122 | $pos2 = strpos($message, ']', $pos + 1); |
2034 | - if ($pos2 == $pos + 2) |
|
2035 | - continue; |
|
2123 | + if ($pos2 == $pos + 2) { |
|
2124 | + continue; |
|
2125 | + } |
|
2036 | 2126 | |
2037 | 2127 | $look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2)); |
2038 | 2128 | |
@@ -2042,8 +2132,9 @@ discard block |
||
2042 | 2132 | do |
2043 | 2133 | { |
2044 | 2134 | $tag = array_pop($open_tags); |
2045 | - if (!$tag) |
|
2046 | - break; |
|
2135 | + if (!$tag) { |
|
2136 | + break; |
|
2137 | + } |
|
2047 | 2138 | |
2048 | 2139 | if (!empty($tag['block_level'])) |
2049 | 2140 | { |
@@ -2057,10 +2148,11 @@ discard block |
||
2057 | 2148 | // The idea is, if we are LOOKING for a block level tag, we can close them on the way. |
2058 | 2149 | if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]])) |
2059 | 2150 | { |
2060 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2061 | - if ($temp['tag'] == $look_for) |
|
2151 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2152 | + if ($temp['tag'] == $look_for) |
|
2062 | 2153 | { |
2063 | 2154 | $block_level = !empty($temp['block_level']); |
2155 | + } |
|
2064 | 2156 | break; |
2065 | 2157 | } |
2066 | 2158 | } |
@@ -2082,15 +2174,15 @@ discard block |
||
2082 | 2174 | { |
2083 | 2175 | $open_tags = $to_close; |
2084 | 2176 | continue; |
2085 | - } |
|
2086 | - elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2177 | + } elseif (!empty($to_close) && $tag['tag'] != $look_for) |
|
2087 | 2178 | { |
2088 | 2179 | if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]])) |
2089 | 2180 | { |
2090 | - foreach ($bbc_codes[$look_for[0]] as $temp) |
|
2091 | - if ($temp['tag'] == $look_for) |
|
2181 | + foreach ($bbc_codes[$look_for[0]] as $temp) { |
|
2182 | + if ($temp['tag'] == $look_for) |
|
2092 | 2183 | { |
2093 | 2184 | $block_level = !empty($temp['block_level']); |
2185 | + } |
|
2094 | 2186 | break; |
2095 | 2187 | } |
2096 | 2188 | } |
@@ -2098,8 +2190,9 @@ discard block |
||
2098 | 2190 | // We're not looking for a block level tag (or maybe even a tag that exists...) |
2099 | 2191 | if (!$block_level) |
2100 | 2192 | { |
2101 | - foreach ($to_close as $tag) |
|
2102 | - array_push($open_tags, $tag); |
|
2193 | + foreach ($to_close as $tag) { |
|
2194 | + array_push($open_tags, $tag); |
|
2195 | + } |
|
2103 | 2196 | continue; |
2104 | 2197 | } |
2105 | 2198 | } |
@@ -2111,10 +2204,12 @@ discard block |
||
2111 | 2204 | $pos2 = $pos - 1; |
2112 | 2205 | |
2113 | 2206 | // See the comment at the end of the big loop - just eating whitespace ;). |
2114 | - if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2115 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2116 | - if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2117 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2207 | + if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2208 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2209 | + } |
|
2210 | + if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2211 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2212 | + } |
|
2118 | 2213 | } |
2119 | 2214 | |
2120 | 2215 | if (!empty($to_close)) |
@@ -2127,8 +2222,9 @@ discard block |
||
2127 | 2222 | } |
2128 | 2223 | |
2129 | 2224 | // No tags for this character, so just keep going (fastest possible course.) |
2130 | - if (!isset($bbc_codes[$tags])) |
|
2131 | - continue; |
|
2225 | + if (!isset($bbc_codes[$tags])) { |
|
2226 | + continue; |
|
2227 | + } |
|
2132 | 2228 | |
2133 | 2229 | $inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1]; |
2134 | 2230 | $tag = null; |
@@ -2137,44 +2233,52 @@ discard block |
||
2137 | 2233 | $pt_strlen = strlen($possible['tag']); |
2138 | 2234 | |
2139 | 2235 | // Not a match? |
2140 | - if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) |
|
2141 | - continue; |
|
2236 | + if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) { |
|
2237 | + continue; |
|
2238 | + } |
|
2142 | 2239 | |
2143 | 2240 | $next_c = $message[$pos + 1 + $pt_strlen]; |
2144 | 2241 | |
2145 | 2242 | // A test validation? |
2146 | - if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) |
|
2147 | - continue; |
|
2243 | + if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) { |
|
2244 | + continue; |
|
2245 | + } |
|
2148 | 2246 | // Do we want parameters? |
2149 | 2247 | elseif (!empty($possible['parameters'])) |
2150 | 2248 | { |
2151 | - if ($next_c != ' ') |
|
2152 | - continue; |
|
2153 | - } |
|
2154 | - elseif (isset($possible['type'])) |
|
2249 | + if ($next_c != ' ') { |
|
2250 | + continue; |
|
2251 | + } |
|
2252 | + } elseif (isset($possible['type'])) |
|
2155 | 2253 | { |
2156 | 2254 | // Do we need an equal sign? |
2157 | - if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') |
|
2158 | - continue; |
|
2255 | + if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') { |
|
2256 | + continue; |
|
2257 | + } |
|
2159 | 2258 | // Maybe we just want a /... |
2160 | - if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') |
|
2161 | - continue; |
|
2259 | + if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') { |
|
2260 | + continue; |
|
2261 | + } |
|
2162 | 2262 | // An immediate ]? |
2163 | - if ($possible['type'] == 'unparsed_content' && $next_c != ']') |
|
2164 | - continue; |
|
2263 | + if ($possible['type'] == 'unparsed_content' && $next_c != ']') { |
|
2264 | + continue; |
|
2265 | + } |
|
2165 | 2266 | } |
2166 | 2267 | // No type means 'parsed_content', which demands an immediate ] without parameters! |
2167 | - elseif ($next_c != ']') |
|
2168 | - continue; |
|
2268 | + elseif ($next_c != ']') { |
|
2269 | + continue; |
|
2270 | + } |
|
2169 | 2271 | |
2170 | 2272 | // Check allowed tree? |
2171 | - if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) |
|
2172 | - continue; |
|
2173 | - elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) |
|
2174 | - continue; |
|
2273 | + if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) { |
|
2274 | + continue; |
|
2275 | + } elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) { |
|
2276 | + continue; |
|
2277 | + } |
|
2175 | 2278 | // If this is in the list of disallowed child tags, don't parse it. |
2176 | - elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) |
|
2177 | - continue; |
|
2279 | + elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) { |
|
2280 | + continue; |
|
2281 | + } |
|
2178 | 2282 | |
2179 | 2283 | $pos1 = $pos + 1 + $pt_strlen + 1; |
2180 | 2284 | |
@@ -2186,8 +2290,9 @@ discard block |
||
2186 | 2290 | foreach ($open_tags as $open_quote) |
2187 | 2291 | { |
2188 | 2292 | // Every parent quote this quote has flips the styling |
2189 | - if ($open_quote['tag'] == 'quote') |
|
2190 | - $quote_alt = !$quote_alt; |
|
2293 | + if ($open_quote['tag'] == 'quote') { |
|
2294 | + $quote_alt = !$quote_alt; |
|
2295 | + } |
|
2191 | 2296 | } |
2192 | 2297 | // Add a class to the quote to style alternating blockquotes |
2193 | 2298 | $possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">')); |
@@ -2198,8 +2303,9 @@ discard block |
||
2198 | 2303 | { |
2199 | 2304 | // Build a regular expression for each parameter for the current tag. |
2200 | 2305 | $preg = array(); |
2201 | - foreach ($possible['parameters'] as $p => $info) |
|
2202 | - $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2306 | + foreach ($possible['parameters'] as $p => $info) { |
|
2307 | + $preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '"') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '"') . '\s*)' . (empty($info['optional']) ? '' : '?'); |
|
2308 | + } |
|
2203 | 2309 | |
2204 | 2310 | // Extract the string that potentially holds our parameters. |
2205 | 2311 | $blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos)); |
@@ -2219,24 +2325,27 @@ discard block |
||
2219 | 2325 | |
2220 | 2326 | $match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0; |
2221 | 2327 | |
2222 | - if ($match) |
|
2223 | - $blob_counter = count($blobs) + 1; |
|
2328 | + if ($match) { |
|
2329 | + $blob_counter = count($blobs) + 1; |
|
2330 | + } |
|
2224 | 2331 | } |
2225 | 2332 | |
2226 | 2333 | // Didn't match our parameter list, try the next possible. |
2227 | - if (!$match) |
|
2228 | - continue; |
|
2334 | + if (!$match) { |
|
2335 | + continue; |
|
2336 | + } |
|
2229 | 2337 | |
2230 | 2338 | $params = array(); |
2231 | 2339 | for ($i = 1, $n = count($matches); $i < $n; $i += 2) |
2232 | 2340 | { |
2233 | 2341 | $key = strtok(ltrim($matches[$i]), '='); |
2234 | - if (isset($possible['parameters'][$key]['value'])) |
|
2235 | - $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2236 | - elseif (isset($possible['parameters'][$key]['validate'])) |
|
2237 | - $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2238 | - else |
|
2239 | - $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2342 | + if (isset($possible['parameters'][$key]['value'])) { |
|
2343 | + $params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1])); |
|
2344 | + } elseif (isset($possible['parameters'][$key]['validate'])) { |
|
2345 | + $params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]); |
|
2346 | + } else { |
|
2347 | + $params['{' . $key . '}'] = $matches[$i + 1]; |
|
2348 | + } |
|
2240 | 2349 | |
2241 | 2350 | // Just to make sure: replace any $ or { so they can't interpolate wrongly. |
2242 | 2351 | $params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '$', '{' => '{')); |
@@ -2244,23 +2353,26 @@ discard block |
||
2244 | 2353 | |
2245 | 2354 | foreach ($possible['parameters'] as $p => $info) |
2246 | 2355 | { |
2247 | - if (!isset($params['{' . $p . '}'])) |
|
2248 | - $params['{' . $p . '}'] = ''; |
|
2356 | + if (!isset($params['{' . $p . '}'])) { |
|
2357 | + $params['{' . $p . '}'] = ''; |
|
2358 | + } |
|
2249 | 2359 | } |
2250 | 2360 | |
2251 | 2361 | $tag = $possible; |
2252 | 2362 | |
2253 | 2363 | // Put the parameters into the string. |
2254 | - if (isset($tag['before'])) |
|
2255 | - $tag['before'] = strtr($tag['before'], $params); |
|
2256 | - if (isset($tag['after'])) |
|
2257 | - $tag['after'] = strtr($tag['after'], $params); |
|
2258 | - if (isset($tag['content'])) |
|
2259 | - $tag['content'] = strtr($tag['content'], $params); |
|
2364 | + if (isset($tag['before'])) { |
|
2365 | + $tag['before'] = strtr($tag['before'], $params); |
|
2366 | + } |
|
2367 | + if (isset($tag['after'])) { |
|
2368 | + $tag['after'] = strtr($tag['after'], $params); |
|
2369 | + } |
|
2370 | + if (isset($tag['content'])) { |
|
2371 | + $tag['content'] = strtr($tag['content'], $params); |
|
2372 | + } |
|
2260 | 2373 | |
2261 | 2374 | $pos1 += strlen($given_param_string); |
2262 | - } |
|
2263 | - else |
|
2375 | + } else |
|
2264 | 2376 | { |
2265 | 2377 | $tag = $possible; |
2266 | 2378 | $params = array(); |
@@ -2271,8 +2383,9 @@ discard block |
||
2271 | 2383 | // Item codes are complicated buggers... they are implicit [li]s and can make [list]s! |
2272 | 2384 | if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li'])) |
2273 | 2385 | { |
2274 | - if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) |
|
2275 | - continue; |
|
2386 | + if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) { |
|
2387 | + continue; |
|
2388 | + } |
|
2276 | 2389 | |
2277 | 2390 | $tag = $itemcodes[$message[$pos + 1]]; |
2278 | 2391 | |
@@ -2293,9 +2406,9 @@ discard block |
||
2293 | 2406 | { |
2294 | 2407 | array_pop($open_tags); |
2295 | 2408 | $code = '</li>'; |
2409 | + } else { |
|
2410 | + $code = ''; |
|
2296 | 2411 | } |
2297 | - else |
|
2298 | - $code = ''; |
|
2299 | 2412 | |
2300 | 2413 | // Now we open a new tag. |
2301 | 2414 | $open_tags[] = array( |
@@ -2342,12 +2455,14 @@ discard block |
||
2342 | 2455 | } |
2343 | 2456 | |
2344 | 2457 | // No tag? Keep looking, then. Silly people using brackets without actual tags. |
2345 | - if ($tag === null) |
|
2346 | - continue; |
|
2458 | + if ($tag === null) { |
|
2459 | + continue; |
|
2460 | + } |
|
2347 | 2461 | |
2348 | 2462 | // Propagate the list to the child (so wrapping the disallowed tag won't work either.) |
2349 | - if (isset($inside['disallow_children'])) |
|
2350 | - $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2463 | + if (isset($inside['disallow_children'])) { |
|
2464 | + $tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children']; |
|
2465 | + } |
|
2351 | 2466 | |
2352 | 2467 | // Is this tag disabled? |
2353 | 2468 | if (isset($disabled[$tag['tag']])) |
@@ -2357,14 +2472,13 @@ discard block |
||
2357 | 2472 | $tag['before'] = !empty($tag['block_level']) ? '<div>' : ''; |
2358 | 2473 | $tag['after'] = !empty($tag['block_level']) ? '</div>' : ''; |
2359 | 2474 | $tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1'); |
2360 | - } |
|
2361 | - elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2475 | + } elseif (isset($tag['disabled_before']) || isset($tag['disabled_after'])) |
|
2362 | 2476 | { |
2363 | 2477 | $tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : ''); |
2364 | 2478 | $tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : ''); |
2479 | + } else { |
|
2480 | + $tag['content'] = $tag['disabled_content']; |
|
2365 | 2481 | } |
2366 | - else |
|
2367 | - $tag['content'] = $tag['disabled_content']; |
|
2368 | 2482 | } |
2369 | 2483 | |
2370 | 2484 | // we use this a lot |
@@ -2374,8 +2488,9 @@ discard block |
||
2374 | 2488 | if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level'])) |
2375 | 2489 | { |
2376 | 2490 | $n = count($open_tags) - 1; |
2377 | - while (empty($open_tags[$n]['block_level']) && $n >= 0) |
|
2378 | - $n--; |
|
2491 | + while (empty($open_tags[$n]['block_level']) && $n >= 0) { |
|
2492 | + $n--; |
|
2493 | + } |
|
2379 | 2494 | |
2380 | 2495 | // Close all the non block level tags so this tag isn't surrounded by them. |
2381 | 2496 | for ($i = count($open_tags) - 1; $i > $n; $i--) |
@@ -2386,10 +2501,12 @@ discard block |
||
2386 | 2501 | $pos1 += $ot_strlen + 2; |
2387 | 2502 | |
2388 | 2503 | // Trim or eat trailing stuff... see comment at the end of the big loop. |
2389 | - if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') |
|
2390 | - $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2391 | - if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) |
|
2392 | - $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2504 | + if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') { |
|
2505 | + $message = substr($message, 0, $pos) . substr($message, $pos + 4); |
|
2506 | + } |
|
2507 | + if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>| |\s)*~', substr($message, $pos), $matches) != 0) { |
|
2508 | + $message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0])); |
|
2509 | + } |
|
2393 | 2510 | |
2394 | 2511 | array_pop($open_tags); |
2395 | 2512 | } |
@@ -2407,16 +2524,19 @@ discard block |
||
2407 | 2524 | elseif ($tag['type'] == 'unparsed_content') |
2408 | 2525 | { |
2409 | 2526 | $pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1); |
2410 | - if ($pos2 === false) |
|
2411 | - continue; |
|
2527 | + if ($pos2 === false) { |
|
2528 | + continue; |
|
2529 | + } |
|
2412 | 2530 | |
2413 | 2531 | $data = substr($message, $pos1, $pos2 - $pos1); |
2414 | 2532 | |
2415 | - if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') |
|
2416 | - $data = substr($data, 4); |
|
2533 | + if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') { |
|
2534 | + $data = substr($data, 4); |
|
2535 | + } |
|
2417 | 2536 | |
2418 | - if (isset($tag['validate'])) |
|
2419 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2537 | + if (isset($tag['validate'])) { |
|
2538 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2539 | + } |
|
2420 | 2540 | |
2421 | 2541 | $code = strtr($tag['content'], array('$1' => $data)); |
2422 | 2542 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen); |
@@ -2432,34 +2552,40 @@ discard block |
||
2432 | 2552 | if (isset($tag['quoted'])) |
2433 | 2553 | { |
2434 | 2554 | $quoted = substr($message, $pos1, 6) == '"'; |
2435 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2436 | - continue; |
|
2555 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2556 | + continue; |
|
2557 | + } |
|
2437 | 2558 | |
2438 | - if ($quoted) |
|
2439 | - $pos1 += 6; |
|
2559 | + if ($quoted) { |
|
2560 | + $pos1 += 6; |
|
2561 | + } |
|
2562 | + } else { |
|
2563 | + $quoted = false; |
|
2440 | 2564 | } |
2441 | - else |
|
2442 | - $quoted = false; |
|
2443 | 2565 | |
2444 | 2566 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2445 | - if ($pos2 === false) |
|
2446 | - continue; |
|
2567 | + if ($pos2 === false) { |
|
2568 | + continue; |
|
2569 | + } |
|
2447 | 2570 | |
2448 | 2571 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2449 | - if ($pos3 === false) |
|
2450 | - continue; |
|
2572 | + if ($pos3 === false) { |
|
2573 | + continue; |
|
2574 | + } |
|
2451 | 2575 | |
2452 | 2576 | $data = array( |
2453 | 2577 | substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))), |
2454 | 2578 | substr($message, $pos1, $pos2 - $pos1) |
2455 | 2579 | ); |
2456 | 2580 | |
2457 | - if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') |
|
2458 | - $data[0] = substr($data[0], 4); |
|
2581 | + if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') { |
|
2582 | + $data[0] = substr($data[0], 4); |
|
2583 | + } |
|
2459 | 2584 | |
2460 | 2585 | // Validation for my parking, please! |
2461 | - if (isset($tag['validate'])) |
|
2462 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2586 | + if (isset($tag['validate'])) { |
|
2587 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2588 | + } |
|
2463 | 2589 | |
2464 | 2590 | $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1])); |
2465 | 2591 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
@@ -2476,23 +2602,27 @@ discard block |
||
2476 | 2602 | elseif ($tag['type'] == 'unparsed_commas_content') |
2477 | 2603 | { |
2478 | 2604 | $pos2 = strpos($message, ']', $pos1); |
2479 | - if ($pos2 === false) |
|
2480 | - continue; |
|
2605 | + if ($pos2 === false) { |
|
2606 | + continue; |
|
2607 | + } |
|
2481 | 2608 | |
2482 | 2609 | $pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2); |
2483 | - if ($pos3 === false) |
|
2484 | - continue; |
|
2610 | + if ($pos3 === false) { |
|
2611 | + continue; |
|
2612 | + } |
|
2485 | 2613 | |
2486 | 2614 | // We want $1 to be the content, and the rest to be csv. |
2487 | 2615 | $data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1)); |
2488 | 2616 | $data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1); |
2489 | 2617 | |
2490 | - if (isset($tag['validate'])) |
|
2491 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2618 | + if (isset($tag['validate'])) { |
|
2619 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2620 | + } |
|
2492 | 2621 | |
2493 | 2622 | $code = $tag['content']; |
2494 | - foreach ($data as $k => $d) |
|
2495 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2623 | + foreach ($data as $k => $d) { |
|
2624 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2625 | + } |
|
2496 | 2626 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen); |
2497 | 2627 | $pos += strlen($code) - 1 + 2; |
2498 | 2628 | } |
@@ -2500,24 +2630,28 @@ discard block |
||
2500 | 2630 | elseif ($tag['type'] == 'unparsed_commas') |
2501 | 2631 | { |
2502 | 2632 | $pos2 = strpos($message, ']', $pos1); |
2503 | - if ($pos2 === false) |
|
2504 | - continue; |
|
2633 | + if ($pos2 === false) { |
|
2634 | + continue; |
|
2635 | + } |
|
2505 | 2636 | |
2506 | 2637 | $data = explode(',', substr($message, $pos1, $pos2 - $pos1)); |
2507 | 2638 | |
2508 | - if (isset($tag['validate'])) |
|
2509 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2639 | + if (isset($tag['validate'])) { |
|
2640 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2641 | + } |
|
2510 | 2642 | |
2511 | 2643 | // Fix after, for disabled code mainly. |
2512 | - foreach ($data as $k => $d) |
|
2513 | - $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2644 | + foreach ($data as $k => $d) { |
|
2645 | + $tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d))); |
|
2646 | + } |
|
2514 | 2647 | |
2515 | 2648 | $open_tags[] = $tag; |
2516 | 2649 | |
2517 | 2650 | // Replace them out, $1, $2, $3, $4, etc. |
2518 | 2651 | $code = $tag['before']; |
2519 | - foreach ($data as $k => $d) |
|
2520 | - $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2652 | + foreach ($data as $k => $d) { |
|
2653 | + $code = strtr($code, array('$' . ($k + 1) => trim($d))); |
|
2654 | + } |
|
2521 | 2655 | $message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1); |
2522 | 2656 | $pos += strlen($code) - 1 + 2; |
2523 | 2657 | } |
@@ -2528,28 +2662,33 @@ discard block |
||
2528 | 2662 | if (isset($tag['quoted'])) |
2529 | 2663 | { |
2530 | 2664 | $quoted = substr($message, $pos1, 6) == '"'; |
2531 | - if ($tag['quoted'] != 'optional' && !$quoted) |
|
2532 | - continue; |
|
2665 | + if ($tag['quoted'] != 'optional' && !$quoted) { |
|
2666 | + continue; |
|
2667 | + } |
|
2533 | 2668 | |
2534 | - if ($quoted) |
|
2535 | - $pos1 += 6; |
|
2669 | + if ($quoted) { |
|
2670 | + $pos1 += 6; |
|
2671 | + } |
|
2672 | + } else { |
|
2673 | + $quoted = false; |
|
2536 | 2674 | } |
2537 | - else |
|
2538 | - $quoted = false; |
|
2539 | 2675 | |
2540 | 2676 | $pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1); |
2541 | - if ($pos2 === false) |
|
2542 | - continue; |
|
2677 | + if ($pos2 === false) { |
|
2678 | + continue; |
|
2679 | + } |
|
2543 | 2680 | |
2544 | 2681 | $data = substr($message, $pos1, $pos2 - $pos1); |
2545 | 2682 | |
2546 | 2683 | // Validation for my parking, please! |
2547 | - if (isset($tag['validate'])) |
|
2548 | - $tag['validate']($tag, $data, $disabled, $params); |
|
2684 | + if (isset($tag['validate'])) { |
|
2685 | + $tag['validate']($tag, $data, $disabled, $params); |
|
2686 | + } |
|
2549 | 2687 | |
2550 | 2688 | // For parsed content, we must recurse to avoid security problems. |
2551 | - if ($tag['type'] != 'unparsed_equals') |
|
2552 | - $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2689 | + if ($tag['type'] != 'unparsed_equals') { |
|
2690 | + $data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array()); |
|
2691 | + } |
|
2553 | 2692 | |
2554 | 2693 | $tag['after'] = strtr($tag['after'], array('$1' => $data)); |
2555 | 2694 | |
@@ -2561,34 +2700,40 @@ discard block |
||
2561 | 2700 | } |
2562 | 2701 | |
2563 | 2702 | // If this is block level, eat any breaks after it. |
2564 | - if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') |
|
2565 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2703 | + if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') { |
|
2704 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 5); |
|
2705 | + } |
|
2566 | 2706 | |
2567 | 2707 | // Are we trimming outside this tag? |
2568 | - if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) |
|
2569 | - $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2708 | + if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>| |\s)*~', substr($message, $pos + 1), $matches) != 0) { |
|
2709 | + $message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0])); |
|
2710 | + } |
|
2570 | 2711 | } |
2571 | 2712 | |
2572 | 2713 | // Close any remaining tags. |
2573 | - while ($tag = array_pop($open_tags)) |
|
2574 | - $message .= "\n" . $tag['after'] . "\n"; |
|
2714 | + while ($tag = array_pop($open_tags)) { |
|
2715 | + $message .= "\n" . $tag['after'] . "\n"; |
|
2716 | + } |
|
2575 | 2717 | |
2576 | 2718 | // Parse the smileys within the parts where it can be done safely. |
2577 | 2719 | if ($smileys === true) |
2578 | 2720 | { |
2579 | 2721 | $message_parts = explode("\n", $message); |
2580 | - for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) |
|
2581 | - parsesmileys($message_parts[$i]); |
|
2722 | + for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) { |
|
2723 | + parsesmileys($message_parts[$i]); |
|
2724 | + } |
|
2582 | 2725 | |
2583 | 2726 | $message = implode('', $message_parts); |
2584 | 2727 | } |
2585 | 2728 | |
2586 | 2729 | // No smileys, just get rid of the markers. |
2587 | - else |
|
2588 | - $message = strtr($message, array("\n" => '')); |
|
2730 | + else { |
|
2731 | + $message = strtr($message, array("\n" => '')); |
|
2732 | + } |
|
2589 | 2733 | |
2590 | - if ($message !== '' && $message[0] === ' ') |
|
2591 | - $message = ' ' . substr($message, 1); |
|
2734 | + if ($message !== '' && $message[0] === ' ') { |
|
2735 | + $message = ' ' . substr($message, 1); |
|
2736 | + } |
|
2592 | 2737 | |
2593 | 2738 | // Cleanup whitespace. |
2594 | 2739 | $message = strtr($message, array(' ' => ' ', "\r" => '', "\n" => '<br>', '<br> ' => '<br> ', ' ' => "\n")); |
@@ -2597,15 +2742,16 @@ discard block |
||
2597 | 2742 | call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags)); |
2598 | 2743 | |
2599 | 2744 | // Cache the output if it took some time... |
2600 | - if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) |
|
2601 | - cache_put_data($cache_key, $message, 240); |
|
2745 | + if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) { |
|
2746 | + cache_put_data($cache_key, $message, 240); |
|
2747 | + } |
|
2602 | 2748 | |
2603 | 2749 | // If this was a force parse revert if needed. |
2604 | 2750 | if (!empty($parse_tags)) |
2605 | 2751 | { |
2606 | - if (empty($temp_bbc)) |
|
2607 | - $bbc_codes = array(); |
|
2608 | - else |
|
2752 | + if (empty($temp_bbc)) { |
|
2753 | + $bbc_codes = array(); |
|
2754 | + } else |
|
2609 | 2755 | { |
2610 | 2756 | $bbc_codes = $temp_bbc; |
2611 | 2757 | unset($temp_bbc); |
@@ -2632,8 +2778,9 @@ discard block |
||
2632 | 2778 | static $smileyPregSearch = null, $smileyPregReplacements = array(); |
2633 | 2779 | |
2634 | 2780 | // No smiley set at all?! |
2635 | - if ($user_info['smiley_set'] == 'none' || trim($message) == '') |
|
2636 | - return; |
|
2781 | + if ($user_info['smiley_set'] == 'none' || trim($message) == '') { |
|
2782 | + return; |
|
2783 | + } |
|
2637 | 2784 | |
2638 | 2785 | // If smileyPregSearch hasn't been set, do it now. |
2639 | 2786 | if (empty($smileyPregSearch)) |
@@ -2644,8 +2791,7 @@ discard block |
||
2644 | 2791 | $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); |
2645 | 2792 | $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); |
2646 | 2793 | $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', ''); |
2647 | - } |
|
2648 | - else |
|
2794 | + } else |
|
2649 | 2795 | { |
2650 | 2796 | // Load the smileys in reverse order by length so they don't get parsed wrong. |
2651 | 2797 | if (($temp = cache_get_data('parsing_smileys', 480)) == null) |
@@ -2669,9 +2815,9 @@ discard block |
||
2669 | 2815 | $smcFunc['db_free_result']($result); |
2670 | 2816 | |
2671 | 2817 | cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); |
2818 | + } else { |
|
2819 | + list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2672 | 2820 | } |
2673 | - else |
|
2674 | - list ($smileysfrom, $smileysto, $smileysdescs) = $temp; |
|
2675 | 2821 | } |
2676 | 2822 | |
2677 | 2823 | // The non-breaking-space is a complex thing... |
@@ -2748,35 +2894,41 @@ discard block |
||
2748 | 2894 | global $scripturl, $context, $modSettings, $db_show_debug, $db_cache; |
2749 | 2895 | |
2750 | 2896 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
2751 | - if (!empty($context['flush_mail'])) |
|
2752 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2897 | + if (!empty($context['flush_mail'])) { |
|
2898 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2753 | 2899 | AddMailQueue(true); |
2900 | + } |
|
2754 | 2901 | |
2755 | 2902 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
2756 | 2903 | |
2757 | - if ($add) |
|
2758 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2904 | + if ($add) { |
|
2905 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
2906 | + } |
|
2759 | 2907 | |
2760 | 2908 | // Put the session ID in. |
2761 | - if (defined('SID') && SID != '') |
|
2762 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2909 | + if (defined('SID') && SID != '') { |
|
2910 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
2911 | + } |
|
2763 | 2912 | // Keep that debug in their for template debugging! |
2764 | - elseif (isset($_GET['debug'])) |
|
2765 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2913 | + elseif (isset($_GET['debug'])) { |
|
2914 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
2915 | + } |
|
2766 | 2916 | |
2767 | 2917 | if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed']))) |
2768 | 2918 | { |
2769 | - if (defined('SID') && SID != '') |
|
2770 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2919 | + if (defined('SID') && SID != '') { |
|
2920 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', |
|
2771 | 2921 | function ($m) use ($scripturl) |
2772 | 2922 | { |
2773 | 2923 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : ""); |
2924 | + } |
|
2774 | 2925 | }, $setLocation); |
2775 | - else |
|
2776 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2926 | + else { |
|
2927 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', |
|
2777 | 2928 | function ($m) use ($scripturl) |
2778 | 2929 | { |
2779 | 2930 | return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : ""); |
2931 | + } |
|
2780 | 2932 | }, $setLocation); |
2781 | 2933 | } |
2782 | 2934 | |
@@ -2787,8 +2939,9 @@ discard block |
||
2787 | 2939 | header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302); |
2788 | 2940 | |
2789 | 2941 | // Debugging. |
2790 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
2791 | - $_SESSION['debug_redirect'] = $db_cache; |
|
2942 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
2943 | + $_SESSION['debug_redirect'] = $db_cache; |
|
2944 | + } |
|
2792 | 2945 | |
2793 | 2946 | obExit(false); |
2794 | 2947 | } |
@@ -2807,51 +2960,60 @@ discard block |
||
2807 | 2960 | |
2808 | 2961 | // Attempt to prevent a recursive loop. |
2809 | 2962 | ++$level; |
2810 | - if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
|
2811 | - exit; |
|
2812 | - if ($from_fatal_error) |
|
2813 | - $has_fatal_error = true; |
|
2963 | + if ($level > 1 && !$from_fatal_error && !$has_fatal_error) { |
|
2964 | + exit; |
|
2965 | + } |
|
2966 | + if ($from_fatal_error) { |
|
2967 | + $has_fatal_error = true; |
|
2968 | + } |
|
2814 | 2969 | |
2815 | 2970 | // Clear out the stat cache. |
2816 | 2971 | trackStats(); |
2817 | 2972 | |
2818 | 2973 | // If we have mail to send, send it. |
2819 | - if (!empty($context['flush_mail'])) |
|
2820 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2974 | + if (!empty($context['flush_mail'])) { |
|
2975 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
2821 | 2976 | AddMailQueue(true); |
2977 | + } |
|
2822 | 2978 | |
2823 | 2979 | $do_header = $header === null ? !$header_done : $header; |
2824 | - if ($do_footer === null) |
|
2825 | - $do_footer = $do_header; |
|
2980 | + if ($do_footer === null) { |
|
2981 | + $do_footer = $do_header; |
|
2982 | + } |
|
2826 | 2983 | |
2827 | 2984 | // Has the template/header been done yet? |
2828 | 2985 | if ($do_header) |
2829 | 2986 | { |
2830 | 2987 | // Was the page title set last minute? Also update the HTML safe one. |
2831 | - if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
|
2832 | - $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2988 | + if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) { |
|
2989 | + $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
2990 | + } |
|
2833 | 2991 | |
2834 | 2992 | // Start up the session URL fixer. |
2835 | 2993 | ob_start('ob_sessrewrite'); |
2836 | 2994 | |
2837 | - if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) |
|
2838 | - $buffers = explode(',', $settings['output_buffers']); |
|
2839 | - elseif (!empty($settings['output_buffers'])) |
|
2840 | - $buffers = $settings['output_buffers']; |
|
2841 | - else |
|
2842 | - $buffers = array(); |
|
2995 | + if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) { |
|
2996 | + $buffers = explode(',', $settings['output_buffers']); |
|
2997 | + } elseif (!empty($settings['output_buffers'])) { |
|
2998 | + $buffers = $settings['output_buffers']; |
|
2999 | + } else { |
|
3000 | + $buffers = array(); |
|
3001 | + } |
|
2843 | 3002 | |
2844 | - if (isset($modSettings['integrate_buffer'])) |
|
2845 | - $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3003 | + if (isset($modSettings['integrate_buffer'])) { |
|
3004 | + $buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers); |
|
3005 | + } |
|
2846 | 3006 | |
2847 | - if (!empty($buffers)) |
|
2848 | - foreach ($buffers as $function) |
|
3007 | + if (!empty($buffers)) { |
|
3008 | + foreach ($buffers as $function) |
|
2849 | 3009 | { |
2850 | 3010 | $call = call_helper($function, true); |
3011 | + } |
|
2851 | 3012 | |
2852 | 3013 | // Is it valid? |
2853 | - if (!empty($call)) |
|
2854 | - ob_start($call); |
|
3014 | + if (!empty($call)) { |
|
3015 | + ob_start($call); |
|
3016 | + } |
|
2855 | 3017 | } |
2856 | 3018 | |
2857 | 3019 | // Display the screen in the logical order. |
@@ -2863,8 +3025,9 @@ discard block |
||
2863 | 3025 | loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main'); |
2864 | 3026 | |
2865 | 3027 | // Anything special to put out? |
2866 | - if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) |
|
2867 | - echo $context['insert_after_template']; |
|
3028 | + if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) { |
|
3029 | + echo $context['insert_after_template']; |
|
3030 | + } |
|
2868 | 3031 | |
2869 | 3032 | // Just so we don't get caught in an endless loop of errors from the footer... |
2870 | 3033 | if (!$footer_done) |
@@ -2873,14 +3036,16 @@ discard block |
||
2873 | 3036 | template_footer(); |
2874 | 3037 | |
2875 | 3038 | // (since this is just debugging... it's okay that it's after </html>.) |
2876 | - if (!isset($_REQUEST['xml'])) |
|
2877 | - displayDebug(); |
|
3039 | + if (!isset($_REQUEST['xml'])) { |
|
3040 | + displayDebug(); |
|
3041 | + } |
|
2878 | 3042 | } |
2879 | 3043 | } |
2880 | 3044 | |
2881 | 3045 | // Remember this URL in case someone doesn't like sending HTTP_REFERER. |
2882 | - if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) |
|
2883 | - $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3046 | + if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) { |
|
3047 | + $_SESSION['old_url'] = $_SERVER['REQUEST_URL']; |
|
3048 | + } |
|
2884 | 3049 | |
2885 | 3050 | // For session check verification.... don't switch browsers... |
2886 | 3051 | $_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT']; |
@@ -2889,9 +3054,10 @@ discard block |
||
2889 | 3054 | call_integration_hook('integrate_exit', array($do_footer)); |
2890 | 3055 | |
2891 | 3056 | // Don't exit if we're coming from index.php; that will pass through normally. |
2892 | - if (!$from_index) |
|
2893 | - exit; |
|
2894 | -} |
|
3057 | + if (!$from_index) { |
|
3058 | + exit; |
|
3059 | + } |
|
3060 | + } |
|
2895 | 3061 | |
2896 | 3062 | /** |
2897 | 3063 | * Get the size of a specified image with better error handling. |
@@ -2910,8 +3076,9 @@ discard block |
||
2910 | 3076 | $url = str_replace(' ', '%20', $url); |
2911 | 3077 | |
2912 | 3078 | // Can we pull this from the cache... please please? |
2913 | - if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) |
|
2914 | - return $temp; |
|
3079 | + if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) { |
|
3080 | + return $temp; |
|
3081 | + } |
|
2915 | 3082 | $t = microtime(); |
2916 | 3083 | |
2917 | 3084 | // Get the host to pester... |
@@ -2921,12 +3088,10 @@ discard block |
||
2921 | 3088 | if ($url == '' || $url == 'http://' || $url == 'https://') |
2922 | 3089 | { |
2923 | 3090 | return false; |
2924 | - } |
|
2925 | - elseif (!isset($match[1])) |
|
3091 | + } elseif (!isset($match[1])) |
|
2926 | 3092 | { |
2927 | 3093 | $size = @getimagesize($url); |
2928 | - } |
|
2929 | - else |
|
3094 | + } else |
|
2930 | 3095 | { |
2931 | 3096 | // Try to connect to the server... give it half a second. |
2932 | 3097 | $temp = 0; |
@@ -2965,12 +3130,14 @@ discard block |
||
2965 | 3130 | } |
2966 | 3131 | |
2967 | 3132 | // If we didn't get it, we failed. |
2968 | - if (!isset($size)) |
|
2969 | - $size = false; |
|
3133 | + if (!isset($size)) { |
|
3134 | + $size = false; |
|
3135 | + } |
|
2970 | 3136 | |
2971 | 3137 | // If this took a long time, we may never have to do it again, but then again we might... |
2972 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) |
|
2973 | - cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3138 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) { |
|
3139 | + cache_put_data('url_image_size-' . md5($url), $size, 240); |
|
3140 | + } |
|
2974 | 3141 | |
2975 | 3142 | // Didn't work. |
2976 | 3143 | return $size; |
@@ -2988,8 +3155,9 @@ discard block |
||
2988 | 3155 | |
2989 | 3156 | // Under SSI this function can be called more then once. That can cause some problems. |
2990 | 3157 | // So only run the function once unless we are forced to run it again. |
2991 | - if ($loaded && !$forceload) |
|
2992 | - return; |
|
3158 | + if ($loaded && !$forceload) { |
|
3159 | + return; |
|
3160 | + } |
|
2993 | 3161 | |
2994 | 3162 | $loaded = true; |
2995 | 3163 | |
@@ -3001,14 +3169,16 @@ discard block |
||
3001 | 3169 | $context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news']))))); |
3002 | 3170 | for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++) |
3003 | 3171 | { |
3004 | - if (trim($context['news_lines'][$i]) == '') |
|
3005 | - continue; |
|
3172 | + if (trim($context['news_lines'][$i]) == '') { |
|
3173 | + continue; |
|
3174 | + } |
|
3006 | 3175 | |
3007 | 3176 | // Clean it up for presentation ;). |
3008 | 3177 | $context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i); |
3009 | 3178 | } |
3010 | - if (!empty($context['news_lines'])) |
|
3011 | - $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3179 | + if (!empty($context['news_lines'])) { |
|
3180 | + $context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)]; |
|
3181 | + } |
|
3012 | 3182 | |
3013 | 3183 | if (!$user_info['is_guest']) |
3014 | 3184 | { |
@@ -3017,40 +3187,48 @@ discard block |
||
3017 | 3187 | $context['user']['alerts'] = &$user_info['alerts']; |
3018 | 3188 | |
3019 | 3189 | // Personal message popup... |
3020 | - if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) |
|
3021 | - $context['user']['popup_messages'] = true; |
|
3022 | - else |
|
3023 | - $context['user']['popup_messages'] = false; |
|
3190 | + if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) { |
|
3191 | + $context['user']['popup_messages'] = true; |
|
3192 | + } else { |
|
3193 | + $context['user']['popup_messages'] = false; |
|
3194 | + } |
|
3024 | 3195 | $_SESSION['unread_messages'] = $user_info['unread_messages']; |
3025 | 3196 | |
3026 | - if (allowedTo('moderate_forum')) |
|
3027 | - $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3197 | + if (allowedTo('moderate_forum')) { |
|
3198 | + $context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0; |
|
3199 | + } |
|
3028 | 3200 | |
3029 | 3201 | $context['user']['avatar'] = array(); |
3030 | 3202 | |
3031 | 3203 | // Check for gravatar first since we might be forcing them... |
3032 | 3204 | if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride'])) |
3033 | 3205 | { |
3034 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) |
|
3035 | - $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3036 | - else |
|
3037 | - $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3206 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) { |
|
3207 | + $context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11)); |
|
3208 | + } else { |
|
3209 | + $context['user']['avatar']['href'] = get_gravatar_url($user_info['email']); |
|
3210 | + } |
|
3038 | 3211 | } |
3039 | 3212 | // Uploaded? |
3040 | - elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) |
|
3041 | - $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3213 | + elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) { |
|
3214 | + $context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar'; |
|
3215 | + } |
|
3042 | 3216 | // Full URL? |
3043 | - elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) |
|
3044 | - $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3217 | + elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) { |
|
3218 | + $context['user']['avatar']['href'] = $user_info['avatar']['url']; |
|
3219 | + } |
|
3045 | 3220 | // Otherwise we assume it's server stored. |
3046 | - elseif ($user_info['avatar']['url'] != '') |
|
3047 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3221 | + elseif ($user_info['avatar']['url'] != '') { |
|
3222 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']); |
|
3223 | + } |
|
3048 | 3224 | // No avatar at all? Fine, we have a big fat default avatar ;) |
3049 | - else |
|
3050 | - $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3225 | + else { |
|
3226 | + $context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png'; |
|
3227 | + } |
|
3051 | 3228 | |
3052 | - if (!empty($context['user']['avatar'])) |
|
3053 | - $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3229 | + if (!empty($context['user']['avatar'])) { |
|
3230 | + $context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">'; |
|
3231 | + } |
|
3054 | 3232 | |
3055 | 3233 | // Figure out how long they've been logged in. |
3056 | 3234 | $context['user']['total_time_logged_in'] = array( |
@@ -3058,8 +3236,7 @@ discard block |
||
3058 | 3236 | 'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600), |
3059 | 3237 | 'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60) |
3060 | 3238 | ); |
3061 | - } |
|
3062 | - else |
|
3239 | + } else |
|
3063 | 3240 | { |
3064 | 3241 | $context['user']['messages'] = 0; |
3065 | 3242 | $context['user']['unread_messages'] = 0; |
@@ -3067,12 +3244,14 @@ discard block |
||
3067 | 3244 | $context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0); |
3068 | 3245 | $context['user']['popup_messages'] = false; |
3069 | 3246 | |
3070 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) |
|
3071 | - $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3247 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) { |
|
3248 | + $txt['welcome_guest'] .= $txt['welcome_guest_activate']; |
|
3249 | + } |
|
3072 | 3250 | |
3073 | 3251 | // If we've upgraded recently, go easy on the passwords. |
3074 | - if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) |
|
3075 | - $context['disable_login_hashing'] = true; |
|
3252 | + if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) { |
|
3253 | + $context['disable_login_hashing'] = true; |
|
3254 | + } |
|
3076 | 3255 | } |
3077 | 3256 | |
3078 | 3257 | // Setup the main menu items. |
@@ -3085,8 +3264,8 @@ discard block |
||
3085 | 3264 | $context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm'); |
3086 | 3265 | |
3087 | 3266 | // 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array. |
3088 | - if ($context['show_pm_popup']) |
|
3089 | - addInlineJavaScript(' |
|
3267 | + if ($context['show_pm_popup']) { |
|
3268 | + addInlineJavaScript(' |
|
3090 | 3269 | jQuery(document).ready(function($) { |
3091 | 3270 | new smc_Popup({ |
3092 | 3271 | heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ', |
@@ -3094,15 +3273,17 @@ discard block |
||
3094 | 3273 | icon_class: \'generic_icons mail_new\' |
3095 | 3274 | }); |
3096 | 3275 | });'); |
3276 | + } |
|
3097 | 3277 | |
3098 | 3278 | // Add a generic "Are you sure?" confirmation message. |
3099 | 3279 | addInlineJavaScript(' |
3100 | 3280 | var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';'); |
3101 | 3281 | |
3102 | 3282 | // Now add the capping code for avatars. |
3103 | - if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') |
|
3104 | - addInlineCss(' |
|
3283 | + if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') { |
|
3284 | + addInlineCss(' |
|
3105 | 3285 | img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }'); |
3286 | + } |
|
3106 | 3287 | |
3107 | 3288 | // This looks weird, but it's because BoardIndex.php references the variable. |
3108 | 3289 | $context['common_stats']['latest_member'] = array( |
@@ -3119,11 +3300,13 @@ discard block |
||
3119 | 3300 | ); |
3120 | 3301 | $context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']); |
3121 | 3302 | |
3122 | - if (empty($settings['theme_version'])) |
|
3123 | - addJavaScriptVar('smf_scripturl', $scripturl); |
|
3303 | + if (empty($settings['theme_version'])) { |
|
3304 | + addJavaScriptVar('smf_scripturl', $scripturl); |
|
3305 | + } |
|
3124 | 3306 | |
3125 | - if (!isset($context['page_title'])) |
|
3126 | - $context['page_title'] = ''; |
|
3307 | + if (!isset($context['page_title'])) { |
|
3308 | + $context['page_title'] = ''; |
|
3309 | + } |
|
3127 | 3310 | |
3128 | 3311 | // Set some specific vars. |
3129 | 3312 | $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
@@ -3133,21 +3316,23 @@ discard block |
||
3133 | 3316 | $context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']); |
3134 | 3317 | $context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']); |
3135 | 3318 | |
3136 | - if (!empty($context['meta_keywords'])) |
|
3137 | - $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3319 | + if (!empty($context['meta_keywords'])) { |
|
3320 | + $context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']); |
|
3321 | + } |
|
3138 | 3322 | |
3139 | - if (!empty($context['canonical_url'])) |
|
3140 | - $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3323 | + if (!empty($context['canonical_url'])) { |
|
3324 | + $context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']); |
|
3325 | + } |
|
3141 | 3326 | |
3142 | - if (!empty($settings['og_image'])) |
|
3143 | - $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3327 | + if (!empty($settings['og_image'])) { |
|
3328 | + $context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']); |
|
3329 | + } |
|
3144 | 3330 | |
3145 | 3331 | if (!empty($context['meta_description'])) |
3146 | 3332 | { |
3147 | 3333 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']); |
3148 | 3334 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']); |
3149 | - } |
|
3150 | - else |
|
3335 | + } else |
|
3151 | 3336 | { |
3152 | 3337 | $context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']); |
3153 | 3338 | $context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']); |
@@ -3172,8 +3357,9 @@ discard block |
||
3172 | 3357 | $memory_needed = memoryReturnBytes($needed); |
3173 | 3358 | |
3174 | 3359 | // should we account for how much is currently being used? |
3175 | - if ($in_use) |
|
3176 | - $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3360 | + if ($in_use) { |
|
3361 | + $memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576); |
|
3362 | + } |
|
3177 | 3363 | |
3178 | 3364 | // if more is needed, request it |
3179 | 3365 | if ($memory_current < $memory_needed) |
@@ -3196,8 +3382,9 @@ discard block |
||
3196 | 3382 | */ |
3197 | 3383 | function memoryReturnBytes($val) |
3198 | 3384 | { |
3199 | - if (is_integer($val)) |
|
3200 | - return $val; |
|
3385 | + if (is_integer($val)) { |
|
3386 | + return $val; |
|
3387 | + } |
|
3201 | 3388 | |
3202 | 3389 | // Separate the number from the designator |
3203 | 3390 | $val = trim($val); |
@@ -3233,10 +3420,11 @@ discard block |
||
3233 | 3420 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
3234 | 3421 | |
3235 | 3422 | // Are we debugging the template/html content? |
3236 | - if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) |
|
3237 | - header('Content-Type: application/xhtml+xml'); |
|
3238 | - elseif (!isset($_REQUEST['xml'])) |
|
3239 | - header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3423 | + if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) { |
|
3424 | + header('Content-Type: application/xhtml+xml'); |
|
3425 | + } elseif (!isset($_REQUEST['xml'])) { |
|
3426 | + header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3427 | + } |
|
3240 | 3428 | } |
3241 | 3429 | |
3242 | 3430 | header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
@@ -3245,8 +3433,9 @@ discard block |
||
3245 | 3433 | if ($context['in_maintenance'] && $context['user']['is_admin']) |
3246 | 3434 | { |
3247 | 3435 | $position = array_search('body', $context['template_layers']); |
3248 | - if ($position === false) |
|
3249 | - $position = array_search('main', $context['template_layers']); |
|
3436 | + if ($position === false) { |
|
3437 | + $position = array_search('main', $context['template_layers']); |
|
3438 | + } |
|
3250 | 3439 | |
3251 | 3440 | if ($position !== false) |
3252 | 3441 | { |
@@ -3274,23 +3463,25 @@ discard block |
||
3274 | 3463 | |
3275 | 3464 | foreach ($securityFiles as $i => $securityFile) |
3276 | 3465 | { |
3277 | - if (!file_exists($boarddir . '/' . $securityFile)) |
|
3278 | - unset($securityFiles[$i]); |
|
3466 | + if (!file_exists($boarddir . '/' . $securityFile)) { |
|
3467 | + unset($securityFiles[$i]); |
|
3468 | + } |
|
3279 | 3469 | } |
3280 | 3470 | |
3281 | 3471 | // We are already checking so many files...just few more doesn't make any difference! :P |
3282 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3283 | - $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3284 | - |
|
3285 | - else |
|
3286 | - $path = $modSettings['attachmentUploadDir']; |
|
3472 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3473 | + $path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
|
3474 | + } else { |
|
3475 | + $path = $modSettings['attachmentUploadDir']; |
|
3476 | + } |
|
3287 | 3477 | |
3288 | 3478 | secureDirectory($path, true); |
3289 | 3479 | secureDirectory($cachedir); |
3290 | 3480 | |
3291 | 3481 | // If agreement is enabled, at least the english version shall exists |
3292 | - if ($modSettings['requireAgreement']) |
|
3293 | - $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3482 | + if ($modSettings['requireAgreement']) { |
|
3483 | + $agreement = !file_exists($boarddir . '/agreement.txt'); |
|
3484 | + } |
|
3294 | 3485 | |
3295 | 3486 | if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement)) |
3296 | 3487 | { |
@@ -3305,18 +3496,21 @@ discard block |
||
3305 | 3496 | echo ' |
3306 | 3497 | ', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>'; |
3307 | 3498 | |
3308 | - if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') |
|
3309 | - echo ' |
|
3499 | + if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') { |
|
3500 | + echo ' |
|
3310 | 3501 | ', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>'; |
3502 | + } |
|
3311 | 3503 | } |
3312 | 3504 | |
3313 | - if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) |
|
3314 | - echo ' |
|
3505 | + if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) { |
|
3506 | + echo ' |
|
3315 | 3507 | <strong>', $txt['cache_writable'], '</strong><br>'; |
3508 | + } |
|
3316 | 3509 | |
3317 | - if (!empty($agreement)) |
|
3318 | - echo ' |
|
3510 | + if (!empty($agreement)) { |
|
3511 | + echo ' |
|
3319 | 3512 | <strong>', $txt['agreement_missing'], '</strong><br>'; |
3513 | + } |
|
3320 | 3514 | |
3321 | 3515 | echo ' |
3322 | 3516 | </p> |
@@ -3331,16 +3525,18 @@ discard block |
||
3331 | 3525 | <div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;"> |
3332 | 3526 | ', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']); |
3333 | 3527 | |
3334 | - if (!empty($_SESSION['ban']['cannot_post']['reason'])) |
|
3335 | - echo ' |
|
3528 | + if (!empty($_SESSION['ban']['cannot_post']['reason'])) { |
|
3529 | + echo ' |
|
3336 | 3530 | <div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>'; |
3531 | + } |
|
3337 | 3532 | |
3338 | - if (!empty($_SESSION['ban']['expire_time'])) |
|
3339 | - echo ' |
|
3533 | + if (!empty($_SESSION['ban']['expire_time'])) { |
|
3534 | + echo ' |
|
3340 | 3535 | <div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>'; |
3341 | - else |
|
3342 | - echo ' |
|
3536 | + } else { |
|
3537 | + echo ' |
|
3343 | 3538 | <div>', $txt['your_ban_expires_never'], '</div>'; |
3539 | + } |
|
3344 | 3540 | |
3345 | 3541 | echo ' |
3346 | 3542 | </div>'; |
@@ -3356,8 +3552,9 @@ discard block |
||
3356 | 3552 | global $forum_copyright, $software_year, $forum_version; |
3357 | 3553 | |
3358 | 3554 | // Don't display copyright for things like SSI. |
3359 | - if (!isset($forum_version) || !isset($software_year)) |
|
3360 | - return; |
|
3555 | + if (!isset($forum_version) || !isset($software_year)) { |
|
3556 | + return; |
|
3557 | + } |
|
3361 | 3558 | |
3362 | 3559 | // Put in the version... |
3363 | 3560 | printf($forum_copyright, $forum_version, $software_year); |
@@ -3375,9 +3572,10 @@ discard block |
||
3375 | 3572 | $context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3)); |
3376 | 3573 | $context['load_queries'] = $db_count; |
3377 | 3574 | |
3378 | - foreach (array_reverse($context['template_layers']) as $layer) |
|
3379 | - loadSubTemplate($layer . '_below', true); |
|
3380 | -} |
|
3575 | + foreach (array_reverse($context['template_layers']) as $layer) { |
|
3576 | + loadSubTemplate($layer . '_below', true); |
|
3577 | + } |
|
3578 | + } |
|
3381 | 3579 | |
3382 | 3580 | /** |
3383 | 3581 | * Output the Javascript files |
@@ -3408,8 +3606,7 @@ discard block |
||
3408 | 3606 | { |
3409 | 3607 | echo ' |
3410 | 3608 | var ', $key, ';'; |
3411 | - } |
|
3412 | - else |
|
3609 | + } else |
|
3413 | 3610 | { |
3414 | 3611 | echo ' |
3415 | 3612 | var ', $key, ' = ', $value, ';'; |
@@ -3424,26 +3621,27 @@ discard block |
||
3424 | 3621 | foreach ($context['javascript_files'] as $id => $js_file) |
3425 | 3622 | { |
3426 | 3623 | // Last minute call! allow theme authors to disable single files. |
3427 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3428 | - continue; |
|
3624 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3625 | + continue; |
|
3626 | + } |
|
3429 | 3627 | |
3430 | 3628 | // By default all files don't get minimized unless the file explicitly says so! |
3431 | 3629 | if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
3432 | 3630 | { |
3433 | - if ($do_deferred && !empty($js_file['options']['defer'])) |
|
3434 | - $toMinifyDefer[] = $js_file; |
|
3435 | - |
|
3436 | - elseif (!$do_deferred && empty($js_file['options']['defer'])) |
|
3437 | - $toMinify[] = $js_file; |
|
3631 | + if ($do_deferred && !empty($js_file['options']['defer'])) { |
|
3632 | + $toMinifyDefer[] = $js_file; |
|
3633 | + } elseif (!$do_deferred && empty($js_file['options']['defer'])) { |
|
3634 | + $toMinify[] = $js_file; |
|
3635 | + } |
|
3438 | 3636 | |
3439 | 3637 | // Grab a random seed. |
3440 | - if (!isset($minSeed)) |
|
3441 | - $minSeed = $js_file['options']['seed']; |
|
3442 | - } |
|
3443 | - |
|
3444 | - elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) |
|
3445 | - echo ' |
|
3638 | + if (!isset($minSeed)) { |
|
3639 | + $minSeed = $js_file['options']['seed']; |
|
3640 | + } |
|
3641 | + } elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) { |
|
3642 | + echo ' |
|
3446 | 3643 | <script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>'; |
3644 | + } |
|
3447 | 3645 | } |
3448 | 3646 | |
3449 | 3647 | if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer))) |
@@ -3451,14 +3649,14 @@ discard block |
||
3451 | 3649 | $result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred); |
3452 | 3650 | |
3453 | 3651 | // Minify process couldn't work, print each individual files. |
3454 | - if (!empty($result) && is_array($result)) |
|
3455 | - foreach ($result as $minFailedFile) |
|
3652 | + if (!empty($result) && is_array($result)) { |
|
3653 | + foreach ($result as $minFailedFile) |
|
3456 | 3654 | echo ' |
3457 | 3655 | <script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>'; |
3458 | - |
|
3459 | - else |
|
3460 | - echo ' |
|
3656 | + } else { |
|
3657 | + echo ' |
|
3461 | 3658 | <script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>'; |
3659 | + } |
|
3462 | 3660 | } |
3463 | 3661 | |
3464 | 3662 | // Inline JavaScript - Actually useful some times! |
@@ -3469,8 +3667,9 @@ discard block |
||
3469 | 3667 | echo ' |
3470 | 3668 | <script>'; |
3471 | 3669 | |
3472 | - foreach ($context['javascript_inline']['defer'] as $js_code) |
|
3473 | - echo $js_code; |
|
3670 | + foreach ($context['javascript_inline']['defer'] as $js_code) { |
|
3671 | + echo $js_code; |
|
3672 | + } |
|
3474 | 3673 | |
3475 | 3674 | echo ' |
3476 | 3675 | </script>'; |
@@ -3481,8 +3680,9 @@ discard block |
||
3481 | 3680 | echo ' |
3482 | 3681 | <script>'; |
3483 | 3682 | |
3484 | - foreach ($context['javascript_inline']['standard'] as $js_code) |
|
3485 | - echo $js_code; |
|
3683 | + foreach ($context['javascript_inline']['standard'] as $js_code) { |
|
3684 | + echo $js_code; |
|
3685 | + } |
|
3486 | 3686 | |
3487 | 3687 | echo ' |
3488 | 3688 | </script>'; |
@@ -3507,8 +3707,9 @@ discard block |
||
3507 | 3707 | foreach ($context['css_files'] as $id => $file) |
3508 | 3708 | { |
3509 | 3709 | // Last minute call! allow theme authors to disable single files. |
3510 | - if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) |
|
3511 | - continue; |
|
3710 | + if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) { |
|
3711 | + continue; |
|
3712 | + } |
|
3512 | 3713 | |
3513 | 3714 | // By default all files don't get minimized unless the file explicitly says so! |
3514 | 3715 | if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files'])) |
@@ -3516,12 +3717,12 @@ discard block |
||
3516 | 3717 | $toMinify[] = $file; |
3517 | 3718 | |
3518 | 3719 | // Grab a random seed. |
3519 | - if (!isset($minSeed)) |
|
3520 | - $minSeed = $file['options']['seed']; |
|
3720 | + if (!isset($minSeed)) { |
|
3721 | + $minSeed = $file['options']['seed']; |
|
3722 | + } |
|
3723 | + } else { |
|
3724 | + $normal[] = $file['fileUrl']; |
|
3521 | 3725 | } |
3522 | - |
|
3523 | - else |
|
3524 | - $normal[] = $file['fileUrl']; |
|
3525 | 3726 | } |
3526 | 3727 | |
3527 | 3728 | if (!empty($toMinify)) |
@@ -3529,28 +3730,30 @@ discard block |
||
3529 | 3730 | $result = custMinify($toMinify, 'css'); |
3530 | 3731 | |
3531 | 3732 | // Minify process couldn't work, print each individual files. |
3532 | - if (!empty($result) && is_array($result)) |
|
3533 | - foreach ($result as $minFailedFile) |
|
3733 | + if (!empty($result) && is_array($result)) { |
|
3734 | + foreach ($result as $minFailedFile) |
|
3534 | 3735 | echo ' |
3535 | 3736 | <link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">'; |
3536 | - |
|
3537 | - else |
|
3538 | - echo ' |
|
3737 | + } else { |
|
3738 | + echo ' |
|
3539 | 3739 | <link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">'; |
3740 | + } |
|
3540 | 3741 | } |
3541 | 3742 | |
3542 | 3743 | // Print the rest after the minified files. |
3543 | - if (!empty($normal)) |
|
3544 | - foreach ($normal as $nf) |
|
3744 | + if (!empty($normal)) { |
|
3745 | + foreach ($normal as $nf) |
|
3545 | 3746 | echo ' |
3546 | 3747 | <link rel="stylesheet" href="', $nf ,'">'; |
3748 | + } |
|
3547 | 3749 | |
3548 | 3750 | if ($db_show_debug === true) |
3549 | 3751 | { |
3550 | 3752 | // Try to keep only what's useful. |
3551 | 3753 | $repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => ''); |
3552 | - foreach ($context['css_files'] as $file) |
|
3553 | - $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3754 | + foreach ($context['css_files'] as $file) { |
|
3755 | + $context['debug']['sheets'][] = strtr($file['fileName'], $repl); |
|
3756 | + } |
|
3554 | 3757 | } |
3555 | 3758 | |
3556 | 3759 | if (!empty($context['css_header'])) |
@@ -3558,9 +3761,10 @@ discard block |
||
3558 | 3761 | echo ' |
3559 | 3762 | <style>'; |
3560 | 3763 | |
3561 | - foreach ($context['css_header'] as $css) |
|
3562 | - echo $css .' |
|
3764 | + foreach ($context['css_header'] as $css) { |
|
3765 | + echo $css .' |
|
3563 | 3766 | '; |
3767 | + } |
|
3564 | 3768 | |
3565 | 3769 | echo' |
3566 | 3770 | </style>'; |
@@ -3584,15 +3788,17 @@ discard block |
||
3584 | 3788 | $type = !empty($type) && in_array($type, $types) ? $type : false; |
3585 | 3789 | $data = !empty($data) ? $data : false; |
3586 | 3790 | |
3587 | - if (empty($type) || empty($data)) |
|
3588 | - return false; |
|
3791 | + if (empty($type) || empty($data)) { |
|
3792 | + return false; |
|
3793 | + } |
|
3589 | 3794 | |
3590 | 3795 | // Did we already did this? |
3591 | 3796 | $toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400); |
3592 | 3797 | |
3593 | 3798 | // Already done? |
3594 | - if (!empty($toCache)) |
|
3595 | - return true; |
|
3799 | + if (!empty($toCache)) { |
|
3800 | + return true; |
|
3801 | + } |
|
3596 | 3802 | |
3597 | 3803 | // Yep, need a bunch of files. |
3598 | 3804 | require_once($sourcedir . '/minify/src/Minify.php'); |
@@ -3680,8 +3886,9 @@ discard block |
||
3680 | 3886 | global $modSettings, $smcFunc; |
3681 | 3887 | |
3682 | 3888 | // Just make up a nice hash... |
3683 | - if ($new) |
|
3684 | - return sha1(md5($filename . time()) . mt_rand()); |
|
3889 | + if ($new) { |
|
3890 | + return sha1(md5($filename . time()) . mt_rand()); |
|
3891 | + } |
|
3685 | 3892 | |
3686 | 3893 | // Grab the file hash if it wasn't added. |
3687 | 3894 | // Left this for legacy. |
@@ -3695,23 +3902,25 @@ discard block |
||
3695 | 3902 | 'id_attach' => $attachment_id, |
3696 | 3903 | )); |
3697 | 3904 | |
3698 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
3699 | - return false; |
|
3905 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
3906 | + return false; |
|
3907 | + } |
|
3700 | 3908 | |
3701 | 3909 | list ($file_hash) = $smcFunc['db_fetch_row']($request); |
3702 | 3910 | $smcFunc['db_free_result']($request); |
3703 | 3911 | } |
3704 | 3912 | |
3705 | 3913 | // Still no hash? mmm... |
3706 | - if (empty($file_hash)) |
|
3707 | - $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3914 | + if (empty($file_hash)) { |
|
3915 | + $file_hash = sha1(md5($filename . time()) . mt_rand()); |
|
3916 | + } |
|
3708 | 3917 | |
3709 | 3918 | // Are we using multiple directories? |
3710 | - if (!empty($modSettings['currentAttachmentUploadDir'])) |
|
3711 | - $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3712 | - |
|
3713 | - else |
|
3714 | - $path = $modSettings['attachmentUploadDir']; |
|
3919 | + if (!empty($modSettings['currentAttachmentUploadDir'])) { |
|
3920 | + $path = $modSettings['attachmentUploadDir'][$dir]; |
|
3921 | + } else { |
|
3922 | + $path = $modSettings['attachmentUploadDir']; |
|
3923 | + } |
|
3715 | 3924 | |
3716 | 3925 | return $path . '/' . $attachment_id . '_' . $file_hash .'.dat'; |
3717 | 3926 | } |
@@ -3726,8 +3935,9 @@ discard block |
||
3726 | 3935 | function ip2range($fullip) |
3727 | 3936 | { |
3728 | 3937 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
3729 | - if ($fullip == 'unknown') |
|
3730 | - $fullip = '255.255.255.255'; |
|
3938 | + if ($fullip == 'unknown') { |
|
3939 | + $fullip = '255.255.255.255'; |
|
3940 | + } |
|
3731 | 3941 | |
3732 | 3942 | $ip_parts = explode('-', $fullip); |
3733 | 3943 | $ip_array = array(); |
@@ -3751,10 +3961,11 @@ discard block |
||
3751 | 3961 | $ip_array['low'] = $ip_parts[0]; |
3752 | 3962 | $ip_array['high'] = $ip_parts[1]; |
3753 | 3963 | return $ip_array; |
3754 | - } |
|
3755 | - elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.* |
|
3964 | + } elseif (count($ip_parts) == 2) { |
|
3965 | + // if ip 22.22.*-22.22.* |
|
3756 | 3966 | { |
3757 | 3967 | $valid_low = isValidIP($ip_parts[0]); |
3968 | + } |
|
3758 | 3969 | $valid_high = isValidIP($ip_parts[1]); |
3759 | 3970 | $count = 0; |
3760 | 3971 | $mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.'); |
@@ -3769,7 +3980,9 @@ discard block |
||
3769 | 3980 | $ip_parts[0] .= $mode . $min; |
3770 | 3981 | $valid_low = isValidIP($ip_parts[0]); |
3771 | 3982 | $count++; |
3772 | - if ($count > 9) break; |
|
3983 | + if ($count > 9) { |
|
3984 | + break; |
|
3985 | + } |
|
3773 | 3986 | } |
3774 | 3987 | } |
3775 | 3988 | |
@@ -3783,7 +3996,9 @@ discard block |
||
3783 | 3996 | $ip_parts[1] .= $mode . $max; |
3784 | 3997 | $valid_high = isValidIP($ip_parts[1]); |
3785 | 3998 | $count++; |
3786 | - if ($count > 9) break; |
|
3999 | + if ($count > 9) { |
|
4000 | + break; |
|
4001 | + } |
|
3787 | 4002 | } |
3788 | 4003 | } |
3789 | 4004 | |
@@ -3808,46 +4023,54 @@ discard block |
||
3808 | 4023 | { |
3809 | 4024 | global $modSettings; |
3810 | 4025 | |
3811 | - if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) |
|
3812 | - return $host; |
|
4026 | + if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) { |
|
4027 | + return $host; |
|
4028 | + } |
|
3813 | 4029 | $t = microtime(); |
3814 | 4030 | |
3815 | 4031 | // Try the Linux host command, perhaps? |
3816 | 4032 | if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1) |
3817 | 4033 | { |
3818 | - if (!isset($modSettings['host_to_dis'])) |
|
3819 | - $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
3820 | - else |
|
3821 | - $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4034 | + if (!isset($modSettings['host_to_dis'])) { |
|
4035 | + $test = @shell_exec('host -W 1 ' . @escapeshellarg($ip)); |
|
4036 | + } else { |
|
4037 | + $test = @shell_exec('host ' . @escapeshellarg($ip)); |
|
4038 | + } |
|
3822 | 4039 | |
3823 | 4040 | // Did host say it didn't find anything? |
3824 | - if (strpos($test, 'not found') !== false) |
|
3825 | - $host = ''; |
|
4041 | + if (strpos($test, 'not found') !== false) { |
|
4042 | + $host = ''; |
|
4043 | + } |
|
3826 | 4044 | // Invalid server option? |
3827 | - elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) |
|
3828 | - updateSettings(array('host_to_dis' => 1)); |
|
4045 | + elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) { |
|
4046 | + updateSettings(array('host_to_dis' => 1)); |
|
4047 | + } |
|
3829 | 4048 | // Maybe it found something, after all? |
3830 | - elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) |
|
3831 | - $host = $match[1]; |
|
4049 | + elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) { |
|
4050 | + $host = $match[1]; |
|
4051 | + } |
|
3832 | 4052 | } |
3833 | 4053 | |
3834 | 4054 | // This is nslookup; usually only Windows, but possibly some Unix? |
3835 | 4055 | if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1) |
3836 | 4056 | { |
3837 | 4057 | $test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip)); |
3838 | - if (strpos($test, 'Non-existent domain') !== false) |
|
3839 | - $host = ''; |
|
3840 | - elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) |
|
3841 | - $host = $match[1]; |
|
4058 | + if (strpos($test, 'Non-existent domain') !== false) { |
|
4059 | + $host = ''; |
|
4060 | + } elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) { |
|
4061 | + $host = $match[1]; |
|
4062 | + } |
|
3842 | 4063 | } |
3843 | 4064 | |
3844 | 4065 | // This is the last try :/. |
3845 | - if (!isset($host) || $host === false) |
|
3846 | - $host = @gethostbyaddr($ip); |
|
4066 | + if (!isset($host) || $host === false) { |
|
4067 | + $host = @gethostbyaddr($ip); |
|
4068 | + } |
|
3847 | 4069 | |
3848 | 4070 | // It took a long time, so let's cache it! |
3849 | - if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) |
|
3850 | - cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4071 | + if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) { |
|
4072 | + cache_put_data('hostlookup-' . $ip, $host, 600); |
|
4073 | + } |
|
3851 | 4074 | |
3852 | 4075 | return $host; |
3853 | 4076 | } |
@@ -3883,20 +4106,21 @@ discard block |
||
3883 | 4106 | { |
3884 | 4107 | $encrypted = substr(crypt($word, 'uk'), 2, $max_chars); |
3885 | 4108 | $total = 0; |
3886 | - for ($i = 0; $i < $max_chars; $i++) |
|
3887 | - $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4109 | + for ($i = 0; $i < $max_chars; $i++) { |
|
4110 | + $total += $possible_chars[ord($encrypted{$i})] * pow(63, $i); |
|
4111 | + } |
|
3888 | 4112 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
3889 | 4113 | } |
3890 | 4114 | } |
3891 | 4115 | return array_unique($returned_ints); |
3892 | - } |
|
3893 | - else |
|
4116 | + } else |
|
3894 | 4117 | { |
3895 | 4118 | // Trim characters before and after and add slashes for database insertion. |
3896 | 4119 | $returned_words = array(); |
3897 | - foreach ($words as $word) |
|
3898 | - if (($word = trim($word, '-_\'')) !== '') |
|
4120 | + foreach ($words as $word) { |
|
4121 | + if (($word = trim($word, '-_\'')) !== '') |
|
3899 | 4122 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
4123 | + } |
|
3900 | 4124 | |
3901 | 4125 | // Filter out all words that occur more than once. |
3902 | 4126 | return array_unique($returned_words); |
@@ -3918,16 +4142,18 @@ discard block |
||
3918 | 4142 | global $settings, $txt; |
3919 | 4143 | |
3920 | 4144 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
3921 | - if (function_exists('template_create_button') && !$force_use) |
|
3922 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4145 | + if (function_exists('template_create_button') && !$force_use) { |
|
4146 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
4147 | + } |
|
3923 | 4148 | |
3924 | - if (!$settings['use_image_buttons']) |
|
3925 | - return $txt[$alt]; |
|
3926 | - elseif (!empty($settings['use_buttons'])) |
|
3927 | - return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
3928 | - else |
|
3929 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
3930 | -} |
|
4149 | + if (!$settings['use_image_buttons']) { |
|
4150 | + return $txt[$alt]; |
|
4151 | + } elseif (!empty($settings['use_buttons'])) { |
|
4152 | + return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
4153 | + } else { |
|
4154 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>'; |
|
4155 | + } |
|
4156 | + } |
|
3931 | 4157 | |
3932 | 4158 | /** |
3933 | 4159 | * Sets up all of the top menu buttons |
@@ -3970,9 +4196,10 @@ discard block |
||
3970 | 4196 | var user_menus = new smc_PopupMenu(); |
3971 | 4197 | user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup"); |
3972 | 4198 | user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true); |
3973 | - if ($context['allow_pm']) |
|
3974 | - addInlineJavaScript(' |
|
4199 | + if ($context['allow_pm']) { |
|
4200 | + addInlineJavaScript(' |
|
3975 | 4201 | user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true); |
4202 | + } |
|
3976 | 4203 | |
3977 | 4204 | if (!empty($modSettings['enable_ajax_alerts'])) |
3978 | 4205 | { |
@@ -4132,88 +4359,96 @@ discard block |
||
4132 | 4359 | |
4133 | 4360 | // Now we put the buttons in the context so the theme can use them. |
4134 | 4361 | $menu_buttons = array(); |
4135 | - foreach ($buttons as $act => $button) |
|
4136 | - if (!empty($button['show'])) |
|
4362 | + foreach ($buttons as $act => $button) { |
|
4363 | + if (!empty($button['show'])) |
|
4137 | 4364 | { |
4138 | 4365 | $button['active_button'] = false; |
4366 | + } |
|
4139 | 4367 | |
4140 | 4368 | // This button needs some action. |
4141 | - if (isset($button['action_hook'])) |
|
4142 | - $needs_action_hook = true; |
|
4369 | + if (isset($button['action_hook'])) { |
|
4370 | + $needs_action_hook = true; |
|
4371 | + } |
|
4143 | 4372 | |
4144 | 4373 | // Make sure the last button truly is the last button. |
4145 | 4374 | if (!empty($button['is_last'])) |
4146 | 4375 | { |
4147 | - if (isset($last_button)) |
|
4148 | - unset($menu_buttons[$last_button]['is_last']); |
|
4376 | + if (isset($last_button)) { |
|
4377 | + unset($menu_buttons[$last_button]['is_last']); |
|
4378 | + } |
|
4149 | 4379 | $last_button = $act; |
4150 | 4380 | } |
4151 | 4381 | |
4152 | 4382 | // Go through the sub buttons if there are any. |
4153 | - if (!empty($button['sub_buttons'])) |
|
4154 | - foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4383 | + if (!empty($button['sub_buttons'])) { |
|
4384 | + foreach ($button['sub_buttons'] as $key => $subbutton) |
|
4155 | 4385 | { |
4156 | 4386 | if (empty($subbutton['show'])) |
4157 | 4387 | unset($button['sub_buttons'][$key]); |
4388 | + } |
|
4158 | 4389 | |
4159 | 4390 | // 2nd level sub buttons next... |
4160 | 4391 | if (!empty($subbutton['sub_buttons'])) |
4161 | 4392 | { |
4162 | 4393 | foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) |
4163 | 4394 | { |
4164 | - if (empty($sub_button2['show'])) |
|
4165 | - unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4395 | + if (empty($sub_button2['show'])) { |
|
4396 | + unset($button['sub_buttons'][$key]['sub_buttons'][$key2]); |
|
4397 | + } |
|
4166 | 4398 | } |
4167 | 4399 | } |
4168 | 4400 | } |
4169 | 4401 | |
4170 | 4402 | // Does this button have its own icon? |
4171 | - if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) |
|
4172 | - $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4173 | - elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) |
|
4174 | - $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4175 | - elseif (isset($button['icon'])) |
|
4176 | - $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4177 | - else |
|
4178 | - $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4403 | + if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) { |
|
4404 | + $button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4405 | + } elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) { |
|
4406 | + $button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">'; |
|
4407 | + } elseif (isset($button['icon'])) { |
|
4408 | + $button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>'; |
|
4409 | + } else { |
|
4410 | + $button['icon'] = '<span class="generic_icons ' . $act . '"></span>'; |
|
4411 | + } |
|
4179 | 4412 | |
4180 | 4413 | $menu_buttons[$act] = $button; |
4181 | 4414 | } |
4182 | 4415 | |
4183 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
4184 | - cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4416 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
4417 | + cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime); |
|
4418 | + } |
|
4185 | 4419 | } |
4186 | 4420 | |
4187 | 4421 | $context['menu_buttons'] = $menu_buttons; |
4188 | 4422 | |
4189 | 4423 | // Logging out requires the session id in the url. |
4190 | - if (isset($context['menu_buttons']['logout'])) |
|
4191 | - $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4424 | + if (isset($context['menu_buttons']['logout'])) { |
|
4425 | + $context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']); |
|
4426 | + } |
|
4192 | 4427 | |
4193 | 4428 | // Figure out which action we are doing so we can set the active tab. |
4194 | 4429 | // Default to home. |
4195 | 4430 | $current_action = 'home'; |
4196 | 4431 | |
4197 | - if (isset($context['menu_buttons'][$context['current_action']])) |
|
4198 | - $current_action = $context['current_action']; |
|
4199 | - elseif ($context['current_action'] == 'search2') |
|
4200 | - $current_action = 'search'; |
|
4201 | - elseif ($context['current_action'] == 'theme') |
|
4202 | - $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4203 | - elseif ($context['current_action'] == 'register2') |
|
4204 | - $current_action = 'register'; |
|
4205 | - elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) |
|
4206 | - $current_action = 'login'; |
|
4207 | - elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) |
|
4208 | - $current_action = 'moderate'; |
|
4432 | + if (isset($context['menu_buttons'][$context['current_action']])) { |
|
4433 | + $current_action = $context['current_action']; |
|
4434 | + } elseif ($context['current_action'] == 'search2') { |
|
4435 | + $current_action = 'search'; |
|
4436 | + } elseif ($context['current_action'] == 'theme') { |
|
4437 | + $current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin'; |
|
4438 | + } elseif ($context['current_action'] == 'register2') { |
|
4439 | + $current_action = 'register'; |
|
4440 | + } elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) { |
|
4441 | + $current_action = 'login'; |
|
4442 | + } elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) { |
|
4443 | + $current_action = 'moderate'; |
|
4444 | + } |
|
4209 | 4445 | |
4210 | 4446 | // There are certain exceptions to the above where we don't want anything on the menu highlighted. |
4211 | 4447 | if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner'])) |
4212 | 4448 | { |
4213 | 4449 | $current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile'; |
4214 | 4450 | $context[$current_action] = true; |
4215 | - } |
|
4216 | - elseif ($context['current_action'] == 'pm') |
|
4451 | + } elseif ($context['current_action'] == 'pm') |
|
4217 | 4452 | { |
4218 | 4453 | $current_action = 'self_pm'; |
4219 | 4454 | $context['self_pm'] = true; |
@@ -4256,12 +4491,14 @@ discard block |
||
4256 | 4491 | } |
4257 | 4492 | |
4258 | 4493 | // Not all actions are simple. |
4259 | - if (!empty($needs_action_hook)) |
|
4260 | - call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4494 | + if (!empty($needs_action_hook)) { |
|
4495 | + call_integration_hook('integrate_current_action', array(&$current_action)); |
|
4496 | + } |
|
4261 | 4497 | |
4262 | - if (isset($context['menu_buttons'][$current_action])) |
|
4263 | - $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4264 | -} |
|
4498 | + if (isset($context['menu_buttons'][$current_action])) { |
|
4499 | + $context['menu_buttons'][$current_action]['active_button'] = true; |
|
4500 | + } |
|
4501 | + } |
|
4265 | 4502 | |
4266 | 4503 | /** |
4267 | 4504 | * Generate a random seed and ensure it's stored in settings. |
@@ -4285,16 +4522,19 @@ discard block |
||
4285 | 4522 | global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug; |
4286 | 4523 | global $context, $txt; |
4287 | 4524 | |
4288 | - if ($db_show_debug === true) |
|
4289 | - $context['debug']['hooks'][] = $hook; |
|
4525 | + if ($db_show_debug === true) { |
|
4526 | + $context['debug']['hooks'][] = $hook; |
|
4527 | + } |
|
4290 | 4528 | |
4291 | 4529 | // Need to have some control. |
4292 | - if (!isset($context['instances'])) |
|
4293 | - $context['instances'] = array(); |
|
4530 | + if (!isset($context['instances'])) { |
|
4531 | + $context['instances'] = array(); |
|
4532 | + } |
|
4294 | 4533 | |
4295 | 4534 | $results = array(); |
4296 | - if (empty($modSettings[$hook])) |
|
4297 | - return $results; |
|
4535 | + if (empty($modSettings[$hook])) { |
|
4536 | + return $results; |
|
4537 | + } |
|
4298 | 4538 | |
4299 | 4539 | // Define some needed vars. |
4300 | 4540 | $function = false; |
@@ -4304,14 +4544,16 @@ discard block |
||
4304 | 4544 | foreach ($functions as $function) |
4305 | 4545 | { |
4306 | 4546 | // Hook has been marked as "disabled". Skip it! |
4307 | - if (strpos($function, '!') !== false) |
|
4308 | - continue; |
|
4547 | + if (strpos($function, '!') !== false) { |
|
4548 | + continue; |
|
4549 | + } |
|
4309 | 4550 | |
4310 | 4551 | $call = call_helper($function, true); |
4311 | 4552 | |
4312 | 4553 | // Is it valid? |
4313 | - if (!empty($call)) |
|
4314 | - $results[$function] = call_user_func_array($call, $parameters); |
|
4554 | + if (!empty($call)) { |
|
4555 | + $results[$function] = call_user_func_array($call, $parameters); |
|
4556 | + } |
|
4315 | 4557 | |
4316 | 4558 | // Whatever it was suppose to call, it failed :( |
4317 | 4559 | elseif (!empty($function)) |
@@ -4327,8 +4569,9 @@ discard block |
||
4327 | 4569 | } |
4328 | 4570 | |
4329 | 4571 | // "Assume" the file resides on $boarddir somewhere... |
4330 | - else |
|
4331 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4572 | + else { |
|
4573 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
4574 | + } |
|
4332 | 4575 | } |
4333 | 4576 | } |
4334 | 4577 | |
@@ -4350,12 +4593,14 @@ discard block |
||
4350 | 4593 | global $smcFunc, $modSettings; |
4351 | 4594 | |
4352 | 4595 | // Any objects? |
4353 | - if ($object) |
|
4354 | - $function = $function . '#'; |
|
4596 | + if ($object) { |
|
4597 | + $function = $function . '#'; |
|
4598 | + } |
|
4355 | 4599 | |
4356 | 4600 | // Any files to load? |
4357 | - if (!empty($file) && is_string($file)) |
|
4358 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4601 | + if (!empty($file) && is_string($file)) { |
|
4602 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
4603 | + } |
|
4359 | 4604 | |
4360 | 4605 | // Get the correct string. |
4361 | 4606 | $integration_call = $function; |
@@ -4377,13 +4622,14 @@ discard block |
||
4377 | 4622 | if (!empty($current_functions)) |
4378 | 4623 | { |
4379 | 4624 | $current_functions = explode(',', $current_functions); |
4380 | - if (in_array($integration_call, $current_functions)) |
|
4381 | - return; |
|
4625 | + if (in_array($integration_call, $current_functions)) { |
|
4626 | + return; |
|
4627 | + } |
|
4382 | 4628 | |
4383 | 4629 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
4630 | + } else { |
|
4631 | + $permanent_functions = array($integration_call); |
|
4384 | 4632 | } |
4385 | - else |
|
4386 | - $permanent_functions = array($integration_call); |
|
4387 | 4633 | |
4388 | 4634 | updateSettings(array($hook => implode(',', $permanent_functions))); |
4389 | 4635 | } |
@@ -4392,8 +4638,9 @@ discard block |
||
4392 | 4638 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4393 | 4639 | |
4394 | 4640 | // Do nothing, if it's already there. |
4395 | - if (in_array($integration_call, $functions)) |
|
4396 | - return; |
|
4641 | + if (in_array($integration_call, $functions)) { |
|
4642 | + return; |
|
4643 | + } |
|
4397 | 4644 | |
4398 | 4645 | $functions[] = $integration_call; |
4399 | 4646 | $modSettings[$hook] = implode(',', $functions); |
@@ -4416,12 +4663,14 @@ discard block |
||
4416 | 4663 | global $smcFunc, $modSettings; |
4417 | 4664 | |
4418 | 4665 | // Any objects? |
4419 | - if ($object) |
|
4420 | - $function = $function . '#'; |
|
4666 | + if ($object) { |
|
4667 | + $function = $function . '#'; |
|
4668 | + } |
|
4421 | 4669 | |
4422 | 4670 | // Any files to load? |
4423 | - if (!empty($file) && is_string($file)) |
|
4424 | - $function = $file . '|' . $function; |
|
4671 | + if (!empty($file) && is_string($file)) { |
|
4672 | + $function = $file . '|' . $function; |
|
4673 | + } |
|
4425 | 4674 | |
4426 | 4675 | // Get the correct string. |
4427 | 4676 | $integration_call = $function; |
@@ -4442,16 +4691,18 @@ discard block |
||
4442 | 4691 | { |
4443 | 4692 | $current_functions = explode(',', $current_functions); |
4444 | 4693 | |
4445 | - if (in_array($integration_call, $current_functions)) |
|
4446 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4694 | + if (in_array($integration_call, $current_functions)) { |
|
4695 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
4696 | + } |
|
4447 | 4697 | } |
4448 | 4698 | |
4449 | 4699 | // Turn the function list into something usable. |
4450 | 4700 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
4451 | 4701 | |
4452 | 4702 | // You can only remove it if it's available. |
4453 | - if (!in_array($integration_call, $functions)) |
|
4454 | - return; |
|
4703 | + if (!in_array($integration_call, $functions)) { |
|
4704 | + return; |
|
4705 | + } |
|
4455 | 4706 | |
4456 | 4707 | $functions = array_diff($functions, array($integration_call)); |
4457 | 4708 | $modSettings[$hook] = implode(',', $functions); |
@@ -4472,17 +4723,20 @@ discard block |
||
4472 | 4723 | global $context, $smcFunc, $txt, $db_show_debug; |
4473 | 4724 | |
4474 | 4725 | // Really? |
4475 | - if (empty($string)) |
|
4476 | - return false; |
|
4726 | + if (empty($string)) { |
|
4727 | + return false; |
|
4728 | + } |
|
4477 | 4729 | |
4478 | 4730 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
4479 | 4731 | // A closure? should be a callable one. |
4480 | - if (is_array($string) || $string instanceof Closure) |
|
4481 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4732 | + if (is_array($string) || $string instanceof Closure) { |
|
4733 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
4734 | + } |
|
4482 | 4735 | |
4483 | 4736 | // No full objects, sorry! pass a method or a property instead! |
4484 | - if (is_object($string)) |
|
4485 | - return false; |
|
4737 | + if (is_object($string)) { |
|
4738 | + return false; |
|
4739 | + } |
|
4486 | 4740 | |
4487 | 4741 | // Stay vitaminized my friends... |
4488 | 4742 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4491,8 +4745,9 @@ discard block |
||
4491 | 4745 | $string = load_file($string); |
4492 | 4746 | |
4493 | 4747 | // Loaded file failed |
4494 | - if (empty($string)) |
|
4495 | - return false; |
|
4748 | + if (empty($string)) { |
|
4749 | + return false; |
|
4750 | + } |
|
4496 | 4751 | |
4497 | 4752 | // Found a method. |
4498 | 4753 | if (strpos($string, '::') !== false) |
@@ -4513,8 +4768,9 @@ discard block |
||
4513 | 4768 | // Add another one to the list. |
4514 | 4769 | if ($db_show_debug === true) |
4515 | 4770 | { |
4516 | - if (!isset($context['debug']['instances'])) |
|
4517 | - $context['debug']['instances'] = array(); |
|
4771 | + if (!isset($context['debug']['instances'])) { |
|
4772 | + $context['debug']['instances'] = array(); |
|
4773 | + } |
|
4518 | 4774 | |
4519 | 4775 | $context['debug']['instances'][$class] = $class; |
4520 | 4776 | } |
@@ -4524,13 +4780,15 @@ discard block |
||
4524 | 4780 | } |
4525 | 4781 | |
4526 | 4782 | // Right then. This is a call to a static method. |
4527 | - else |
|
4528 | - $func = array($class, $method); |
|
4783 | + else { |
|
4784 | + $func = array($class, $method); |
|
4785 | + } |
|
4529 | 4786 | } |
4530 | 4787 | |
4531 | 4788 | // Nope! just a plain regular function. |
4532 | - else |
|
4533 | - $func = $string; |
|
4789 | + else { |
|
4790 | + $func = $string; |
|
4791 | + } |
|
4534 | 4792 | |
4535 | 4793 | // Right, we got what we need, time to do some checks. |
4536 | 4794 | if (!is_callable($func, false, $callable_name)) |
@@ -4546,17 +4804,18 @@ discard block |
||
4546 | 4804 | else |
4547 | 4805 | { |
4548 | 4806 | // What are we gonna do about it? |
4549 | - if ($return) |
|
4550 | - return $func; |
|
4807 | + if ($return) { |
|
4808 | + return $func; |
|
4809 | + } |
|
4551 | 4810 | |
4552 | 4811 | // If this is a plain function, avoid the heat of calling call_user_func(). |
4553 | 4812 | else |
4554 | 4813 | { |
4555 | - if (is_array($func)) |
|
4556 | - call_user_func($func); |
|
4557 | - |
|
4558 | - else |
|
4559 | - $func(); |
|
4814 | + if (is_array($func)) { |
|
4815 | + call_user_func($func); |
|
4816 | + } else { |
|
4817 | + $func(); |
|
4818 | + } |
|
4560 | 4819 | } |
4561 | 4820 | } |
4562 | 4821 | } |
@@ -4573,31 +4832,34 @@ discard block |
||
4573 | 4832 | { |
4574 | 4833 | global $sourcedir, $txt, $boarddir, $settings; |
4575 | 4834 | |
4576 | - if (empty($string)) |
|
4577 | - return false; |
|
4835 | + if (empty($string)) { |
|
4836 | + return false; |
|
4837 | + } |
|
4578 | 4838 | |
4579 | 4839 | if (strpos($string, '|') !== false) |
4580 | 4840 | { |
4581 | 4841 | list ($file, $string) = explode('|', $string); |
4582 | 4842 | |
4583 | 4843 | // Match the wildcards to their regular vars. |
4584 | - if (empty($settings['theme_dir'])) |
|
4585 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4586 | - |
|
4587 | - else |
|
4588 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4844 | + if (empty($settings['theme_dir'])) { |
|
4845 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
4846 | + } else { |
|
4847 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
4848 | + } |
|
4589 | 4849 | |
4590 | 4850 | // Load the file if it can be loaded. |
4591 | - if (file_exists($absPath)) |
|
4592 | - require_once($absPath); |
|
4851 | + if (file_exists($absPath)) { |
|
4852 | + require_once($absPath); |
|
4853 | + } |
|
4593 | 4854 | |
4594 | 4855 | // No? try a fallback to $sourcedir |
4595 | 4856 | else |
4596 | 4857 | { |
4597 | 4858 | $absPath = $sourcedir .'/'. $file; |
4598 | 4859 | |
4599 | - if (file_exists($absPath)) |
|
4600 | - require_once($absPath); |
|
4860 | + if (file_exists($absPath)) { |
|
4861 | + require_once($absPath); |
|
4862 | + } |
|
4601 | 4863 | |
4602 | 4864 | // Sorry, can't do much for you at this point. |
4603 | 4865 | else |
@@ -4624,8 +4886,9 @@ discard block |
||
4624 | 4886 | global $user_info, $smcFunc; |
4625 | 4887 | |
4626 | 4888 | // Make sure we have something to work with. |
4627 | - if (empty($topic)) |
|
4628 | - return array(); |
|
4889 | + if (empty($topic)) { |
|
4890 | + return array(); |
|
4891 | + } |
|
4629 | 4892 | |
4630 | 4893 | |
4631 | 4894 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4648,8 +4911,9 @@ discard block |
||
4648 | 4911 | 'topic' => $topic, |
4649 | 4912 | ) |
4650 | 4913 | ); |
4651 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
4652 | - $temp[] = (int) $row['content_id']; |
|
4914 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
4915 | + $temp[] = (int) $row['content_id']; |
|
4916 | + } |
|
4653 | 4917 | |
4654 | 4918 | cache_put_data($cache_key, $temp, $ttl); |
4655 | 4919 | } |
@@ -4670,8 +4934,9 @@ discard block |
||
4670 | 4934 | { |
4671 | 4935 | global $context; |
4672 | 4936 | |
4673 | - if (empty($string)) |
|
4674 | - return $string; |
|
4937 | + if (empty($string)) { |
|
4938 | + return $string; |
|
4939 | + } |
|
4675 | 4940 | |
4676 | 4941 | // UTF-8 occurences of MS special characters |
4677 | 4942 | $findchars_utf8 = array( |
@@ -4712,10 +4977,11 @@ discard block |
||
4712 | 4977 | '--', // — |
4713 | 4978 | ); |
4714 | 4979 | |
4715 | - if ($context['utf8']) |
|
4716 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4717 | - else |
|
4718 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
4980 | + if ($context['utf8']) { |
|
4981 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
4982 | + } else { |
|
4983 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
4984 | + } |
|
4719 | 4985 | |
4720 | 4986 | return $string; |
4721 | 4987 | } |
@@ -4734,49 +5000,59 @@ discard block |
||
4734 | 5000 | { |
4735 | 5001 | global $context; |
4736 | 5002 | |
4737 | - if (!isset($matches[2])) |
|
4738 | - return ''; |
|
5003 | + if (!isset($matches[2])) { |
|
5004 | + return ''; |
|
5005 | + } |
|
4739 | 5006 | |
4740 | 5007 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4741 | 5008 | |
4742 | 5009 | // remove left to right / right to left overrides |
4743 | - if ($num === 0x202D || $num === 0x202E) |
|
4744 | - return ''; |
|
5010 | + if ($num === 0x202D || $num === 0x202E) { |
|
5011 | + return ''; |
|
5012 | + } |
|
4745 | 5013 | |
4746 | 5014 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
4747 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
4748 | - return '&#' . $num . ';'; |
|
5015 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
5016 | + return '&#' . $num . ';'; |
|
5017 | + } |
|
4749 | 5018 | |
4750 | 5019 | if (empty($context['utf8'])) |
4751 | 5020 | { |
4752 | 5021 | // no control characters |
4753 | - if ($num < 0x20) |
|
4754 | - return ''; |
|
5022 | + if ($num < 0x20) { |
|
5023 | + return ''; |
|
5024 | + } |
|
4755 | 5025 | // text is text |
4756 | - elseif ($num < 0x80) |
|
4757 | - return chr($num); |
|
5026 | + elseif ($num < 0x80) { |
|
5027 | + return chr($num); |
|
5028 | + } |
|
4758 | 5029 | // all others get html-ised |
4759 | - else |
|
4760 | - return '&#' . $matches[2] . ';'; |
|
4761 | - } |
|
4762 | - else |
|
5030 | + else { |
|
5031 | + return '&#' . $matches[2] . ';'; |
|
5032 | + } |
|
5033 | + } else |
|
4763 | 5034 | { |
4764 | 5035 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
4765 | 5036 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
4766 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
4767 | - return ''; |
|
5037 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
5038 | + return ''; |
|
5039 | + } |
|
4768 | 5040 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4769 | - elseif ($num < 0x80) |
|
4770 | - return chr($num); |
|
5041 | + elseif ($num < 0x80) { |
|
5042 | + return chr($num); |
|
5043 | + } |
|
4771 | 5044 | // <0x800 (2048) |
4772 | - elseif ($num < 0x800) |
|
4773 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5045 | + elseif ($num < 0x800) { |
|
5046 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5047 | + } |
|
4774 | 5048 | // < 0x10000 (65536) |
4775 | - elseif ($num < 0x10000) |
|
4776 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5049 | + elseif ($num < 0x10000) { |
|
5050 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5051 | + } |
|
4777 | 5052 | // <= 0x10FFFF (1114111) |
4778 | - else |
|
4779 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5053 | + else { |
|
5054 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5055 | + } |
|
4780 | 5056 | } |
4781 | 5057 | } |
4782 | 5058 | |
@@ -4792,28 +5068,34 @@ discard block |
||
4792 | 5068 | */ |
4793 | 5069 | function fixchar__callback($matches) |
4794 | 5070 | { |
4795 | - if (!isset($matches[1])) |
|
4796 | - return ''; |
|
5071 | + if (!isset($matches[1])) { |
|
5072 | + return ''; |
|
5073 | + } |
|
4797 | 5074 | |
4798 | 5075 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
4799 | 5076 | |
4800 | 5077 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
4801 | 5078 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
4802 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
4803 | - return ''; |
|
5079 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
5080 | + return ''; |
|
5081 | + } |
|
4804 | 5082 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
4805 | - elseif ($num < 0x80) |
|
4806 | - return chr($num); |
|
5083 | + elseif ($num < 0x80) { |
|
5084 | + return chr($num); |
|
5085 | + } |
|
4807 | 5086 | // <0x800 (2048) |
4808 | - elseif ($num < 0x800) |
|
4809 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5087 | + elseif ($num < 0x800) { |
|
5088 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
5089 | + } |
|
4810 | 5090 | // < 0x10000 (65536) |
4811 | - elseif ($num < 0x10000) |
|
4812 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5091 | + elseif ($num < 0x10000) { |
|
5092 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5093 | + } |
|
4813 | 5094 | // <= 0x10FFFF (1114111) |
4814 | - else |
|
4815 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
4816 | -} |
|
5095 | + else { |
|
5096 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
5097 | + } |
|
5098 | + } |
|
4817 | 5099 | |
4818 | 5100 | /** |
4819 | 5101 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4826,17 +5108,19 @@ discard block |
||
4826 | 5108 | */ |
4827 | 5109 | function entity_fix__callback($matches) |
4828 | 5110 | { |
4829 | - if (!isset($matches[2])) |
|
4830 | - return ''; |
|
5111 | + if (!isset($matches[2])) { |
|
5112 | + return ''; |
|
5113 | + } |
|
4831 | 5114 | |
4832 | 5115 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
4833 | 5116 | |
4834 | 5117 | // we don't allow control characters, characters out of range, byte markers, etc |
4835 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
4836 | - return ''; |
|
4837 | - else |
|
4838 | - return '&#' . $num . ';'; |
|
4839 | -} |
|
5118 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
5119 | + return ''; |
|
5120 | + } else { |
|
5121 | + return '&#' . $num . ';'; |
|
5122 | + } |
|
5123 | + } |
|
4840 | 5124 | |
4841 | 5125 | /** |
4842 | 5126 | * Return a Gravatar URL based on |
@@ -4860,18 +5144,23 @@ discard block |
||
4860 | 5144 | $ratings = array('G', 'PG', 'R', 'X'); |
4861 | 5145 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
4862 | 5146 | $url_params = array(); |
4863 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
4864 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
4865 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
4866 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
4867 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
4868 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
4869 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
4870 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
5147 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
5148 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
5149 | + } |
|
5150 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
5151 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
5152 | + } |
|
5153 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
5154 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
5155 | + } |
|
5156 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
5157 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
4871 | 5158 | $size_string = $modSettings['avatar_max_height_external']; |
5159 | + } |
|
4872 | 5160 | |
4873 | - if (!empty($size_string)) |
|
4874 | - $url_params[] = 's=' . $size_string; |
|
5161 | + if (!empty($size_string)) { |
|
5162 | + $url_params[] = 's=' . $size_string; |
|
5163 | + } |
|
4875 | 5164 | } |
4876 | 5165 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
4877 | 5166 | |
@@ -4890,22 +5179,26 @@ discard block |
||
4890 | 5179 | static $timezones = null, $lastwhen = null; |
4891 | 5180 | |
4892 | 5181 | // No point doing this over if we already did it once |
4893 | - if (!empty($timezones) && $when == $lastwhen) |
|
4894 | - return $timezones; |
|
4895 | - else |
|
4896 | - $lastwhen = $when; |
|
5182 | + if (!empty($timezones) && $when == $lastwhen) { |
|
5183 | + return $timezones; |
|
5184 | + } else { |
|
5185 | + $lastwhen = $when; |
|
5186 | + } |
|
4897 | 5187 | |
4898 | 5188 | // Parseable datetime string? |
4899 | - if (is_int($timestamp = strtotime($when))) |
|
4900 | - $when = $timestamp; |
|
5189 | + if (is_int($timestamp = strtotime($when))) { |
|
5190 | + $when = $timestamp; |
|
5191 | + } |
|
4901 | 5192 | |
4902 | 5193 | // A Unix timestamp? |
4903 | - elseif (is_numeric($when)) |
|
4904 | - $when = intval($when); |
|
5194 | + elseif (is_numeric($when)) { |
|
5195 | + $when = intval($when); |
|
5196 | + } |
|
4905 | 5197 | |
4906 | 5198 | // Invalid value? Just get current Unix timestamp. |
4907 | - else |
|
4908 | - $when = time(); |
|
5199 | + else { |
|
5200 | + $when = time(); |
|
5201 | + } |
|
4909 | 5202 | |
4910 | 5203 | // We'll need this too |
4911 | 5204 | $later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U'); |
@@ -4968,8 +5261,9 @@ discard block |
||
4968 | 5261 | foreach ($priority_countries as $country) |
4969 | 5262 | { |
4970 | 5263 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
4971 | - if (!empty($country_tzids)) |
|
4972 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5264 | + if (!empty($country_tzids)) { |
|
5265 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
5266 | + } |
|
4973 | 5267 | } |
4974 | 5268 | |
4975 | 5269 | // Process the preferred timezones first, then the rest. |
@@ -4979,8 +5273,9 @@ discard block |
||
4979 | 5273 | foreach ($tzids as $tzid) |
4980 | 5274 | { |
4981 | 5275 | // We don't want UTC right now |
4982 | - if ($tzid == 'UTC') |
|
4983 | - continue; |
|
5276 | + if ($tzid == 'UTC') { |
|
5277 | + continue; |
|
5278 | + } |
|
4984 | 5279 | |
4985 | 5280 | // First, get the set of transition rules for this tzid |
4986 | 5281 | $tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later); |
@@ -4991,8 +5286,9 @@ discard block |
||
4991 | 5286 | $tz_location = timezone_location_get(timezone_open($tzid)); |
4992 | 5287 | |
4993 | 5288 | // Kazakstan |
4994 | - if ($tz_location['country_code'] == 'KZ') |
|
4995 | - $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5289 | + if ($tz_location['country_code'] == 'KZ') { |
|
5290 | + $tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']); |
|
5291 | + } |
|
4996 | 5292 | |
4997 | 5293 | // Russia likes to experiment with time zones |
4998 | 5294 | if ($tz_location['country_code'] == 'RU') |
@@ -5003,19 +5299,22 @@ discard block |
||
5003 | 5299 | } |
5004 | 5300 | |
5005 | 5301 | // Still no good? We'll just mark it as a UTC offset |
5006 | - if (strspn($tzinfo[0]['abbr'], '+-') > 0) |
|
5007 | - $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5302 | + if (strspn($tzinfo[0]['abbr'], '+-') > 0) { |
|
5303 | + $tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr']; |
|
5304 | + } |
|
5008 | 5305 | } |
5009 | 5306 | |
5010 | 5307 | $tzkey = serialize($tzinfo); |
5011 | 5308 | |
5012 | 5309 | // Don't overwrite our preferred tzids |
5013 | - if (empty($zones[$tzkey]['tzid'])) |
|
5014 | - $zones[$tzkey]['tzid'] = $tzid; |
|
5310 | + if (empty($zones[$tzkey]['tzid'])) { |
|
5311 | + $zones[$tzkey]['tzid'] = $tzid; |
|
5312 | + } |
|
5015 | 5313 | |
5016 | 5314 | // A time zone from a prioritized country? |
5017 | - if (in_array($tzid, $priority_tzids)) |
|
5018 | - $priority_zones[$tzkey] = true; |
|
5315 | + if (in_array($tzid, $priority_tzids)) { |
|
5316 | + $priority_zones[$tzkey] = true; |
|
5317 | + } |
|
5019 | 5318 | |
5020 | 5319 | // Keep track of the location and offset for this tzid |
5021 | 5320 | $tzid_parts = explode('/', $tzid); |
@@ -5033,15 +5332,17 @@ discard block |
||
5033 | 5332 | { |
5034 | 5333 | $tzinfo = unserialize($tzkey); |
5035 | 5334 | |
5036 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
5037 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5038 | - else |
|
5039 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5335 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
5336 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
5337 | + } else { |
|
5338 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
5339 | + } |
|
5040 | 5340 | |
5041 | - if (isset($priority_zones[$tzkey])) |
|
5042 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5043 | - else |
|
5044 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5341 | + if (isset($priority_zones[$tzkey])) { |
|
5342 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5343 | + } else { |
|
5344 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']'; |
|
5345 | + } |
|
5045 | 5346 | } |
5046 | 5347 | |
5047 | 5348 | $timezones = array_merge( |
@@ -5059,8 +5360,9 @@ discard block |
||
5059 | 5360 | */ |
5060 | 5361 | function inet_ptod($ip_address) |
5061 | 5362 | { |
5062 | - if (!isValidIP($ip_address)) |
|
5063 | - return $ip_address; |
|
5363 | + if (!isValidIP($ip_address)) { |
|
5364 | + return $ip_address; |
|
5365 | + } |
|
5064 | 5366 | |
5065 | 5367 | $bin = inet_pton($ip_address); |
5066 | 5368 | return $bin; |
@@ -5072,13 +5374,15 @@ discard block |
||
5072 | 5374 | */ |
5073 | 5375 | function inet_dtop($bin) |
5074 | 5376 | { |
5075 | - if(empty($bin)) |
|
5076 | - return ''; |
|
5377 | + if(empty($bin)) { |
|
5378 | + return ''; |
|
5379 | + } |
|
5077 | 5380 | |
5078 | 5381 | global $db_type; |
5079 | 5382 | |
5080 | - if ($db_type == 'postgresql') |
|
5081 | - return $bin; |
|
5383 | + if ($db_type == 'postgresql') { |
|
5384 | + return $bin; |
|
5385 | + } |
|
5082 | 5386 | |
5083 | 5387 | $ip_address = inet_ntop($bin); |
5084 | 5388 | |
@@ -5103,26 +5407,32 @@ discard block |
||
5103 | 5407 | */ |
5104 | 5408 | function _safe_serialize($value) |
5105 | 5409 | { |
5106 | - if(is_null($value)) |
|
5107 | - return 'N;'; |
|
5410 | + if(is_null($value)) { |
|
5411 | + return 'N;'; |
|
5412 | + } |
|
5108 | 5413 | |
5109 | - if(is_bool($value)) |
|
5110 | - return 'b:'. (int) $value .';'; |
|
5414 | + if(is_bool($value)) { |
|
5415 | + return 'b:'. (int) $value .';'; |
|
5416 | + } |
|
5111 | 5417 | |
5112 | - if(is_int($value)) |
|
5113 | - return 'i:'. $value .';'; |
|
5418 | + if(is_int($value)) { |
|
5419 | + return 'i:'. $value .';'; |
|
5420 | + } |
|
5114 | 5421 | |
5115 | - if(is_float($value)) |
|
5116 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
5422 | + if(is_float($value)) { |
|
5423 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
5424 | + } |
|
5117 | 5425 | |
5118 | - if(is_string($value)) |
|
5119 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
5426 | + if(is_string($value)) { |
|
5427 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
5428 | + } |
|
5120 | 5429 | |
5121 | 5430 | if(is_array($value)) |
5122 | 5431 | { |
5123 | 5432 | $out = ''; |
5124 | - foreach($value as $k => $v) |
|
5125 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5433 | + foreach($value as $k => $v) { |
|
5434 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
5435 | + } |
|
5126 | 5436 | |
5127 | 5437 | return 'a:'. count($value) .':{'. $out .'}'; |
5128 | 5438 | } |
@@ -5148,8 +5458,9 @@ discard block |
||
5148 | 5458 | |
5149 | 5459 | $out = _safe_serialize($value); |
5150 | 5460 | |
5151 | - if (isset($mbIntEnc)) |
|
5152 | - mb_internal_encoding($mbIntEnc); |
|
5461 | + if (isset($mbIntEnc)) { |
|
5462 | + mb_internal_encoding($mbIntEnc); |
|
5463 | + } |
|
5153 | 5464 | |
5154 | 5465 | return $out; |
5155 | 5466 | } |
@@ -5166,8 +5477,9 @@ discard block |
||
5166 | 5477 | function _safe_unserialize($str) |
5167 | 5478 | { |
5168 | 5479 | // Input is not a string. |
5169 | - if(empty($str) || !is_string($str)) |
|
5170 | - return false; |
|
5480 | + if(empty($str) || !is_string($str)) { |
|
5481 | + return false; |
|
5482 | + } |
|
5171 | 5483 | |
5172 | 5484 | $stack = array(); |
5173 | 5485 | $expected = array(); |
@@ -5183,43 +5495,38 @@ discard block |
||
5183 | 5495 | while($state != 1) |
5184 | 5496 | { |
5185 | 5497 | $type = isset($str[0]) ? $str[0] : ''; |
5186 | - if($type == '}') |
|
5187 | - $str = substr($str, 1); |
|
5188 | - |
|
5189 | - else if($type == 'N' && $str[1] == ';') |
|
5498 | + if($type == '}') { |
|
5499 | + $str = substr($str, 1); |
|
5500 | + } else if($type == 'N' && $str[1] == ';') |
|
5190 | 5501 | { |
5191 | 5502 | $value = null; |
5192 | 5503 | $str = substr($str, 2); |
5193 | - } |
|
5194 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5504 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
5195 | 5505 | { |
5196 | 5506 | $value = $matches[1] == '1' ? true : false; |
5197 | 5507 | $str = substr($str, 4); |
5198 | - } |
|
5199 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5508 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
5200 | 5509 | { |
5201 | 5510 | $value = (int)$matches[1]; |
5202 | 5511 | $str = $matches[2]; |
5203 | - } |
|
5204 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5512 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
5205 | 5513 | { |
5206 | 5514 | $value = (float)$matches[1]; |
5207 | 5515 | $str = $matches[3]; |
5208 | - } |
|
5209 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5516 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
5210 | 5517 | { |
5211 | 5518 | $value = substr($matches[2], 0, (int)$matches[1]); |
5212 | 5519 | $str = substr($matches[2], (int)$matches[1] + 2); |
5213 | - } |
|
5214 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5520 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
5215 | 5521 | { |
5216 | 5522 | $expectedLength = (int)$matches[1]; |
5217 | 5523 | $str = $matches[2]; |
5218 | 5524 | } |
5219 | 5525 | |
5220 | 5526 | // Object or unknown/malformed type. |
5221 | - else |
|
5222 | - return false; |
|
5527 | + else { |
|
5528 | + return false; |
|
5529 | + } |
|
5223 | 5530 | |
5224 | 5531 | switch($state) |
5225 | 5532 | { |
@@ -5247,8 +5554,9 @@ discard block |
||
5247 | 5554 | if($type == '}') |
5248 | 5555 | { |
5249 | 5556 | // Array size is less than expected. |
5250 | - if(count($list) < end($expected)) |
|
5251 | - return false; |
|
5557 | + if(count($list) < end($expected)) { |
|
5558 | + return false; |
|
5559 | + } |
|
5252 | 5560 | |
5253 | 5561 | unset($list); |
5254 | 5562 | $list = &$stack[count($stack)-1]; |
@@ -5257,8 +5565,9 @@ discard block |
||
5257 | 5565 | // Go to terminal state if we're at the end of the root array. |
5258 | 5566 | array_pop($expected); |
5259 | 5567 | |
5260 | - if(count($expected) == 0) |
|
5261 | - $state = 1; |
|
5568 | + if(count($expected) == 0) { |
|
5569 | + $state = 1; |
|
5570 | + } |
|
5262 | 5571 | |
5263 | 5572 | break; |
5264 | 5573 | } |
@@ -5266,8 +5575,9 @@ discard block |
||
5266 | 5575 | if($type == 'i' || $type == 's') |
5267 | 5576 | { |
5268 | 5577 | // Array size exceeds expected length. |
5269 | - if(count($list) >= end($expected)) |
|
5270 | - return false; |
|
5578 | + if(count($list) >= end($expected)) { |
|
5579 | + return false; |
|
5580 | + } |
|
5271 | 5581 | |
5272 | 5582 | $key = $value; |
5273 | 5583 | $state = 3; |
@@ -5301,8 +5611,9 @@ discard block |
||
5301 | 5611 | } |
5302 | 5612 | |
5303 | 5613 | // Trailing data in input. |
5304 | - if(!empty($str)) |
|
5305 | - return false; |
|
5614 | + if(!empty($str)) { |
|
5615 | + return false; |
|
5616 | + } |
|
5306 | 5617 | |
5307 | 5618 | return $data; |
5308 | 5619 | } |
@@ -5325,8 +5636,9 @@ discard block |
||
5325 | 5636 | |
5326 | 5637 | $out = _safe_unserialize($str); |
5327 | 5638 | |
5328 | - if (isset($mbIntEnc)) |
|
5329 | - mb_internal_encoding($mbIntEnc); |
|
5639 | + if (isset($mbIntEnc)) { |
|
5640 | + mb_internal_encoding($mbIntEnc); |
|
5641 | + } |
|
5330 | 5642 | |
5331 | 5643 | return $out; |
5332 | 5644 | } |
@@ -5341,12 +5653,14 @@ discard block |
||
5341 | 5653 | function smf_chmod($file, $value = 0) |
5342 | 5654 | { |
5343 | 5655 | // No file? no checks! |
5344 | - if (empty($file)) |
|
5345 | - return false; |
|
5656 | + if (empty($file)) { |
|
5657 | + return false; |
|
5658 | + } |
|
5346 | 5659 | |
5347 | 5660 | // Already writable? |
5348 | - if (is_writable($file)) |
|
5349 | - return true; |
|
5661 | + if (is_writable($file)) { |
|
5662 | + return true; |
|
5663 | + } |
|
5350 | 5664 | |
5351 | 5665 | // Do we have a file or a dir? |
5352 | 5666 | $isDir = is_dir($file); |
@@ -5362,10 +5676,9 @@ discard block |
||
5362 | 5676 | { |
5363 | 5677 | $isWritable = true; |
5364 | 5678 | break; |
5679 | + } else { |
|
5680 | + @chmod($file, $val); |
|
5365 | 5681 | } |
5366 | - |
|
5367 | - else |
|
5368 | - @chmod($file, $val); |
|
5369 | 5682 | } |
5370 | 5683 | |
5371 | 5684 | return $isWritable; |
@@ -5384,8 +5697,9 @@ discard block |
||
5384 | 5697 | global $txt; |
5385 | 5698 | |
5386 | 5699 | // Come on... |
5387 | - if (empty($json) || !is_string($json)) |
|
5388 | - return array(); |
|
5700 | + if (empty($json) || !is_string($json)) { |
|
5701 | + return array(); |
|
5702 | + } |
|
5389 | 5703 | |
5390 | 5704 | $returnArray = @json_decode($json, $returnAsArray); |
5391 | 5705 | |
@@ -5423,11 +5737,11 @@ discard block |
||
5423 | 5737 | $jsonDebug = $jsonDebug[0]; |
5424 | 5738 | loadLanguage('Errors'); |
5425 | 5739 | |
5426 | - if (!empty($jsonDebug)) |
|
5427 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5428 | - |
|
5429 | - else |
|
5430 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
5740 | + if (!empty($jsonDebug)) { |
|
5741 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
5742 | + } else { |
|
5743 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
5744 | + } |
|
5431 | 5745 | |
5432 | 5746 | // Everyone expects an array. |
5433 | 5747 | return array(); |
@@ -5457,8 +5771,9 @@ discard block |
||
5457 | 5771 | global $db_show_debug, $modSettings; |
5458 | 5772 | |
5459 | 5773 | // Defensive programming anyone? |
5460 | - if (empty($data)) |
|
5461 | - return false; |
|
5774 | + if (empty($data)) { |
|
5775 | + return false; |
|
5776 | + } |
|
5462 | 5777 | |
5463 | 5778 | // Don't need extra stuff... |
5464 | 5779 | $db_show_debug = false; |
@@ -5466,11 +5781,11 @@ discard block |
||
5466 | 5781 | // Kill anything else. |
5467 | 5782 | ob_end_clean(); |
5468 | 5783 | |
5469 | - if (!empty($modSettings['CompressedOutput'])) |
|
5470 | - @ob_start('ob_gzhandler'); |
|
5471 | - |
|
5472 | - else |
|
5473 | - ob_start(); |
|
5784 | + if (!empty($modSettings['CompressedOutput'])) { |
|
5785 | + @ob_start('ob_gzhandler'); |
|
5786 | + } else { |
|
5787 | + ob_start(); |
|
5788 | + } |
|
5474 | 5789 | |
5475 | 5790 | // Set the header. |
5476 | 5791 | header($type); |
@@ -5502,8 +5817,9 @@ discard block |
||
5502 | 5817 | static $done = false; |
5503 | 5818 | |
5504 | 5819 | // If we don't need to do anything, don't |
5505 | - if (!$update && $done) |
|
5506 | - return; |
|
5820 | + if (!$update && $done) { |
|
5821 | + return; |
|
5822 | + } |
|
5507 | 5823 | |
5508 | 5824 | // Should we get a new copy of the official list of TLDs? |
5509 | 5825 | if ($update) |
@@ -5524,10 +5840,11 @@ discard block |
||
5524 | 5840 | // Clean $tlds and convert it to an array |
5525 | 5841 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
5526 | 5842 | $line = trim($line); |
5527 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
5528 | - return false; |
|
5529 | - else |
|
5530 | - return true; |
|
5843 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
5844 | + return false; |
|
5845 | + } else { |
|
5846 | + return true; |
|
5847 | + } |
|
5531 | 5848 | }); |
5532 | 5849 | |
5533 | 5850 | // Convert Punycode to Unicode |
@@ -5581,8 +5898,9 @@ discard block |
||
5581 | 5898 | $idx += $digit * $w; |
5582 | 5899 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
5583 | 5900 | |
5584 | - if ($digit < $t) |
|
5585 | - break; |
|
5901 | + if ($digit < $t) { |
|
5902 | + break; |
|
5903 | + } |
|
5586 | 5904 | |
5587 | 5905 | $w = (int) ($w * ($base - $t)); |
5588 | 5906 | } |
@@ -5591,8 +5909,9 @@ discard block |
||
5591 | 5909 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
5592 | 5910 | $delta += intval($delta / ($deco_len + 1)); |
5593 | 5911 | |
5594 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
5595 | - $delta = intval($delta / ($base - $tmin)); |
|
5912 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
5913 | + $delta = intval($delta / ($base - $tmin)); |
|
5914 | + } |
|
5596 | 5915 | |
5597 | 5916 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
5598 | 5917 | $is_first = false; |
@@ -5601,8 +5920,9 @@ discard block |
||
5601 | 5920 | |
5602 | 5921 | if ($deco_len > 0) |
5603 | 5922 | { |
5604 | - for ($i = $deco_len; $i > $idx; $i--) |
|
5605 | - $decoded[$i] = $decoded[($i - 1)]; |
|
5923 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
5924 | + $decoded[$i] = $decoded[($i - 1)]; |
|
5925 | + } |
|
5606 | 5926 | } |
5607 | 5927 | $decoded[$idx++] = $char; |
5608 | 5928 | } |
@@ -5610,24 +5930,29 @@ discard block |
||
5610 | 5930 | foreach ($decoded as $k => $v) |
5611 | 5931 | { |
5612 | 5932 | // 7bit are transferred literally |
5613 | - if ($v < 128) |
|
5614 | - $output .= chr($v); |
|
5933 | + if ($v < 128) { |
|
5934 | + $output .= chr($v); |
|
5935 | + } |
|
5615 | 5936 | |
5616 | 5937 | // 2 bytes |
5617 | - elseif ($v < (1 << 11)) |
|
5618 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5938 | + elseif ($v < (1 << 11)) { |
|
5939 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
5940 | + } |
|
5619 | 5941 | |
5620 | 5942 | // 3 bytes |
5621 | - elseif ($v < (1 << 16)) |
|
5622 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5943 | + elseif ($v < (1 << 16)) { |
|
5944 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5945 | + } |
|
5623 | 5946 | |
5624 | 5947 | // 4 bytes |
5625 | - elseif ($v < (1 << 21)) |
|
5626 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5948 | + elseif ($v < (1 << 21)) { |
|
5949 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
5950 | + } |
|
5627 | 5951 | |
5628 | 5952 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
5629 | - else |
|
5630 | - $output .= $safe_char; |
|
5953 | + else { |
|
5954 | + $output .= $safe_char; |
|
5955 | + } |
|
5631 | 5956 | } |
5632 | 5957 | |
5633 | 5958 | $output_parts[] = $output; |
@@ -5722,8 +6047,7 @@ discard block |
||
5722 | 6047 | |
5723 | 6048 | $strlen = 'mb_strlen'; |
5724 | 6049 | $substr = 'mb_substr'; |
5725 | - } |
|
5726 | - else |
|
6050 | + } else |
|
5727 | 6051 | { |
5728 | 6052 | $strlen = $smcFunc['strlen']; |
5729 | 6053 | $substr = $smcFunc['substr']; |
@@ -5737,20 +6061,21 @@ discard block |
||
5737 | 6061 | |
5738 | 6062 | $first = $substr($string, 0, 1); |
5739 | 6063 | |
5740 | - if (empty($index[$first])) |
|
5741 | - $index[$first] = array(); |
|
6064 | + if (empty($index[$first])) { |
|
6065 | + $index[$first] = array(); |
|
6066 | + } |
|
5742 | 6067 | |
5743 | 6068 | if ($strlen($string) > 1) |
5744 | 6069 | { |
5745 | 6070 | // Sanity check on recursion |
5746 | - if ($depth > 99) |
|
5747 | - $index[$first][$substr($string, 1)] = ''; |
|
5748 | - |
|
5749 | - else |
|
5750 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6071 | + if ($depth > 99) { |
|
6072 | + $index[$first][$substr($string, 1)] = ''; |
|
6073 | + } else { |
|
6074 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
6075 | + } |
|
6076 | + } else { |
|
6077 | + $index[$first][''] = ''; |
|
5751 | 6078 | } |
5752 | - else |
|
5753 | - $index[$first][''] = ''; |
|
5754 | 6079 | |
5755 | 6080 | $depth--; |
5756 | 6081 | return $index; |
@@ -5773,9 +6098,9 @@ discard block |
||
5773 | 6098 | $key_regex = preg_quote($key, $delim); |
5774 | 6099 | $new_key = $key; |
5775 | 6100 | |
5776 | - if (empty($value)) |
|
5777 | - $sub_regex = ''; |
|
5778 | - else |
|
6101 | + if (empty($value)) { |
|
6102 | + $sub_regex = ''; |
|
6103 | + } else |
|
5779 | 6104 | { |
5780 | 6105 | $sub_regex = $index_to_regex($value, $delim); |
5781 | 6106 | |
@@ -5783,22 +6108,22 @@ discard block |
||
5783 | 6108 | { |
5784 | 6109 | $new_key_array = explode('(?'.'>', $sub_regex); |
5785 | 6110 | $new_key .= $new_key_array[0]; |
6111 | + } else { |
|
6112 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5786 | 6113 | } |
5787 | - else |
|
5788 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
5789 | 6114 | } |
5790 | 6115 | |
5791 | - if ($depth > 1) |
|
5792 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
5793 | - else |
|
6116 | + if ($depth > 1) { |
|
6117 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
6118 | + } else |
|
5794 | 6119 | { |
5795 | 6120 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
5796 | 6121 | { |
5797 | 6122 | $regex[$new_key] = $key_regex . $sub_regex; |
5798 | 6123 | unset($index[$key]); |
6124 | + } else { |
|
6125 | + break; |
|
5799 | 6126 | } |
5800 | - else |
|
5801 | - break; |
|
5802 | 6127 | } |
5803 | 6128 | } |
5804 | 6129 | |
@@ -5807,10 +6132,11 @@ discard block |
||
5807 | 6132 | $l1 = $strlen($k1); |
5808 | 6133 | $l2 = $strlen($k2); |
5809 | 6134 | |
5810 | - if ($l1 == $l2) |
|
5811 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
5812 | - else |
|
5813 | - return $l1 > $l2 ? -1 : 1; |
|
6135 | + if ($l1 == $l2) { |
|
6136 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
6137 | + } else { |
|
6138 | + return $l1 > $l2 ? -1 : 1; |
|
6139 | + } |
|
5814 | 6140 | }); |
5815 | 6141 | |
5816 | 6142 | $depth--; |
@@ -5821,15 +6147,18 @@ discard block |
||
5821 | 6147 | $index = array(); |
5822 | 6148 | $regexes = array(); |
5823 | 6149 | |
5824 | - foreach ($strings as $string) |
|
5825 | - $index = $add_string_to_index($string, $index); |
|
6150 | + foreach ($strings as $string) { |
|
6151 | + $index = $add_string_to_index($string, $index); |
|
6152 | + } |
|
5826 | 6153 | |
5827 | - while (!empty($index)) |
|
5828 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6154 | + while (!empty($index)) { |
|
6155 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
6156 | + } |
|
5829 | 6157 | |
5830 | 6158 | // Restore PHP's internal character encoding to whatever it was originally |
5831 | - if (!empty($current_encoding)) |
|
5832 | - mb_internal_encoding($current_encoding); |
|
6159 | + if (!empty($current_encoding)) { |
|
6160 | + mb_internal_encoding($current_encoding); |
|
6161 | + } |
|
5833 | 6162 | |
5834 | 6163 | return $regexes; |
5835 | 6164 | } |