@@ -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 | { |
@@ -251,11 +257,13 @@ discard block |
||
251 | 257 | } |
252 | 258 | |
253 | 259 | // Open up the old china. |
254 | - if (!isset($archive_content)) |
|
255 | - $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
260 | + if (!isset($archive_content)) { |
|
261 | + $archive_content = read_tgz_file('https://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null); |
|
262 | + } |
|
256 | 263 | |
257 | - if (empty($archive_content)) |
|
258 | - fatal_error($txt['add_language_error_no_response']); |
|
264 | + if (empty($archive_content)) { |
|
265 | + fatal_error($txt['add_language_error_no_response']); |
|
266 | + } |
|
259 | 267 | |
260 | 268 | // Now for each of the files, let's do some *stuff* |
261 | 269 | $context['files'] = array( |
@@ -270,8 +278,9 @@ discard block |
||
270 | 278 | $extension = substr($filename, strrpos($filename, '.') + 1); |
271 | 279 | |
272 | 280 | // Don't do anything with files we don't understand. |
273 | - if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) |
|
274 | - continue; |
|
281 | + if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) { |
|
282 | + continue; |
|
283 | + } |
|
275 | 284 | |
276 | 285 | // Basic data. |
277 | 286 | $context_data = array( |
@@ -290,8 +299,9 @@ discard block |
||
290 | 299 | // Does the file exist, is it different and can we overwrite? |
291 | 300 | if (file_exists($boarddir . '/' . $file['filename'])) |
292 | 301 | { |
293 | - if (is_writable($boarddir . '/' . $file['filename'])) |
|
294 | - $context_data['writable'] = true; |
|
302 | + if (is_writable($boarddir . '/' . $file['filename'])) { |
|
303 | + $context_data['writable'] = true; |
|
304 | + } |
|
295 | 305 | |
296 | 306 | // Finally, do we actually think the content has changed? |
297 | 307 | if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) |
@@ -304,16 +314,17 @@ discard block |
||
304 | 314 | { |
305 | 315 | $context_data['exists'] = 'same'; |
306 | 316 | $context_data['default_copy'] = false; |
317 | + } else { |
|
318 | + $context_data['exists'] = 'different'; |
|
307 | 319 | } |
308 | - else |
|
309 | - $context_data['exists'] = 'different'; |
|
310 | 320 | } |
311 | 321 | // No overwrite? |
312 | 322 | else |
313 | 323 | { |
314 | 324 | // Can we at least stick it in the directory... |
315 | - if (is_writable($boarddir . '/' . $dirname)) |
|
316 | - $context_data['writable'] = true; |
|
325 | + if (is_writable($boarddir . '/' . $dirname)) { |
|
326 | + $context_data['writable'] = true; |
|
327 | + } |
|
317 | 328 | } |
318 | 329 | |
319 | 330 | // 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... |
@@ -328,8 +339,9 @@ discard block |
||
328 | 339 | list ($name, $language) = explode('.', $filename); |
329 | 340 | |
330 | 341 | // Let's get the new version, I like versions, they tell me that I'm up to date. |
331 | - if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) |
|
332 | - $context_data['version'] = $match[1]; |
|
342 | + if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) { |
|
343 | + $context_data['version'] = $match[1]; |
|
344 | + } |
|
333 | 345 | |
334 | 346 | // Now does the old file exist - if so what is it's version? |
335 | 347 | if (file_exists($boarddir . '/' . $file['filename'])) |
@@ -345,34 +357,35 @@ discard block |
||
345 | 357 | $context_data['cur_version'] = $match[1]; |
346 | 358 | |
347 | 359 | // How does this compare? |
348 | - if ($context_data['cur_version'] == $context_data['version']) |
|
349 | - $context_data['version_compare'] = 'same'; |
|
350 | - elseif ($context_data['cur_version'] > $context_data['version']) |
|
351 | - $context_data['version_compare'] = 'older'; |
|
360 | + if ($context_data['cur_version'] == $context_data['version']) { |
|
361 | + $context_data['version_compare'] = 'same'; |
|
362 | + } elseif ($context_data['cur_version'] > $context_data['version']) { |
|
363 | + $context_data['version_compare'] = 'older'; |
|
364 | + } |
|
352 | 365 | |
353 | 366 | // Don't recommend copying if the version is the same. |
354 | - if ($context_data['version_compare'] != 'newer') |
|
355 | - $context_data['default_copy'] = false; |
|
367 | + if ($context_data['version_compare'] != 'newer') { |
|
368 | + $context_data['default_copy'] = false; |
|
369 | + } |
|
356 | 370 | } |
357 | 371 | } |
358 | 372 | |
359 | 373 | // Add the context data to the main set. |
360 | 374 | $context['files']['lang'][] = $context_data; |
361 | - } |
|
362 | - elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
375 | + } elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false) |
|
363 | 376 | { |
364 | 377 | // Registration agreement is a primary file |
365 | 378 | $context['files']['lang'][] = $context_data; |
366 | - } |
|
367 | - else |
|
379 | + } else |
|
368 | 380 | { |
369 | 381 | // There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future |
370 | 382 | $context['files']['other'][] = $context_data; |
371 | 383 | } |
372 | 384 | |
373 | 385 | // Collect together all non-writable areas. |
374 | - if (!$context_data['writable']) |
|
375 | - $context['make_writable'][] = $context_data['destination']; |
|
386 | + if (!$context_data['writable']) { |
|
387 | + $context['make_writable'][] = $context_data['destination']; |
|
388 | + } |
|
376 | 389 | } |
377 | 390 | |
378 | 391 | // Before we go to far can we make anything writable, eh, eh? |
@@ -387,22 +400,24 @@ discard block |
||
387 | 400 | { |
388 | 401 | if ($type == 'lang') |
389 | 402 | { |
390 | - foreach ($data as $k => $file) |
|
391 | - if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
403 | + foreach ($data as $k => $file) { |
|
404 | + if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
|
392 | 405 | $context['files'][$type][$k]['writable'] = true; |
393 | - } |
|
394 | - else |
|
406 | + } |
|
407 | + } else |
|
395 | 408 | { |
396 | - foreach ($data as $theme => $files) |
|
397 | - foreach ($files as $k => $file) |
|
409 | + foreach ($data as $theme => $files) { |
|
410 | + foreach ($files as $k => $file) |
|
398 | 411 | if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable'])) |
399 | 412 | $context['files'][$type][$theme][$k]['writable'] = true; |
413 | + } |
|
400 | 414 | } |
401 | 415 | } |
402 | 416 | |
403 | 417 | // Are we going to need more language stuff? |
404 | - if (!empty($context['still_not_writable'])) |
|
405 | - loadLanguage('Packages'); |
|
418 | + if (!empty($context['still_not_writable'])) { |
|
419 | + loadLanguage('Packages'); |
|
420 | + } |
|
406 | 421 | } |
407 | 422 | |
408 | 423 | // This is the list for the main files. |
@@ -615,12 +630,13 @@ discard block |
||
615 | 630 | highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true); |
616 | 631 | |
617 | 632 | // Display a warning if we cannot edit the default setting. |
618 | - if (!is_writable($boarddir . '/Settings.php')) |
|
619 | - $listOptions['additional_rows'][] = array( |
|
633 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
634 | + $listOptions['additional_rows'][] = array( |
|
620 | 635 | 'position' => 'after_title', |
621 | 636 | 'value' => $txt['language_settings_writable'], |
622 | 637 | 'class' => 'smalltext alert', |
623 | 638 | ); |
639 | + } |
|
624 | 640 | |
625 | 641 | require_once($sourcedir . '/Subs-List.php'); |
626 | 642 | createList($listOptions); |
@@ -662,10 +678,11 @@ discard block |
||
662 | 678 | |
663 | 679 | // Put them back. |
664 | 680 | $settings['actual_theme_dir'] = $backup_actual_theme_dir; |
665 | - if (!empty($backup_base_theme_dir)) |
|
666 | - $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
667 | - else |
|
668 | - unset($settings['base_theme_dir']); |
|
681 | + if (!empty($backup_base_theme_dir)) { |
|
682 | + $settings['base_theme_dir'] = $backup_base_theme_dir; |
|
683 | + } else { |
|
684 | + unset($settings['base_theme_dir']); |
|
685 | + } |
|
669 | 686 | |
670 | 687 | // Get the language files and data... |
671 | 688 | foreach ($context['languages'] as $lang) |
@@ -694,13 +711,15 @@ discard block |
||
694 | 711 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
695 | 712 | { |
696 | 713 | // Default? |
697 | - if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) |
|
698 | - $row['lngfile'] = $language; |
|
714 | + if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) { |
|
715 | + $row['lngfile'] = $language; |
|
716 | + } |
|
699 | 717 | |
700 | - if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) |
|
701 | - $languages['english']['count'] += $row['num_users']; |
|
702 | - elseif (isset($languages[$row['lngfile']])) |
|
703 | - $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
718 | + if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) { |
|
719 | + $languages['english']['count'] += $row['num_users']; |
|
720 | + } elseif (isset($languages[$row['lngfile']])) { |
|
721 | + $languages[$row['lngfile']]['count'] += $row['num_users']; |
|
722 | + } |
|
704 | 723 | } |
705 | 724 | $smcFunc['db_free_result']($request); |
706 | 725 | |
@@ -740,13 +759,15 @@ discard block |
||
740 | 759 | |
741 | 760 | call_integration_hook('integrate_language_settings', array(&$config_vars)); |
742 | 761 | |
743 | - if ($return_config) |
|
744 | - return $config_vars; |
|
762 | + if ($return_config) { |
|
763 | + return $config_vars; |
|
764 | + } |
|
745 | 765 | |
746 | 766 | // Get our languages. No cache |
747 | 767 | getLanguages(false); |
748 | - foreach ($context['languages'] as $lang) |
|
749 | - $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
768 | + foreach ($context['languages'] as $lang) { |
|
769 | + $config_vars['language'][4][$lang['filename']] = array($lang['filename'], $lang['name']); |
|
770 | + } |
|
750 | 771 | |
751 | 772 | // Saving settings? |
752 | 773 | if (isset($_REQUEST['save'])) |
@@ -756,8 +777,9 @@ discard block |
||
756 | 777 | call_integration_hook('integrate_save_language_settings', array(&$config_vars)); |
757 | 778 | |
758 | 779 | saveSettings($config_vars); |
759 | - if (!$settings_not_writable && !$settings_backup_fail) |
|
760 | - $_SESSION['adm-save'] = true; |
|
780 | + if (!$settings_not_writable && !$settings_backup_fail) { |
|
781 | + $_SESSION['adm-save'] = true; |
|
782 | + } |
|
761 | 783 | redirectexit('action=admin;area=languages;sa=settings'); |
762 | 784 | } |
763 | 785 | |
@@ -766,10 +788,11 @@ discard block |
||
766 | 788 | $context['settings_title'] = $txt['language_settings']; |
767 | 789 | $context['save_disabled'] = $settings_not_writable; |
768 | 790 | |
769 | - if ($settings_not_writable) |
|
770 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
771 | - elseif ($settings_backup_fail) |
|
772 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
791 | + if ($settings_not_writable) { |
|
792 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
793 | + } elseif ($settings_backup_fail) { |
|
794 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
795 | + } |
|
773 | 796 | |
774 | 797 | // Fill the config array. |
775 | 798 | prepareServerSettingsContext($config_vars); |
@@ -816,8 +839,9 @@ discard block |
||
816 | 839 | 'theme_dir' => $settings['default_theme_dir'], |
817 | 840 | ), |
818 | 841 | ); |
819 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
820 | - $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
842 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
843 | + $themes[$row['id_theme']][$row['variable']] = $row['value']; |
|
844 | + } |
|
821 | 845 | $smcFunc['db_free_result']($request); |
822 | 846 | |
823 | 847 | // This will be where we look |
@@ -829,14 +853,16 @@ discard block |
||
829 | 853 | // Check we have themes with a path and a name - just in case - and add the path. |
830 | 854 | foreach ($themes as $id => $data) |
831 | 855 | { |
832 | - if (count($data) != 2) |
|
833 | - unset($themes[$id]); |
|
834 | - elseif (is_dir($data['theme_dir'] . '/languages')) |
|
835 | - $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
856 | + if (count($data) != 2) { |
|
857 | + unset($themes[$id]); |
|
858 | + } elseif (is_dir($data['theme_dir'] . '/languages')) { |
|
859 | + $lang_dirs[$id] = $data['theme_dir'] . '/languages'; |
|
860 | + } |
|
836 | 861 | |
837 | 862 | // How about image directories? |
838 | - if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) |
|
839 | - $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
863 | + if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) { |
|
864 | + $images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id']; |
|
865 | + } |
|
840 | 866 | } |
841 | 867 | |
842 | 868 | $current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : ''; |
@@ -850,15 +876,17 @@ discard block |
||
850 | 876 | while ($entry = $dir->read()) |
851 | 877 | { |
852 | 878 | // We're only after the files for this language. |
853 | - if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) |
|
854 | - continue; |
|
879 | + if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) { |
|
880 | + continue; |
|
881 | + } |
|
855 | 882 | |
856 | - if (!isset($context['possible_files'][$theme])) |
|
857 | - $context['possible_files'][$theme] = array( |
|
883 | + if (!isset($context['possible_files'][$theme])) { |
|
884 | + $context['possible_files'][$theme] = array( |
|
858 | 885 | 'id' => $theme, |
859 | 886 | 'name' => $themes[$theme]['name'], |
860 | 887 | 'files' => array(), |
861 | 888 | ); |
889 | + } |
|
862 | 890 | |
863 | 891 | $context['possible_files'][$theme]['files'][] = array( |
864 | 892 | 'id' => $matches[1], |
@@ -887,31 +915,36 @@ discard block |
||
887 | 915 | { |
888 | 916 | $_SESSION['last_backup_for'] = $context['lang_id'] . '$$$'; |
889 | 917 | $result = package_create_backup('backup_lang_' . $context['lang_id']); |
890 | - if (!$result) |
|
891 | - fatal_lang_error('could_not_language_backup', false); |
|
918 | + if (!$result) { |
|
919 | + fatal_lang_error('could_not_language_backup', false); |
|
920 | + } |
|
892 | 921 | } |
893 | 922 | |
894 | 923 | // Second, loop through the array to remove the files. |
895 | 924 | foreach ($lang_dirs as $curPath) |
896 | 925 | { |
897 | - foreach ($context['possible_files'][1]['files'] as $lang) |
|
898 | - if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
926 | + foreach ($context['possible_files'][1]['files'] as $lang) { |
|
927 | + if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php')) |
|
899 | 928 | unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'); |
929 | + } |
|
900 | 930 | |
901 | 931 | // Check for the email template. |
902 | - if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) |
|
903 | - unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
932 | + if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) { |
|
933 | + unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'); |
|
934 | + } |
|
904 | 935 | } |
905 | 936 | |
906 | 937 | // Third, the agreement file. |
907 | - if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) |
|
908 | - unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
938 | + if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) { |
|
939 | + unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt'); |
|
940 | + } |
|
909 | 941 | |
910 | 942 | // Fourth, a related images folder, if it exists... |
911 | - if (!empty($images_dirs)) |
|
912 | - foreach ($images_dirs as $curPath) |
|
943 | + if (!empty($images_dirs)) { |
|
944 | + foreach ($images_dirs as $curPath) |
|
913 | 945 | if (is_dir($curPath)) |
914 | 946 | deltree($curPath); |
947 | + } |
|
915 | 948 | |
916 | 949 | // Members can no longer use this language. |
917 | 950 | $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; |
@@ -32,43 +32,43 @@ |
||
32 | 32 | class Curl |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @see https://php.net/curl_init |
|
37 | - * @param string $url |
|
38 | - * @return resource cURL handle |
|
39 | - */ |
|
40 | - public function init($url = null) |
|
41 | - { |
|
42 | - return curl_init($url); |
|
43 | - } |
|
35 | + /** |
|
36 | + * @see https://php.net/curl_init |
|
37 | + * @param string $url |
|
38 | + * @return resource cURL handle |
|
39 | + */ |
|
40 | + public function init($url = null) |
|
41 | + { |
|
42 | + return curl_init($url); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @see https://php.net/curl_setopt_array |
|
47 | - * @param resource $ch |
|
48 | - * @param array $options |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function setoptArray($ch, array $options) |
|
52 | - { |
|
53 | - return curl_setopt_array($ch, $options); |
|
54 | - } |
|
45 | + /** |
|
46 | + * @see https://php.net/curl_setopt_array |
|
47 | + * @param resource $ch |
|
48 | + * @param array $options |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function setoptArray($ch, array $options) |
|
52 | + { |
|
53 | + return curl_setopt_array($ch, $options); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @see https://php.net/curl_exec |
|
58 | - * @param resource $ch |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - public function exec($ch) |
|
62 | - { |
|
63 | - return curl_exec($ch); |
|
64 | - } |
|
56 | + /** |
|
57 | + * @see https://php.net/curl_exec |
|
58 | + * @param resource $ch |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + public function exec($ch) |
|
62 | + { |
|
63 | + return curl_exec($ch); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @see https://php.net/curl_close |
|
68 | - * @param resource $ch |
|
69 | - */ |
|
70 | - public function close($ch) |
|
71 | - { |
|
72 | - curl_close($ch); |
|
73 | - } |
|
66 | + /** |
|
67 | + * @see https://php.net/curl_close |
|
68 | + * @param resource $ch |
|
69 | + */ |
|
70 | + public function close($ch) |
|
71 | + { |
|
72 | + curl_close($ch); |
|
73 | + } |
|
74 | 74 | } |
@@ -32,74 +32,74 @@ |
||
32 | 32 | */ |
33 | 33 | class Socket |
34 | 34 | { |
35 | - private $handle = null; |
|
35 | + private $handle = null; |
|
36 | 36 | |
37 | - /** |
|
38 | - * fsockopen |
|
39 | - * |
|
40 | - * @see https://php.net/fsockopen |
|
41 | - * @param string $hostname |
|
42 | - * @param int $port |
|
43 | - * @param int $errno |
|
44 | - * @param string $errstr |
|
45 | - * @param float $timeout |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | - { |
|
50 | - $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
37 | + /** |
|
38 | + * fsockopen |
|
39 | + * |
|
40 | + * @see https://php.net/fsockopen |
|
41 | + * @param string $hostname |
|
42 | + * @param int $port |
|
43 | + * @param int $errno |
|
44 | + * @param string $errstr |
|
45 | + * @param float $timeout |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
49 | + { |
|
50 | + $this->handle = fsockopen($hostname, $port, $errno, $errstr, (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout)); |
|
51 | 51 | |
52 | - if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | - return $this->handle; |
|
54 | - } else { |
|
55 | - return false; |
|
56 | - } |
|
57 | - } |
|
52 | + if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
53 | + return $this->handle; |
|
54 | + } else { |
|
55 | + return false; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * fwrite |
|
61 | - * |
|
62 | - * @see https://php.net/fwrite |
|
63 | - * @param string $string |
|
64 | - * @param int $length |
|
65 | - * @return int | bool |
|
66 | - */ |
|
67 | - public function fwrite($string, $length = null) |
|
68 | - { |
|
69 | - return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | - } |
|
59 | + /** |
|
60 | + * fwrite |
|
61 | + * |
|
62 | + * @see https://php.net/fwrite |
|
63 | + * @param string $string |
|
64 | + * @param int $length |
|
65 | + * @return int | bool |
|
66 | + */ |
|
67 | + public function fwrite($string, $length = null) |
|
68 | + { |
|
69 | + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * fgets |
|
74 | - * |
|
75 | - * @see https://php.net/fgets |
|
76 | - * @param int $length |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function fgets($length = null) |
|
80 | - { |
|
81 | - return fgets($this->handle, $length); |
|
82 | - } |
|
72 | + /** |
|
73 | + * fgets |
|
74 | + * |
|
75 | + * @see https://php.net/fgets |
|
76 | + * @param int $length |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function fgets($length = null) |
|
80 | + { |
|
81 | + return fgets($this->handle, $length); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * feof |
|
86 | - * |
|
87 | - * @see https://php.net/feof |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function feof() |
|
91 | - { |
|
92 | - return feof($this->handle); |
|
93 | - } |
|
84 | + /** |
|
85 | + * feof |
|
86 | + * |
|
87 | + * @see https://php.net/feof |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function feof() |
|
91 | + { |
|
92 | + return feof($this->handle); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * fclose |
|
97 | - * |
|
98 | - * @see https://php.net/fclose |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function fclose() |
|
102 | - { |
|
103 | - return fclose($this->handle); |
|
104 | - } |
|
95 | + /** |
|
96 | + * fclose |
|
97 | + * |
|
98 | + * @see https://php.net/fclose |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function fclose() |
|
102 | + { |
|
103 | + return fclose($this->handle); |
|
104 | + } |
|
105 | 105 | } |
@@ -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 | * The main admin handling function.<br> |
@@ -444,8 +445,9 @@ discard block |
||
444 | 445 | foreach ($admin_includes as $include) |
445 | 446 | { |
446 | 447 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
447 | - if (file_exists($include)) |
|
448 | - require_once($include); |
|
448 | + if (file_exists($include)) { |
|
449 | + require_once($include); |
|
450 | + } |
|
449 | 451 | } |
450 | 452 | } |
451 | 453 | |
@@ -457,24 +459,27 @@ discard block |
||
457 | 459 | unset($admin_areas); |
458 | 460 | |
459 | 461 | // Nothing valid? |
460 | - if ($admin_include_data == false) |
|
461 | - fatal_lang_error('no_access', false); |
|
462 | + if ($admin_include_data == false) { |
|
463 | + fatal_lang_error('no_access', false); |
|
464 | + } |
|
462 | 465 | |
463 | 466 | // Build the link tree. |
464 | 467 | $context['linktree'][] = array( |
465 | 468 | 'url' => $scripturl . '?action=admin', |
466 | 469 | 'name' => $txt['admin_center'], |
467 | 470 | ); |
468 | - if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') |
|
469 | - $context['linktree'][] = array( |
|
471 | + if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index') { |
|
472 | + $context['linktree'][] = array( |
|
470 | 473 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
471 | 474 | 'name' => $admin_include_data['label'], |
472 | 475 | ); |
473 | - if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) |
|
474 | - $context['linktree'][] = array( |
|
476 | + } |
|
477 | + if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label']) { |
|
478 | + $context['linktree'][] = array( |
|
475 | 479 | 'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
476 | 480 | 'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0], |
477 | 481 | ); |
482 | + } |
|
478 | 483 | |
479 | 484 | // Make a note of the Unique ID for this menu. |
480 | 485 | $context['admin_menu_id'] = $context['max_menu_id']; |
@@ -484,16 +489,18 @@ discard block |
||
484 | 489 | $context['admin_area'] = $admin_include_data['current_area']; |
485 | 490 | |
486 | 491 | // Now - finally - call the right place! |
487 | - if (isset($admin_include_data['file'])) |
|
488 | - require_once($sourcedir . '/' . $admin_include_data['file']); |
|
492 | + if (isset($admin_include_data['file'])) { |
|
493 | + require_once($sourcedir . '/' . $admin_include_data['file']); |
|
494 | + } |
|
489 | 495 | |
490 | 496 | // Get the right callable. |
491 | 497 | $call = call_helper($admin_include_data['function'], true); |
492 | 498 | |
493 | 499 | // Is it valid? |
494 | - if (!empty($call)) |
|
495 | - call_user_func($call); |
|
496 | -} |
|
500 | + if (!empty($call)) { |
|
501 | + call_user_func($call); |
|
502 | + } |
|
503 | + } |
|
497 | 504 | |
498 | 505 | /** |
499 | 506 | * The main administration section. |
@@ -547,13 +554,14 @@ discard block |
||
547 | 554 | |
548 | 555 | $context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin'; |
549 | 556 | $context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center']; |
550 | - if ($context['admin_area'] != 'credits') |
|
551 | - $context[$context['admin_menu_name']]['tab_data'] = array( |
|
557 | + if ($context['admin_area'] != 'credits') { |
|
558 | + $context[$context['admin_menu_name']]['tab_data'] = array( |
|
552 | 559 | 'title' => $txt['admin_center'], |
553 | 560 | 'help' => '', |
554 | 561 | 'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong> |
555 | 562 | ' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']), |
556 | 563 | ); |
564 | + } |
|
557 | 565 | |
558 | 566 | // Lastly, fill in the blanks in the support resources paragraphs. |
559 | 567 | $txt['support_resources_p1'] = sprintf($txt['support_resources_p1'], |
@@ -571,9 +579,10 @@ discard block |
||
571 | 579 | 'https://www.simplemachines.org/redirect/customize_support' |
572 | 580 | ); |
573 | 581 | |
574 | - if ($context['admin_area'] == 'admin') |
|
575 | - loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
576 | -} |
|
582 | + if ($context['admin_area'] == 'admin') { |
|
583 | + loadJavaScriptFile('admin.js', array('defer' => false), 'smf_admin'); |
|
584 | + } |
|
585 | + } |
|
577 | 586 | |
578 | 587 | /** |
579 | 588 | * Get one of the admin information files from Simple Machines. |
@@ -584,8 +593,9 @@ discard block |
||
584 | 593 | |
585 | 594 | setMemoryLimit('32M'); |
586 | 595 | |
587 | - if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) |
|
588 | - fatal_lang_error('no_access', false); |
|
596 | + if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename'])) { |
|
597 | + fatal_lang_error('no_access', false); |
|
598 | + } |
|
589 | 599 | |
590 | 600 | // Strip off the forum cache part or we won't find it... |
591 | 601 | $_REQUEST['filename'] = str_replace($modSettings['browser_cache'], '', $_REQUEST['filename']); |
@@ -600,27 +610,30 @@ discard block |
||
600 | 610 | ) |
601 | 611 | ); |
602 | 612 | |
603 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
604 | - fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
613 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
614 | + fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404); |
|
615 | + } |
|
605 | 616 | |
606 | 617 | list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request); |
607 | 618 | $smcFunc['db_free_result']($request); |
608 | 619 | |
609 | 620 | // @todo Temp |
610 | 621 | // Figure out if sesc is still being used. |
611 | - if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') |
|
612 | - $file_data = ' |
|
622 | + if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript') { |
|
623 | + $file_data = ' |
|
613 | 624 | if (!(\'smfForum_sessionvar\' in window)) |
614 | 625 | window.smfForum_sessionvar = \'sesc\'; |
615 | 626 | ' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'=')); |
627 | + } |
|
616 | 628 | |
617 | 629 | $context['template_layers'] = array(); |
618 | 630 | // Lets make sure we aren't going to output anything nasty. |
619 | 631 | @ob_end_clean(); |
620 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
621 | - @ob_start('ob_gzhandler'); |
|
622 | - else |
|
623 | - @ob_start(); |
|
632 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
633 | + @ob_start('ob_gzhandler'); |
|
634 | + } else { |
|
635 | + @ob_start(); |
|
636 | + } |
|
624 | 637 | |
625 | 638 | // Make sure they know what type of file we are. |
626 | 639 | header('Content-Type: ' . $filetype); |
@@ -660,11 +673,12 @@ discard block |
||
660 | 673 | updateAdminPreferences(); |
661 | 674 | } |
662 | 675 | |
663 | - if (trim($context['search_term']) == '') |
|
664 | - $context['search_results'] = array(); |
|
665 | - else |
|
666 | - call_helper($subActions[$context['search_type']]); |
|
667 | -} |
|
676 | + if (trim($context['search_term']) == '') { |
|
677 | + $context['search_results'] = array(); |
|
678 | + } else { |
|
679 | + call_helper($subActions[$context['search_type']]); |
|
680 | + } |
|
681 | + } |
|
668 | 682 | |
669 | 683 | /** |
670 | 684 | * A complicated but relatively quick internal search. |
@@ -728,8 +742,9 @@ discard block |
||
728 | 742 | |
729 | 743 | loadLanguage(implode('+', $language_files)); |
730 | 744 | |
731 | - foreach ($include_files as $file) |
|
732 | - require_once($sourcedir . '/' . $file . '.php'); |
|
745 | + foreach ($include_files as $file) { |
|
746 | + require_once($sourcedir . '/' . $file . '.php'); |
|
747 | + } |
|
733 | 748 | |
734 | 749 | /* This is the huge array that defines everything... it's a huge array of items formatted as follows: |
735 | 750 | 0 = Language index (Can be array of indexes) to search through for this setting. |
@@ -753,11 +768,12 @@ discard block |
||
753 | 768 | foreach ($section['areas'] as $menu_key => $menu_item) |
754 | 769 | { |
755 | 770 | $search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key); |
756 | - if (!empty($menu_item['subsections'])) |
|
757 | - foreach ($menu_item['subsections'] as $key => $sublabel) |
|
771 | + if (!empty($menu_item['subsections'])) { |
|
772 | + foreach ($menu_item['subsections'] as $key => $sublabel) |
|
758 | 773 | { |
759 | 774 | if (isset($sublabel['label'])) |
760 | 775 | $search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key); |
776 | + } |
|
761 | 777 | } |
762 | 778 | } |
763 | 779 | } |
@@ -767,9 +783,10 @@ discard block |
||
767 | 783 | // Get a list of their variables. |
768 | 784 | $config_vars = $setting_area[0](true); |
769 | 785 | |
770 | - foreach ($config_vars as $var) |
|
771 | - if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
786 | + foreach ($config_vars as $var) { |
|
787 | + if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc'))) |
|
772 | 788 | $search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1]); |
789 | + } |
|
773 | 790 | } |
774 | 791 | |
775 | 792 | $context['page_title'] = $txt['admin_search_results']; |
@@ -782,8 +799,9 @@ discard block |
||
782 | 799 | foreach ($data as $item) |
783 | 800 | { |
784 | 801 | $found = false; |
785 | - if (!is_array($item[0])) |
|
786 | - $item[0] = array($item[0]); |
|
802 | + if (!is_array($item[0])) { |
|
803 | + $item[0] = array($item[0]); |
|
804 | + } |
|
787 | 805 | foreach ($item[0] as $term) |
788 | 806 | { |
789 | 807 | if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false)) |
@@ -841,8 +859,9 @@ discard block |
||
841 | 859 | $postVars = explode(' ', $context['search_term']); |
842 | 860 | |
843 | 861 | // Encode the search data. |
844 | - foreach ($postVars as $k => $v) |
|
845 | - $postVars[$k] = urlencode($v); |
|
862 | + foreach ($postVars as $k => $v) { |
|
863 | + $postVars[$k] = urlencode($v); |
|
864 | + } |
|
846 | 865 | |
847 | 866 | // This is what we will send. |
848 | 867 | $postVars = implode('+', $postVars); |
@@ -854,8 +873,9 @@ discard block |
||
854 | 873 | $search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars); |
855 | 874 | |
856 | 875 | // If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded? |
857 | - if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) |
|
858 | - fatal_lang_error('cannot_connect_doc_site'); |
|
876 | + if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api>.+?</api>)~is', $search_results, $matches) != true) { |
|
877 | + fatal_lang_error('cannot_connect_doc_site'); |
|
878 | + } |
|
859 | 879 | |
860 | 880 | $search_results = $matches[1]; |
861 | 881 | |
@@ -867,8 +887,9 @@ discard block |
||
867 | 887 | $results = new xmlArray($search_results, false); |
868 | 888 | |
869 | 889 | // Move through the api layer. |
870 | - if (!$results->exists('api')) |
|
871 | - fatal_lang_error('cannot_connect_doc_site'); |
|
890 | + if (!$results->exists('api')) { |
|
891 | + fatal_lang_error('cannot_connect_doc_site'); |
|
892 | + } |
|
872 | 893 | |
873 | 894 | // Are there actually some results? |
874 | 895 | if ($results->exists('api/query/search/p')) |
@@ -904,8 +925,9 @@ discard block |
||
904 | 925 | ); |
905 | 926 | |
906 | 927 | // If it's not got a sa set it must have come here for first time, pretend error log should be reversed. |
907 | - if (!isset($_REQUEST['sa'])) |
|
908 | - $_REQUEST['desc'] = true; |
|
928 | + if (!isset($_REQUEST['sa'])) { |
|
929 | + $_REQUEST['desc'] = true; |
|
930 | + } |
|
909 | 931 | |
910 | 932 | // Setup some tab stuff. |
911 | 933 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -955,9 +977,10 @@ discard block |
||
955 | 977 | unset($_SESSION['admin_time']); |
956 | 978 | |
957 | 979 | // Clean any admin tokens as well. |
958 | - foreach ($_SESSION['token'] as $key => $token) |
|
959 | - if (strpos($key, '-admin') !== false) |
|
980 | + foreach ($_SESSION['token'] as $key => $token) { |
|
981 | + if (strpos($key, '-admin') !== false) |
|
960 | 982 | unset($_SESSION['token'][$key]); |
983 | + } |
|
961 | 984 | |
962 | 985 | redirectexit(); |
963 | 986 | } |
@@ -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,15 @@ 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 | // Replace the normal file with its thumbnail if it has one! |
184 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
185 | - $file = $thumbFile; |
|
186 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
187 | + $file = $thumbFile; |
|
188 | + } |
|
186 | 189 | |
187 | 190 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
188 | 191 | if (!file_exists($file['filePath'])) |
@@ -232,8 +235,8 @@ discard block |
||
232 | 235 | } |
233 | 236 | |
234 | 237 | // Update the download counter (unless it's a thumbnail or resuming an incomplete download). |
235 | - if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) |
|
236 | - $smcFunc['db_query']('attach_download_increase', ' |
|
238 | + if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) { |
|
239 | + $smcFunc['db_query']('attach_download_increase', ' |
|
237 | 240 | UPDATE LOW_PRIORITY {db_prefix}attachments |
238 | 241 | SET downloads = downloads + 1 |
239 | 242 | WHERE id_attach = {int:id_attach}', |
@@ -241,12 +244,14 @@ discard block |
||
241 | 244 | 'id_attach' => $attachId, |
242 | 245 | ) |
243 | 246 | ); |
247 | + } |
|
244 | 248 | |
245 | 249 | // Send the attachment headers. |
246 | 250 | header('Pragma: '); |
247 | 251 | |
248 | - if (!isBrowser('gecko')) |
|
249 | - header('Content-Transfer-Encoding: binary'); |
|
252 | + if (!isBrowser('gecko')) { |
|
253 | + header('Content-Transfer-Encoding: binary'); |
|
254 | + } |
|
250 | 255 | |
251 | 256 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
252 | 257 | header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -255,18 +260,19 @@ discard block |
||
255 | 260 | header('ETag: ' . $eTag); |
256 | 261 | |
257 | 262 | // Make sure the mime type warrants an inline display. |
258 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
259 | - unset($_REQUEST['image']); |
|
263 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
264 | + unset($_REQUEST['image']); |
|
265 | + } |
|
260 | 266 | |
261 | 267 | // Does this have a mime type? |
262 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
263 | - header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
264 | - |
|
265 | - else |
|
268 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
269 | + header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
270 | + } else |
|
266 | 271 | { |
267 | 272 | header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
268 | - if (isset($_REQUEST['image'])) |
|
269 | - unset($_REQUEST['image']); |
|
273 | + if (isset($_REQUEST['image'])) { |
|
274 | + unset($_REQUEST['image']); |
|
275 | + } |
|
270 | 276 | } |
271 | 277 | |
272 | 278 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -274,24 +280,22 @@ discard block |
||
274 | 280 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
275 | 281 | |
276 | 282 | // Different browsers like different standards... |
277 | - if (isBrowser('firefox')) |
|
278 | - header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
279 | - |
|
280 | - elseif (isBrowser('opera')) |
|
281 | - header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
282 | - |
|
283 | - elseif (isBrowser('ie')) |
|
284 | - header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
285 | - |
|
286 | - else |
|
287 | - header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
283 | + if (isBrowser('firefox')) { |
|
284 | + header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
285 | + } elseif (isBrowser('opera')) { |
|
286 | + header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
287 | + } elseif (isBrowser('ie')) { |
|
288 | + header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
289 | + } else { |
|
290 | + header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
291 | + } |
|
288 | 292 | |
289 | 293 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
290 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
291 | - header('Cache-Control: no-cache'); |
|
292 | - |
|
293 | - else |
|
294 | - header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
294 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
295 | + header('Cache-Control: no-cache'); |
|
296 | + } else { |
|
297 | + header('Cache-Control: max-age=' . (525600 * 60) . ', private'); |
|
298 | + } |
|
295 | 299 | |
296 | 300 | // Multipart and resuming support |
297 | 301 | if (isset($_SERVER['HTTP_RANGE'])) |
@@ -299,9 +303,9 @@ discard block |
||
299 | 303 | header("HTTP/1.1 206 Partial Content"); |
300 | 304 | header("Content-Length: $new_length"); |
301 | 305 | header("Content-Range: bytes $range-$range_end/$size"); |
306 | + } else { |
|
307 | + header("Content-Length: " . $size); |
|
302 | 308 | } |
303 | - else |
|
304 | - header("Content-Length: " . $size); |
|
305 | 309 | |
306 | 310 | |
307 | 311 | // Try to buy some time... |
@@ -310,8 +314,9 @@ discard block |
||
310 | 314 | // For multipart/resumable downloads, send the requested chunk(s) of the file |
311 | 315 | if (isset($_SERVER['HTTP_RANGE'])) |
312 | 316 | { |
313 | - while (@ob_get_level() > 0) |
|
314 | - @ob_end_clean(); |
|
317 | + while (@ob_get_level() > 0) { |
|
318 | + @ob_end_clean(); |
|
319 | + } |
|
315 | 320 | |
316 | 321 | // 40 kilobytes is a good-ish amount |
317 | 322 | $chunksize = 40 * 1024; |
@@ -335,8 +340,9 @@ discard block |
||
335 | 340 | elseif ($size > 4194304) |
336 | 341 | { |
337 | 342 | // Forcibly end any output buffering going on. |
338 | - while (@ob_get_level() > 0) |
|
339 | - @ob_end_clean(); |
|
343 | + while (@ob_get_level() > 0) { |
|
344 | + @ob_end_clean(); |
|
345 | + } |
|
340 | 346 | |
341 | 347 | $fp = fopen($file['filePath'], 'rb'); |
342 | 348 | while (!feof($fp)) |
@@ -348,8 +354,9 @@ discard block |
||
348 | 354 | } |
349 | 355 | |
350 | 356 | // 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. |
351 | - elseif (@readfile($file['filePath']) === null) |
|
352 | - echo file_get_contents($file['filePath']); |
|
357 | + elseif (@readfile($file['filePath']) === null) { |
|
358 | + echo file_get_contents($file['filePath']); |
|
359 | + } |
|
353 | 360 | |
354 | 361 | die(); |
355 | 362 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | |
207 | 207 | if (!empty($modSettings['search_simple_fulltext'])) |
208 | 208 | { |
209 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
209 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
210 | 210 | { |
211 | 211 | $language_ftx = $smcFunc['db_search_language'](); |
212 | 212 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // remove any indexed words that are used in the complex body search terms |
225 | 225 | $words['indexed_words'] = array_diff($words['indexed_words'], $words['complex_words']); |
226 | 226 | |
227 | - if($smcFunc['db_title'] == "PostgreSQL"){ |
|
227 | + if ($smcFunc['db_title'] == "PostgreSQL") { |
|
228 | 228 | $row = 0; |
229 | 229 | foreach ($words['indexed_words'] as $fulltextWord) { |
230 | 230 | $query_params['boolean_match'] .= ($row <> 0 ? '&' : ''); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | |
241 | 241 | // if we have bool terms to search, add them in |
242 | 242 | if ($query_params['boolean_match']) { |
243 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
243 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
244 | 244 | { |
245 | 245 | $language_ftx = $smcFunc['db_search_language'](); |
246 | 246 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | |
254 | 254 | } |
255 | 255 | |
256 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
256 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
257 | 257 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
258 | 258 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
259 | 259 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Class fulltext_search |
@@ -98,8 +99,9 @@ discard block |
||
98 | 99 | $smcFunc['db_free_result']($request); |
99 | 100 | } |
100 | 101 | // 4 is the MySQL default... |
101 | - else |
|
102 | - $min_word_length = 4; |
|
102 | + else { |
|
103 | + $min_word_length = 4; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | return $min_word_length; |
105 | 107 | } |
@@ -138,8 +140,7 @@ discard block |
||
138 | 140 | $wordsSearch['words'][] = trim($word, "/*- "); |
139 | 141 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
140 | 142 | } |
141 | - } |
|
142 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
143 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
143 | 144 | { |
144 | 145 | // short words have feelings too |
145 | 146 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -149,8 +150,9 @@ discard block |
||
149 | 150 | |
150 | 151 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
151 | 152 | $wordsSearch['indexed_words'][] = $fulltextWord; |
152 | - if ($isExcluded) |
|
153 | - $wordsExclude[] = $fulltextWord; |
|
153 | + if ($isExcluded) { |
|
154 | + $wordsExclude[] = $fulltextWord; |
|
155 | + } |
|
154 | 156 | } |
155 | 157 | |
156 | 158 | /** |
@@ -166,41 +168,50 @@ discard block |
||
166 | 168 | $query_where = array(); |
167 | 169 | $query_params = $search_data['params']; |
168 | 170 | |
169 | - if ($query_params['id_search']) |
|
170 | - $query_select['id_search'] = '{int:id_search}'; |
|
171 | + if ($query_params['id_search']) { |
|
172 | + $query_select['id_search'] = '{int:id_search}'; |
|
173 | + } |
|
171 | 174 | |
172 | 175 | $count = 0; |
173 | - if (empty($modSettings['search_simple_fulltext'])) |
|
174 | - foreach ($words['words'] as $regularWord) |
|
176 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
177 | + foreach ($words['words'] as $regularWord) |
|
175 | 178 | { |
176 | 179 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
180 | + } |
|
177 | 181 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
178 | 182 | } |
179 | 183 | |
180 | - if ($query_params['user_query']) |
|
181 | - $query_where[] = '{raw:user_query}'; |
|
182 | - if ($query_params['board_query']) |
|
183 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
184 | + if ($query_params['user_query']) { |
|
185 | + $query_where[] = '{raw:user_query}'; |
|
186 | + } |
|
187 | + if ($query_params['board_query']) { |
|
188 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
189 | + } |
|
184 | 190 | |
185 | - if ($query_params['topic']) |
|
186 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
187 | - if ($query_params['min_msg_id']) |
|
188 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
189 | - if ($query_params['max_msg_id']) |
|
190 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
191 | + if ($query_params['topic']) { |
|
192 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
193 | + } |
|
194 | + if ($query_params['min_msg_id']) { |
|
195 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
196 | + } |
|
197 | + if ($query_params['max_msg_id']) { |
|
198 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
199 | + } |
|
191 | 200 | |
192 | 201 | $count = 0; |
193 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
194 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
202 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
203 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
195 | 204 | { |
196 | 205 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
206 | + } |
|
197 | 207 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
198 | 208 | } |
199 | 209 | $count = 0; |
200 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
201 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
210 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
211 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
202 | 212 | { |
203 | 213 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
214 | + } |
|
204 | 215 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
205 | 216 | } |
206 | 217 | |
@@ -212,12 +223,11 @@ discard block |
||
212 | 223 | |
213 | 224 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:body_match})'; |
214 | 225 | $query_params['language_ftx'] = $language_ftx; |
226 | + } else { |
|
227 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
215 | 228 | } |
216 | - else |
|
217 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
218 | 229 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
219 | - } |
|
220 | - else |
|
230 | + } else |
|
221 | 231 | { |
222 | 232 | $query_params['boolean_match'] = ''; |
223 | 233 | |
@@ -231,10 +241,10 @@ discard block |
||
231 | 241 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
232 | 242 | $row++; |
233 | 243 | } |
234 | - } |
|
235 | - else |
|
236 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
244 | + } else { |
|
245 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
237 | 246 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
247 | + } |
|
238 | 248 | |
239 | 249 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
240 | 250 | |
@@ -246,9 +256,9 @@ discard block |
||
246 | 256 | |
247 | 257 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ to_tsquery({string:language_ftx},{string:boolean_match})'; |
248 | 258 | $query_params['language_ftx'] = $language_ftx; |
259 | + } else { |
|
260 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
249 | 261 | } |
250 | - else |
|
251 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
252 | 262 | } |
253 | 263 | |
254 | 264 | } |
@@ -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 | * !!!Compatibility!!! |
@@ -30,8 +31,9 @@ discard block |
||
30 | 31 | { |
31 | 32 | global $modSettings; |
32 | 33 | |
33 | - if (!$compat_mode) |
|
34 | - return $text; |
|
34 | + if (!$compat_mode) { |
|
35 | + return $text; |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // Turn line breaks back into br's. |
37 | 39 | $text = strtr($text, array("\r" => '', "\n" => '<br>')); |
@@ -48,8 +50,9 @@ discard block |
||
48 | 50 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
49 | 51 | { |
50 | 52 | // Value of 2 means we're inside the tag. |
51 | - if ($i % 4 == 2) |
|
52 | - $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
53 | + if ($i % 4 == 2) { |
|
54 | + $parts[$i] = strtr($parts[$i], array('[' => '[', ']' => ']', "'" => "'")); |
|
55 | + } |
|
53 | 56 | } |
54 | 57 | // Put our humpty dumpty message back together again. |
55 | 58 | $text = implode('', $parts); |
@@ -107,8 +110,9 @@ discard block |
||
107 | 110 | $text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text); |
108 | 111 | |
109 | 112 | // Safari/webkit wraps lines in Wysiwyg in <div>'s. |
110 | - if (isBrowser('webkit')) |
|
111 | - $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
113 | + if (isBrowser('webkit')) { |
|
114 | + $text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text); |
|
115 | + } |
|
112 | 116 | |
113 | 117 | // If there's a trailing break get rid of it - Firefox tends to add one. |
114 | 118 | $text = preg_replace('~<br\s?/?' . '>$~i', '', $text); |
@@ -123,8 +127,9 @@ discard block |
||
123 | 127 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
124 | 128 | { |
125 | 129 | // Value of 2 means we're inside the tag. |
126 | - if ($i % 4 == 2) |
|
127 | - $parts[$i] = strip_tags($parts[$i]); |
|
130 | + if ($i % 4 == 2) { |
|
131 | + $parts[$i] = strip_tags($parts[$i]); |
|
132 | + } |
|
128 | 133 | } |
129 | 134 | |
130 | 135 | $text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>')); |
@@ -150,18 +155,19 @@ discard block |
||
150 | 155 | { |
151 | 156 | $found = array_search($file, $smileysto); |
152 | 157 | // Note the weirdness here is to stop double spaces between smileys. |
153 | - if ($found) |
|
154 | - $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
155 | - else |
|
156 | - $matches[1][$k] = ''; |
|
158 | + if ($found) { |
|
159 | + $matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#'; |
|
160 | + } else { |
|
161 | + $matches[1][$k] = ''; |
|
162 | + } |
|
157 | 163 | } |
158 | - } |
|
159 | - else |
|
164 | + } else |
|
160 | 165 | { |
161 | 166 | // Load all the smileys. |
162 | 167 | $names = array(); |
163 | - foreach ($matches[1] as $file) |
|
164 | - $names[] = $file; |
|
168 | + foreach ($matches[1] as $file) { |
|
169 | + $names[] = $file; |
|
170 | + } |
|
165 | 171 | $names = array_unique($names); |
166 | 172 | |
167 | 173 | if (!empty($names)) |
@@ -175,13 +181,15 @@ discard block |
||
175 | 181 | ) |
176 | 182 | ); |
177 | 183 | $mappings = array(); |
178 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
179 | - $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
184 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
185 | + $mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']); |
|
186 | + } |
|
180 | 187 | $smcFunc['db_free_result']($request); |
181 | 188 | |
182 | - foreach ($matches[1] as $k => $file) |
|
183 | - if (isset($mappings[$file])) |
|
189 | + foreach ($matches[1] as $k => $file) { |
|
190 | + if (isset($mappings[$file])) |
|
184 | 191 | $matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#'; |
192 | + } |
|
185 | 193 | } |
186 | 194 | } |
187 | 195 | |
@@ -193,8 +201,9 @@ discard block |
||
193 | 201 | } |
194 | 202 | |
195 | 203 | // Only try to buy more time if the client didn't quit. |
196 | - if (connection_aborted() && $context['server']['is_apache']) |
|
197 | - @apache_reset_timeout(); |
|
204 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
205 | + @apache_reset_timeout(); |
|
206 | + } |
|
198 | 207 | |
199 | 208 | $parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
200 | 209 | $replacement = ''; |
@@ -205,9 +214,9 @@ discard block |
||
205 | 214 | if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) |
206 | 215 | { |
207 | 216 | // If it's being closed instantly, we can't deal with it...yet. |
208 | - if ($matches[5] === '/') |
|
209 | - continue; |
|
210 | - else |
|
217 | + if ($matches[5] === '/') { |
|
218 | + continue; |
|
219 | + } else |
|
211 | 220 | { |
212 | 221 | // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) |
213 | 222 | $styles = explode(';', strtr($matches[3], array('"' => ''))); |
@@ -223,8 +232,9 @@ discard block |
||
223 | 232 | $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); |
224 | 233 | |
225 | 234 | // Something like 'font-weight: bold' is expected here. |
226 | - if (strpos($clean_type_value_pair, ':') === false) |
|
227 | - continue; |
|
235 | + if (strpos($clean_type_value_pair, ':') === false) { |
|
236 | + continue; |
|
237 | + } |
|
228 | 238 | |
229 | 239 | // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). |
230 | 240 | list ($style_type, $style_value) = explode(':', $type_value_pair); |
@@ -246,8 +256,7 @@ discard block |
||
246 | 256 | { |
247 | 257 | $curCloseTags .= '[/u]'; |
248 | 258 | $replacement .= '[u]'; |
249 | - } |
|
250 | - elseif ($style_value == 'line-through') |
|
259 | + } elseif ($style_value == 'line-through') |
|
251 | 260 | { |
252 | 261 | $curCloseTags .= '[/s]'; |
253 | 262 | $replacement .= '[s]'; |
@@ -259,13 +268,11 @@ discard block |
||
259 | 268 | { |
260 | 269 | $curCloseTags .= '[/left]'; |
261 | 270 | $replacement .= '[left]'; |
262 | - } |
|
263 | - elseif ($style_value == 'center') |
|
271 | + } elseif ($style_value == 'center') |
|
264 | 272 | { |
265 | 273 | $curCloseTags .= '[/center]'; |
266 | 274 | $replacement .= '[center]'; |
267 | - } |
|
268 | - elseif ($style_value == 'right') |
|
275 | + } elseif ($style_value == 'right') |
|
269 | 276 | { |
270 | 277 | $curCloseTags .= '[/right]'; |
271 | 278 | $replacement .= '[right]'; |
@@ -287,8 +294,9 @@ discard block |
||
287 | 294 | |
288 | 295 | case 'font-size': |
289 | 296 | // Sometimes people put decimals where decimals should not be. |
290 | - if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) |
|
291 | - $style_value = $dec_matches[1] . $dec_matches[2]; |
|
297 | + if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) { |
|
298 | + $style_value = $dec_matches[1] . $dec_matches[2]; |
|
299 | + } |
|
292 | 300 | |
293 | 301 | $curCloseTags .= '[/size]'; |
294 | 302 | $replacement .= '[size=' . $style_value . ']'; |
@@ -296,8 +304,9 @@ discard block |
||
296 | 304 | |
297 | 305 | case 'font-family': |
298 | 306 | // Only get the first freaking font if there's a list! |
299 | - if (strpos($style_value, ',') !== false) |
|
300 | - $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
307 | + if (strpos($style_value, ',') !== false) { |
|
308 | + $style_value = substr($style_value, 0, strpos($style_value, ',')); |
|
309 | + } |
|
301 | 310 | |
302 | 311 | $curCloseTags .= '[/font]'; |
303 | 312 | $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; |
@@ -306,13 +315,15 @@ discard block |
||
306 | 315 | // This is a hack for images with dimensions embedded. |
307 | 316 | case 'width': |
308 | 317 | case 'height': |
309 | - if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) |
|
310 | - $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
318 | + if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) { |
|
319 | + $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; |
|
320 | + } |
|
311 | 321 | break; |
312 | 322 | |
313 | 323 | case 'list-style-type': |
314 | - if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) |
|
315 | - $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
324 | + if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { |
|
325 | + $extra_attr .= ' listtype="' . $listType[0] . '"'; |
|
326 | + } |
|
316 | 327 | break; |
317 | 328 | } |
318 | 329 | } |
@@ -325,18 +336,17 @@ discard block |
||
325 | 336 | } |
326 | 337 | |
327 | 338 | // If there's something that still needs closing, push it to the stack. |
328 | - if (!empty($curCloseTags)) |
|
329 | - array_push($stack, array( |
|
339 | + if (!empty($curCloseTags)) { |
|
340 | + array_push($stack, array( |
|
330 | 341 | 'element' => strtolower($curElement), |
331 | 342 | 'closeTags' => $curCloseTags |
332 | 343 | ) |
333 | 344 | ); |
334 | - elseif (!empty($extra_attr)) |
|
335 | - $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
345 | + } elseif (!empty($extra_attr)) { |
|
346 | + $replacement .= $precedingStyle . $extra_attr . $afterStyle; |
|
347 | + } |
|
336 | 348 | } |
337 | - } |
|
338 | - |
|
339 | - elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
349 | + } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) |
|
340 | 350 | { |
341 | 351 | // Is this the element that we've been waiting for to be closed? |
342 | 352 | if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) |
@@ -346,28 +356,32 @@ discard block |
||
346 | 356 | } |
347 | 357 | |
348 | 358 | // Must've been something else. |
349 | - else |
|
350 | - $replacement .= $part; |
|
359 | + else { |
|
360 | + $replacement .= $part; |
|
361 | + } |
|
351 | 362 | } |
352 | 363 | // In all other cases, just add the part to the replacement. |
353 | - else |
|
354 | - $replacement .= $part; |
|
364 | + else { |
|
365 | + $replacement .= $part; |
|
366 | + } |
|
355 | 367 | } |
356 | 368 | |
357 | 369 | // Now put back the replacement in the text. |
358 | 370 | $text = $replacement; |
359 | 371 | |
360 | 372 | // We are not finished yet, request more time. |
361 | - if (connection_aborted() && $context['server']['is_apache']) |
|
362 | - @apache_reset_timeout(); |
|
373 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
374 | + @apache_reset_timeout(); |
|
375 | + } |
|
363 | 376 | |
364 | 377 | // Let's pull out any legacy alignments. |
365 | 378 | while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) |
366 | 379 | { |
367 | 380 | // Find the position in the text of this tag over again. |
368 | 381 | $start_pos = strpos($text, $matches[0]); |
369 | - if ($start_pos === false) |
|
370 | - break; |
|
382 | + if ($start_pos === false) { |
|
383 | + break; |
|
384 | + } |
|
371 | 385 | |
372 | 386 | // End tag? |
373 | 387 | if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) |
@@ -382,8 +396,7 @@ discard block |
||
382 | 396 | |
383 | 397 | // Put the tags back into the body. |
384 | 398 | $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); |
385 | - } |
|
386 | - else |
|
399 | + } else |
|
387 | 400 | { |
388 | 401 | // Just get rid of this evil tag. |
389 | 402 | $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); |
@@ -396,8 +409,9 @@ discard block |
||
396 | 409 | // Find the position of this again. |
397 | 410 | $start_pos = strpos($text, $matches[0]); |
398 | 411 | $end_pos = false; |
399 | - if ($start_pos === false) |
|
400 | - break; |
|
412 | + if ($start_pos === false) { |
|
413 | + break; |
|
414 | + } |
|
401 | 415 | |
402 | 416 | // This must have an end tag - and we must find the right one. |
403 | 417 | $lower_text = strtolower($text); |
@@ -430,8 +444,9 @@ discard block |
||
430 | 444 | break; |
431 | 445 | } |
432 | 446 | } |
433 | - if ($end_pos === false) |
|
434 | - break; |
|
447 | + if ($end_pos === false) { |
|
448 | + break; |
|
449 | + } |
|
435 | 450 | |
436 | 451 | // Now work out what the attributes are. |
437 | 452 | $attribs = fetchTagAttributes($matches[1]); |
@@ -445,11 +460,11 @@ discard block |
||
445 | 460 | $v = (int) trim($v); |
446 | 461 | $v = empty($v) ? 1 : $v; |
447 | 462 | $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); |
463 | + } elseif ($s == 'face') { |
|
464 | + $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
465 | + } elseif ($s == 'color') { |
|
466 | + $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
448 | 467 | } |
449 | - elseif ($s == 'face') |
|
450 | - $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); |
|
451 | - elseif ($s == 'color') |
|
452 | - $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); |
|
453 | 468 | } |
454 | 469 | |
455 | 470 | // As before add in our tags. |
@@ -457,8 +472,9 @@ discard block |
||
457 | 472 | foreach ($tags as $tag) |
458 | 473 | { |
459 | 474 | $before .= $tag[0]; |
460 | - if (isset($tag[1])) |
|
461 | - $after = $tag[1] . $after; |
|
475 | + if (isset($tag[1])) { |
|
476 | + $after = $tag[1] . $after; |
|
477 | + } |
|
462 | 478 | } |
463 | 479 | |
464 | 480 | // Remove the tag so it's never checked again. |
@@ -469,8 +485,9 @@ discard block |
||
469 | 485 | } |
470 | 486 | |
471 | 487 | // Almost there, just a little more time. |
472 | - if (connection_aborted() && $context['server']['is_apache']) |
|
473 | - @apache_reset_timeout(); |
|
488 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
489 | + @apache_reset_timeout(); |
|
490 | + } |
|
474 | 491 | |
475 | 492 | if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) |
476 | 493 | { |
@@ -526,12 +543,13 @@ discard block |
||
526 | 543 | { |
527 | 544 | $inList = true; |
528 | 545 | |
529 | - if ($tag === 'ol') |
|
530 | - $listType = 'decimal'; |
|
531 | - elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) |
|
532 | - $listType = $listTypeMapping[$match[1]]; |
|
533 | - else |
|
534 | - $listType = null; |
|
546 | + if ($tag === 'ol') { |
|
547 | + $listType = 'decimal'; |
|
548 | + } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { |
|
549 | + $listType = $listTypeMapping[$match[1]]; |
|
550 | + } else { |
|
551 | + $listType = null; |
|
552 | + } |
|
535 | 553 | |
536 | 554 | $listDepth++; |
537 | 555 | |
@@ -595,9 +613,7 @@ discard block |
||
595 | 613 | $parts[$i + 1] = ''; |
596 | 614 | $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; |
597 | 615 | $parts[$i + 3] = ''; |
598 | - } |
|
599 | - |
|
600 | - else |
|
616 | + } else |
|
601 | 617 | { |
602 | 618 | // We're in a list item. |
603 | 619 | if ($listDepth > 0) |
@@ -634,9 +650,7 @@ discard block |
||
634 | 650 | $parts[$i + 1] = ''; |
635 | 651 | $parts[$i + 2] = ''; |
636 | 652 | $parts[$i + 3] = ''; |
637 | - } |
|
638 | - |
|
639 | - else |
|
653 | + } else |
|
640 | 654 | { |
641 | 655 | // Remove the trailing breaks from the list item. |
642 | 656 | $parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]); |
@@ -674,8 +688,9 @@ discard block |
||
674 | 688 | $text .= str_repeat("\t", $listDepth) . '[/list]'; |
675 | 689 | } |
676 | 690 | |
677 | - for ($i = $listDepth; $i > 0; $i--) |
|
678 | - $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
691 | + for ($i = $listDepth; $i > 0; $i--) { |
|
692 | + $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; |
|
693 | + } |
|
679 | 694 | |
680 | 695 | } |
681 | 696 | |
@@ -684,8 +699,9 @@ discard block |
||
684 | 699 | { |
685 | 700 | // Find the position of the image. |
686 | 701 | $start_pos = strpos($text, $matches[0]); |
687 | - if ($start_pos === false) |
|
688 | - break; |
|
702 | + if ($start_pos === false) { |
|
703 | + break; |
|
704 | + } |
|
689 | 705 | $end_pos = $start_pos + strlen($matches[0]); |
690 | 706 | |
691 | 707 | $params = ''; |
@@ -694,12 +710,13 @@ discard block |
||
694 | 710 | $attrs = fetchTagAttributes($matches[1]); |
695 | 711 | foreach ($attrs as $attrib => $value) |
696 | 712 | { |
697 | - if (in_array($attrib, array('width', 'height'))) |
|
698 | - $params .= ' ' . $attrib . '=' . (int) $value; |
|
699 | - elseif ($attrib == 'alt' && trim($value) != '') |
|
700 | - $params .= ' alt=' . trim($value); |
|
701 | - elseif ($attrib == 'src') |
|
702 | - $src = trim($value); |
|
713 | + if (in_array($attrib, array('width', 'height'))) { |
|
714 | + $params .= ' ' . $attrib . '=' . (int) $value; |
|
715 | + } elseif ($attrib == 'alt' && trim($value) != '') { |
|
716 | + $params .= ' alt=' . trim($value); |
|
717 | + } elseif ($attrib == 'src') { |
|
718 | + $src = trim($value); |
|
719 | + } |
|
703 | 720 | } |
704 | 721 | |
705 | 722 | $tag = ''; |
@@ -710,10 +727,11 @@ discard block |
||
710 | 727 | { |
711 | 728 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
712 | 729 | |
713 | - if (substr($src, 0, 1) === '/') |
|
714 | - $src = $baseURL . $src; |
|
715 | - else |
|
716 | - $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
730 | + if (substr($src, 0, 1) === '/') { |
|
731 | + $src = $baseURL . $src; |
|
732 | + } else { |
|
733 | + $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; |
|
734 | + } |
|
717 | 735 | } |
718 | 736 | |
719 | 737 | $tag = '[img' . $params . ']' . $src . '[/img]'; |
@@ -891,20 +909,23 @@ discard block |
||
891 | 909 | }, |
892 | 910 | ); |
893 | 911 | |
894 | - foreach ($tags as $tag => $replace) |
|
895 | - $text = preg_replace_callback($tag, $replace, $text); |
|
912 | + foreach ($tags as $tag => $replace) { |
|
913 | + $text = preg_replace_callback($tag, $replace, $text); |
|
914 | + } |
|
896 | 915 | |
897 | 916 | // Please give us just a little more time. |
898 | - if (connection_aborted() && $context['server']['is_apache']) |
|
899 | - @apache_reset_timeout(); |
|
917 | + if (connection_aborted() && $context['server']['is_apache']) { |
|
918 | + @apache_reset_timeout(); |
|
919 | + } |
|
900 | 920 | |
901 | 921 | // What about URL's - the pain in the ass of the tag world. |
902 | 922 | while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1) |
903 | 923 | { |
904 | 924 | // Find the position of the URL. |
905 | 925 | $start_pos = strpos($text, $matches[0]); |
906 | - if ($start_pos === false) |
|
907 | - break; |
|
926 | + if ($start_pos === false) { |
|
927 | + break; |
|
928 | + } |
|
908 | 929 | $end_pos = $start_pos + strlen($matches[0]); |
909 | 930 | |
910 | 931 | $tag_type = 'url'; |
@@ -918,8 +939,9 @@ discard block |
||
918 | 939 | $href = trim($value); |
919 | 940 | |
920 | 941 | // Are we dealing with an FTP link? |
921 | - if (preg_match('~^ftps?://~', $href) === 1) |
|
922 | - $tag_type = 'ftp'; |
|
942 | + if (preg_match('~^ftps?://~', $href) === 1) { |
|
943 | + $tag_type = 'ftp'; |
|
944 | + } |
|
923 | 945 | |
924 | 946 | // Or is this a link to an email address? |
925 | 947 | elseif (substr($href, 0, 7) == 'mailto:') |
@@ -933,28 +955,31 @@ discard block |
||
933 | 955 | { |
934 | 956 | $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); |
935 | 957 | |
936 | - if (substr($href, 0, 1) === '/') |
|
937 | - $href = $baseURL . $href; |
|
938 | - else |
|
939 | - $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
958 | + if (substr($href, 0, 1) === '/') { |
|
959 | + $href = $baseURL . $href; |
|
960 | + } else { |
|
961 | + $href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href; |
|
962 | + } |
|
940 | 963 | } |
941 | 964 | } |
942 | 965 | |
943 | 966 | // External URL? |
944 | 967 | if ($attrib == 'target' && $tag_type == 'url') |
945 | 968 | { |
946 | - if (trim($value) == '_blank') |
|
947 | - $tag_type == 'iurl'; |
|
969 | + if (trim($value) == '_blank') { |
|
970 | + $tag_type == 'iurl'; |
|
971 | + } |
|
948 | 972 | } |
949 | 973 | } |
950 | 974 | |
951 | 975 | $tag = ''; |
952 | 976 | if ($href != '') |
953 | 977 | { |
954 | - if ($matches[2] == $href) |
|
955 | - $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
956 | - else |
|
957 | - $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
978 | + if ($matches[2] == $href) { |
|
979 | + $tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']'; |
|
980 | + } else { |
|
981 | + $tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']'; |
|
982 | + } |
|
958 | 983 | } |
959 | 984 | |
960 | 985 | // Replace the tag |
@@ -993,17 +1018,18 @@ discard block |
||
993 | 1018 | // We're either moving from the key to the attribute or we're in a string and this is fine. |
994 | 1019 | if ($text[$i] == '=') |
995 | 1020 | { |
996 | - if ($tag_state == 0) |
|
997 | - $tag_state = 1; |
|
998 | - elseif ($tag_state == 2) |
|
999 | - $value .= '='; |
|
1021 | + if ($tag_state == 0) { |
|
1022 | + $tag_state = 1; |
|
1023 | + } elseif ($tag_state == 2) { |
|
1024 | + $value .= '='; |
|
1025 | + } |
|
1000 | 1026 | } |
1001 | 1027 | // A space is either moving from an attribute back to a potential key or in a string is fine. |
1002 | 1028 | elseif ($text[$i] == ' ') |
1003 | 1029 | { |
1004 | - if ($tag_state == 2) |
|
1005 | - $value .= ' '; |
|
1006 | - elseif ($tag_state == 1) |
|
1030 | + if ($tag_state == 2) { |
|
1031 | + $value .= ' '; |
|
1032 | + } elseif ($tag_state == 1) |
|
1007 | 1033 | { |
1008 | 1034 | $attribs[$key] = $value; |
1009 | 1035 | $key = $value = ''; |
@@ -1014,24 +1040,27 @@ discard block |
||
1014 | 1040 | elseif ($text[$i] == '"') |
1015 | 1041 | { |
1016 | 1042 | // Must be either going into or out of a string. |
1017 | - if ($tag_state == 1) |
|
1018 | - $tag_state = 2; |
|
1019 | - else |
|
1020 | - $tag_state = 1; |
|
1043 | + if ($tag_state == 1) { |
|
1044 | + $tag_state = 2; |
|
1045 | + } else { |
|
1046 | + $tag_state = 1; |
|
1047 | + } |
|
1021 | 1048 | } |
1022 | 1049 | // Otherwise it's fine. |
1023 | 1050 | else |
1024 | 1051 | { |
1025 | - if ($tag_state == 0) |
|
1026 | - $key .= $text[$i]; |
|
1027 | - else |
|
1028 | - $value .= $text[$i]; |
|
1052 | + if ($tag_state == 0) { |
|
1053 | + $key .= $text[$i]; |
|
1054 | + } else { |
|
1055 | + $value .= $text[$i]; |
|
1056 | + } |
|
1029 | 1057 | } |
1030 | 1058 | } |
1031 | 1059 | |
1032 | 1060 | // Anything left? |
1033 | - if ($key != '' && $value != '') |
|
1034 | - $attribs[$key] = $value; |
|
1061 | + if ($key != '' && $value != '') { |
|
1062 | + $attribs[$key] = $value; |
|
1063 | + } |
|
1035 | 1064 | |
1036 | 1065 | return $attribs; |
1037 | 1066 | } |
@@ -1047,15 +1076,17 @@ discard block |
||
1047 | 1076 | global $modSettings; |
1048 | 1077 | |
1049 | 1078 | // Don't care about the texts that are too short. |
1050 | - if (strlen($text) < 3) |
|
1051 | - return $text; |
|
1079 | + if (strlen($text) < 3) { |
|
1080 | + return $text; |
|
1081 | + } |
|
1052 | 1082 | |
1053 | 1083 | // A list of tags that's disabled by the admin. |
1054 | 1084 | $disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC']))); |
1055 | 1085 | |
1056 | 1086 | // Add flash if it's disabled as embedded tag. |
1057 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
1058 | - $disabled['flash'] = true; |
|
1087 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1088 | + $disabled['flash'] = true; |
|
1089 | + } |
|
1059 | 1090 | |
1060 | 1091 | // Get a list of all the tags that are not disabled. |
1061 | 1092 | $all_tags = parse_bbc(false); |
@@ -1063,10 +1094,12 @@ discard block |
||
1063 | 1094 | $self_closing_tags = array(); |
1064 | 1095 | foreach ($all_tags as $tag) |
1065 | 1096 | { |
1066 | - if (!isset($disabled[$tag['tag']])) |
|
1067 | - $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
1068 | - if (isset($tag['type']) && $tag['type'] == 'closed') |
|
1069 | - $self_closing_tags[] = $tag['tag']; |
|
1097 | + if (!isset($disabled[$tag['tag']])) { |
|
1098 | + $valid_tags[$tag['tag']] = !empty($tag['block_level']); |
|
1099 | + } |
|
1100 | + if (isset($tag['type']) && $tag['type'] == 'closed') { |
|
1101 | + $self_closing_tags[] = $tag['tag']; |
|
1102 | + } |
|
1070 | 1103 | } |
1071 | 1104 | |
1072 | 1105 | // Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid! |
@@ -1093,16 +1126,19 @@ discard block |
||
1093 | 1126 | $tagName = substr($match, $isClosingTag ? 2 : 1, -1); |
1094 | 1127 | |
1095 | 1128 | // We're closing the exact same tag that we opened. |
1096 | - if ($isClosingTag && $insideTag === $tagName) |
|
1097 | - $insideTag = null; |
|
1129 | + if ($isClosingTag && $insideTag === $tagName) { |
|
1130 | + $insideTag = null; |
|
1131 | + } |
|
1098 | 1132 | |
1099 | 1133 | // We're opening a tag and we're not yet inside one either |
1100 | - elseif (!$isClosingTag && $insideTag === null) |
|
1101 | - $insideTag = $tagName; |
|
1134 | + elseif (!$isClosingTag && $insideTag === null) { |
|
1135 | + $insideTag = $tagName; |
|
1136 | + } |
|
1102 | 1137 | |
1103 | 1138 | // In all other cases, this tag must be invalid |
1104 | - else |
|
1105 | - unset($matches[$i]); |
|
1139 | + else { |
|
1140 | + unset($matches[$i]); |
|
1141 | + } |
|
1106 | 1142 | } |
1107 | 1143 | |
1108 | 1144 | // The next one is gonna be the other one. |
@@ -1110,8 +1146,9 @@ discard block |
||
1110 | 1146 | } |
1111 | 1147 | |
1112 | 1148 | // We're still inside a tag and had no chance for closure? |
1113 | - if ($insideTag !== null) |
|
1114 | - $matches[] = '[/' . $insideTag . ']'; |
|
1149 | + if ($insideTag !== null) { |
|
1150 | + $matches[] = '[/' . $insideTag . ']'; |
|
1151 | + } |
|
1115 | 1152 | |
1116 | 1153 | // And a complete text string again. |
1117 | 1154 | $text = implode('', $matches); |
@@ -1120,8 +1157,9 @@ discard block |
||
1120 | 1157 | // Quickly remove any tags which are back to back. |
1121 | 1158 | $backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~'; |
1122 | 1159 | $lastlen = 0; |
1123 | - while (strlen($text) !== $lastlen) |
|
1124 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1160 | + while (strlen($text) !== $lastlen) { |
|
1161 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1162 | + } |
|
1125 | 1163 | |
1126 | 1164 | // Need to sort the tags my name length. |
1127 | 1165 | uksort($valid_tags, 'sort_array_length'); |
@@ -1158,8 +1196,9 @@ discard block |
||
1158 | 1196 | $isCompetingTag = in_array($tag, $competing_tags); |
1159 | 1197 | |
1160 | 1198 | // Check if this might be one of those cleaned out tags. |
1161 | - if ($tag === '') |
|
1162 | - continue; |
|
1199 | + if ($tag === '') { |
|
1200 | + continue; |
|
1201 | + } |
|
1163 | 1202 | |
1164 | 1203 | // Special case: inside [code] blocks any code is left untouched. |
1165 | 1204 | elseif ($tag === 'code') |
@@ -1170,8 +1209,9 @@ discard block |
||
1170 | 1209 | $inCode = false; |
1171 | 1210 | |
1172 | 1211 | // Reopen tags that were closed before the code block. |
1173 | - if (!empty($inlineElements)) |
|
1174 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1212 | + if (!empty($inlineElements)) { |
|
1213 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1214 | + } |
|
1175 | 1215 | } |
1176 | 1216 | |
1177 | 1217 | // We're outside a coding and nobbc block and opening it. |
@@ -1200,8 +1240,9 @@ discard block |
||
1200 | 1240 | $inNoBbc = false; |
1201 | 1241 | |
1202 | 1242 | // Some inline elements might've been closed that need reopening. |
1203 | - if (!empty($inlineElements)) |
|
1204 | - $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1243 | + if (!empty($inlineElements)) { |
|
1244 | + $parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']'; |
|
1245 | + } |
|
1205 | 1246 | } |
1206 | 1247 | |
1207 | 1248 | // We're outside a nobbc and coding block and opening it. |
@@ -1221,8 +1262,9 @@ discard block |
||
1221 | 1262 | } |
1222 | 1263 | |
1223 | 1264 | // So, we're inside one of the special blocks: ignore any tag. |
1224 | - elseif ($inCode || $inNoBbc) |
|
1225 | - continue; |
|
1265 | + elseif ($inCode || $inNoBbc) { |
|
1266 | + continue; |
|
1267 | + } |
|
1226 | 1268 | |
1227 | 1269 | // We're dealing with an opening tag. |
1228 | 1270 | if ($isOpeningTag) |
@@ -1263,8 +1305,9 @@ discard block |
||
1263 | 1305 | if ($parts[$j + 3] === $tag) |
1264 | 1306 | { |
1265 | 1307 | // If it's an opening tag, increase the level. |
1266 | - if ($parts[$j + 2] === '') |
|
1267 | - $curLevel++; |
|
1308 | + if ($parts[$j + 2] === '') { |
|
1309 | + $curLevel++; |
|
1310 | + } |
|
1268 | 1311 | |
1269 | 1312 | // A closing tag, decrease the level. |
1270 | 1313 | else |
@@ -1287,13 +1330,15 @@ discard block |
||
1287 | 1330 | { |
1288 | 1331 | if ($isCompetingTag) |
1289 | 1332 | { |
1290 | - if (!isset($competingElements[$tag])) |
|
1291 | - $competingElements[$tag] = array(); |
|
1333 | + if (!isset($competingElements[$tag])) { |
|
1334 | + $competingElements[$tag] = array(); |
|
1335 | + } |
|
1292 | 1336 | |
1293 | 1337 | $competingElements[$tag][] = $parts[$i + 4]; |
1294 | 1338 | |
1295 | - if (count($competingElements[$tag]) > 1) |
|
1296 | - $parts[$i] .= '[/' . $tag . ']'; |
|
1339 | + if (count($competingElements[$tag]) > 1) { |
|
1340 | + $parts[$i] .= '[/' . $tag . ']'; |
|
1341 | + } |
|
1297 | 1342 | } |
1298 | 1343 | |
1299 | 1344 | $inlineElements[$elementContent] = $tag; |
@@ -1314,15 +1359,17 @@ discard block |
||
1314 | 1359 | $addClosingTags = array(); |
1315 | 1360 | while ($element = array_pop($blockElements)) |
1316 | 1361 | { |
1317 | - if ($element === $tag) |
|
1318 | - break; |
|
1362 | + if ($element === $tag) { |
|
1363 | + break; |
|
1364 | + } |
|
1319 | 1365 | |
1320 | 1366 | // Still a block tag was open not equal to this tag. |
1321 | 1367 | $addClosingTags[] = $element['type']; |
1322 | 1368 | } |
1323 | 1369 | |
1324 | - if (!empty($addClosingTags)) |
|
1325 | - $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
1370 | + if (!empty($addClosingTags)) { |
|
1371 | + $parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1]; |
|
1372 | + } |
|
1326 | 1373 | |
1327 | 1374 | // Apparently the closing tag was not found on the stack. |
1328 | 1375 | if (!is_string($element) || $element !== $tag) |
@@ -1332,8 +1379,7 @@ discard block |
||
1332 | 1379 | $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
1333 | 1380 | continue; |
1334 | 1381 | } |
1335 | - } |
|
1336 | - else |
|
1382 | + } else |
|
1337 | 1383 | { |
1338 | 1384 | // Get rid of this closing tag! |
1339 | 1385 | $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
@@ -1362,53 +1408,62 @@ discard block |
||
1362 | 1408 | unset($inlineElements[$tagContentToBeClosed]); |
1363 | 1409 | |
1364 | 1410 | // Was this the tag we were looking for? |
1365 | - if ($tagToBeClosed === $tag) |
|
1366 | - break; |
|
1411 | + if ($tagToBeClosed === $tag) { |
|
1412 | + break; |
|
1413 | + } |
|
1367 | 1414 | |
1368 | 1415 | // Nope, close it and look further! |
1369 | - else |
|
1370 | - $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
1416 | + else { |
|
1417 | + $parts[$i] .= '[/' . $tagToBeClosed . ']'; |
|
1418 | + } |
|
1371 | 1419 | } |
1372 | 1420 | |
1373 | 1421 | if ($isCompetingTag && !empty($competingElements[$tag])) |
1374 | 1422 | { |
1375 | 1423 | array_pop($competingElements[$tag]); |
1376 | 1424 | |
1377 | - if (count($competingElements[$tag]) > 0) |
|
1378 | - $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
1425 | + if (count($competingElements[$tag]) > 0) { |
|
1426 | + $parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5]; |
|
1427 | + } |
|
1379 | 1428 | } |
1380 | 1429 | } |
1381 | 1430 | |
1382 | 1431 | // Unexpected closing tag, ex-ter-mi-nate. |
1383 | - else |
|
1384 | - $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
1432 | + else { |
|
1433 | + $parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = ''; |
|
1434 | + } |
|
1385 | 1435 | } |
1386 | 1436 | } |
1387 | 1437 | } |
1388 | 1438 | |
1389 | 1439 | // Close the code tags. |
1390 | - if ($inCode) |
|
1391 | - $parts[$i] .= '[/code]'; |
|
1440 | + if ($inCode) { |
|
1441 | + $parts[$i] .= '[/code]'; |
|
1442 | + } |
|
1392 | 1443 | |
1393 | 1444 | // The same for nobbc tags. |
1394 | - elseif ($inNoBbc) |
|
1395 | - $parts[$i] .= '[/nobbc]'; |
|
1445 | + elseif ($inNoBbc) { |
|
1446 | + $parts[$i] .= '[/nobbc]'; |
|
1447 | + } |
|
1396 | 1448 | |
1397 | 1449 | // Still inline tags left unclosed? Close them now, better late than never. |
1398 | - elseif (!empty($inlineElements)) |
|
1399 | - $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
1450 | + elseif (!empty($inlineElements)) { |
|
1451 | + $parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']'; |
|
1452 | + } |
|
1400 | 1453 | |
1401 | 1454 | // Now close the block elements. |
1402 | - if (!empty($blockElements)) |
|
1403 | - $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
1455 | + if (!empty($blockElements)) { |
|
1456 | + $parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']'; |
|
1457 | + } |
|
1404 | 1458 | |
1405 | 1459 | $text = implode('', $parts); |
1406 | 1460 | } |
1407 | 1461 | |
1408 | 1462 | // Final clean up of back to back tags. |
1409 | 1463 | $lastlen = 0; |
1410 | - while (strlen($text) !== $lastlen) |
|
1411 | - $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1464 | + while (strlen($text) !== $lastlen) { |
|
1465 | + $lastlen = strlen($text = preg_replace($backToBackPattern, '', $text)); |
|
1466 | + } |
|
1412 | 1467 | |
1413 | 1468 | return $text; |
1414 | 1469 | } |
@@ -1437,22 +1492,25 @@ discard block |
||
1437 | 1492 | $context['template_layers'] = array(); |
1438 | 1493 | // Lets make sure we aren't going to output anything nasty. |
1439 | 1494 | @ob_end_clean(); |
1440 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
1441 | - @ob_start('ob_gzhandler'); |
|
1442 | - else |
|
1443 | - @ob_start(); |
|
1495 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
1496 | + @ob_start('ob_gzhandler'); |
|
1497 | + } else { |
|
1498 | + @ob_start(); |
|
1499 | + } |
|
1444 | 1500 | |
1445 | 1501 | // If we don't have any locale better avoid broken js |
1446 | - if (empty($txt['lang_locale'])) |
|
1447 | - die(); |
|
1502 | + if (empty($txt['lang_locale'])) { |
|
1503 | + die(); |
|
1504 | + } |
|
1448 | 1505 | |
1449 | 1506 | $file_data = '(function ($) { |
1450 | 1507 | \'use strict\'; |
1451 | 1508 | |
1452 | 1509 | $.sceditor.locale[' . javaScriptEscape($txt['lang_locale']) . '] = {'; |
1453 | - foreach ($editortxt as $key => $val) |
|
1454 | - $file_data .= ' |
|
1510 | + foreach ($editortxt as $key => $val) { |
|
1511 | + $file_data .= ' |
|
1455 | 1512 | ' . javaScriptEscape($key) . ': ' . javaScriptEscape($val) . ','; |
1513 | + } |
|
1456 | 1514 | |
1457 | 1515 | $file_data .= ' |
1458 | 1516 | dateFormat: "day.month.year" |
@@ -1520,8 +1578,9 @@ discard block |
||
1520 | 1578 | ) |
1521 | 1579 | ); |
1522 | 1580 | $icon_data = array(); |
1523 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1524 | - $icon_data[] = $row; |
|
1581 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1582 | + $icon_data[] = $row; |
|
1583 | + } |
|
1525 | 1584 | $smcFunc['db_free_result']($request); |
1526 | 1585 | |
1527 | 1586 | $icons = array(); |
@@ -1536,9 +1595,9 @@ discard block |
||
1536 | 1595 | } |
1537 | 1596 | |
1538 | 1597 | cache_put_data('posting_icons-' . $board_id, $icons, 480); |
1598 | + } else { |
|
1599 | + $icons = $temp; |
|
1539 | 1600 | } |
1540 | - else |
|
1541 | - $icons = $temp; |
|
1542 | 1601 | } |
1543 | 1602 | call_integration_hook('integrate_load_message_icons', array(&$icons)); |
1544 | 1603 | |
@@ -1579,8 +1638,9 @@ discard block |
||
1579 | 1638 | { |
1580 | 1639 | // Some general stuff. |
1581 | 1640 | $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; |
1582 | - if (!empty($context['drafts_autosave'])) |
|
1583 | - $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
1641 | + if (!empty($context['drafts_autosave'])) { |
|
1642 | + $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000; |
|
1643 | + } |
|
1584 | 1644 | |
1585 | 1645 | // This really has some WYSIWYG stuff. |
1586 | 1646 | loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor'); |
@@ -1596,8 +1656,9 @@ discard block |
||
1596 | 1656 | var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\'; |
1597 | 1657 | var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';'); |
1598 | 1658 | // editor language file |
1599 | - if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') |
|
1600 | - loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
1659 | + if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') { |
|
1660 | + loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language'); |
|
1661 | + } |
|
1601 | 1662 | |
1602 | 1663 | $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))]; |
1603 | 1664 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
@@ -1606,11 +1667,12 @@ discard block |
||
1606 | 1667 | loadJavaScriptFile('spellcheck.js', array(), 'smf_spellcheck'); |
1607 | 1668 | |
1608 | 1669 | // Some hidden information is needed in order to make the spell checking work. |
1609 | - if (!isset($_REQUEST['xml'])) |
|
1610 | - $context['insert_after_template'] .= ' |
|
1670 | + if (!isset($_REQUEST['xml'])) { |
|
1671 | + $context['insert_after_template'] .= ' |
|
1611 | 1672 | <form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> |
1612 | 1673 | <input type="hidden" name="spellstring" value=""> |
1613 | 1674 | </form>'; |
1675 | + } |
|
1614 | 1676 | } |
1615 | 1677 | } |
1616 | 1678 | |
@@ -1776,10 +1838,12 @@ discard block |
||
1776 | 1838 | |
1777 | 1839 | // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this. |
1778 | 1840 | $disabled_tags = array(); |
1779 | - if (!empty($modSettings['disabledBBC'])) |
|
1780 | - $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
1781 | - if (empty($modSettings['enableEmbeddedFlash'])) |
|
1782 | - $disabled_tags[] = 'flash'; |
|
1841 | + if (!empty($modSettings['disabledBBC'])) { |
|
1842 | + $disabled_tags = explode(',', $modSettings['disabledBBC']); |
|
1843 | + } |
|
1844 | + if (empty($modSettings['enableEmbeddedFlash'])) { |
|
1845 | + $disabled_tags[] = 'flash'; |
|
1846 | + } |
|
1783 | 1847 | |
1784 | 1848 | foreach ($disabled_tags as $tag) |
1785 | 1849 | { |
@@ -1789,9 +1853,10 @@ discard block |
||
1789 | 1853 | $context['disabled_tags']['orderedlist'] = true; |
1790 | 1854 | } |
1791 | 1855 | |
1792 | - foreach ($editor_tag_map as $thisTag => $tagNameBBC) |
|
1793 | - if ($tag === $thisTag) |
|
1856 | + foreach ($editor_tag_map as $thisTag => $tagNameBBC) { |
|
1857 | + if ($tag === $thisTag) |
|
1794 | 1858 | $context['disabled_tags'][$tagNameBBC] = true; |
1859 | + } |
|
1795 | 1860 | |
1796 | 1861 | $context['disabled_tags'][trim($tag)] = true; |
1797 | 1862 | } |
@@ -1801,19 +1866,21 @@ discard block |
||
1801 | 1866 | $context['bbc_toolbar'] = array(); |
1802 | 1867 | foreach ($context['bbc_tags'] as $row => $tagRow) |
1803 | 1868 | { |
1804 | - if (!isset($context['bbc_toolbar'][$row])) |
|
1805 | - $context['bbc_toolbar'][$row] = array(); |
|
1869 | + if (!isset($context['bbc_toolbar'][$row])) { |
|
1870 | + $context['bbc_toolbar'][$row] = array(); |
|
1871 | + } |
|
1806 | 1872 | $tagsRow = array(); |
1807 | 1873 | foreach ($tagRow as $tag) |
1808 | 1874 | { |
1809 | 1875 | if ((!empty($tag['code'])) && empty($context['disabled_tags'][$tag['code']])) |
1810 | 1876 | { |
1811 | 1877 | $tagsRow[] = $tag['code']; |
1812 | - if (isset($tag['image'])) |
|
1813 | - $bbcodes_styles .= ' |
|
1878 | + if (isset($tag['image'])) { |
|
1879 | + $bbcodes_styles .= ' |
|
1814 | 1880 | .sceditor-button-' . $tag['code'] . ' div { |
1815 | 1881 | background: url(\'' . $settings['default_theme_url'] . '/images/bbc/' . $tag['image'] . '.png\'); |
1816 | 1882 | }'; |
1883 | + } |
|
1817 | 1884 | if (isset($tag['before'])) |
1818 | 1885 | { |
1819 | 1886 | $context['bbcodes_handlers'] .= ' |
@@ -1827,8 +1894,7 @@ discard block |
||
1827 | 1894 | });'; |
1828 | 1895 | } |
1829 | 1896 | |
1830 | - } |
|
1831 | - else |
|
1897 | + } else |
|
1832 | 1898 | { |
1833 | 1899 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
1834 | 1900 | $tagsRow = array(); |
@@ -1839,14 +1905,16 @@ discard block |
||
1839 | 1905 | { |
1840 | 1906 | $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
1841 | 1907 | $tagsRow = array(); |
1842 | - if (!isset($context['disabled_tags']['font'])) |
|
1843 | - $tagsRow[] = 'font'; |
|
1844 | - if (!isset($context['disabled_tags']['size'])) |
|
1845 | - $tagsRow[] = 'size'; |
|
1846 | - if (!isset($context['disabled_tags']['color'])) |
|
1847 | - $tagsRow[] = 'color'; |
|
1848 | - } |
|
1849 | - elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
1908 | + if (!isset($context['disabled_tags']['font'])) { |
|
1909 | + $tagsRow[] = 'font'; |
|
1910 | + } |
|
1911 | + if (!isset($context['disabled_tags']['size'])) { |
|
1912 | + $tagsRow[] = 'size'; |
|
1913 | + } |
|
1914 | + if (!isset($context['disabled_tags']['color'])) { |
|
1915 | + $tagsRow[] = 'color'; |
|
1916 | + } |
|
1917 | + } elseif ($row == 1 && empty($modSettings['disable_wysiwyg'])) |
|
1850 | 1918 | { |
1851 | 1919 | $tmp = array(); |
1852 | 1920 | $tagsRow[] = 'removeformat'; |
@@ -1857,13 +1925,15 @@ discard block |
||
1857 | 1925 | } |
1858 | 1926 | } |
1859 | 1927 | |
1860 | - if (!empty($tagsRow)) |
|
1861 | - $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
1928 | + if (!empty($tagsRow)) { |
|
1929 | + $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); |
|
1930 | + } |
|
1862 | 1931 | } |
1863 | - if (!empty($bbcodes_styles)) |
|
1864 | - $context['html_headers'] .= ' |
|
1932 | + if (!empty($bbcodes_styles)) { |
|
1933 | + $context['html_headers'] .= ' |
|
1865 | 1934 | <style>' . $bbcodes_styles . ' |
1866 | 1935 | </style>'; |
1936 | + } |
|
1867 | 1937 | } |
1868 | 1938 | |
1869 | 1939 | // Initialize smiley array... if not loaded before. |
@@ -1875,8 +1945,8 @@ discard block |
||
1875 | 1945 | ); |
1876 | 1946 | |
1877 | 1947 | // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. |
1878 | - if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') |
|
1879 | - $context['smileys']['postform'][] = array( |
|
1948 | + if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { |
|
1949 | + $context['smileys']['postform'][] = array( |
|
1880 | 1950 | 'smileys' => array( |
1881 | 1951 | array( |
1882 | 1952 | 'code' => ':)', |
@@ -1962,7 +2032,7 @@ discard block |
||
1962 | 2032 | ), |
1963 | 2033 | 'isLast' => true, |
1964 | 2034 | ); |
1965 | - elseif ($user_info['smiley_set'] != 'none') |
|
2035 | + } elseif ($user_info['smiley_set'] != 'none') |
|
1966 | 2036 | { |
1967 | 2037 | if (($temp = cache_get_data('posting_smileys', 480)) == null) |
1968 | 2038 | { |
@@ -1985,17 +2055,19 @@ discard block |
||
1985 | 2055 | |
1986 | 2056 | foreach ($context['smileys'] as $section => $smileyRows) |
1987 | 2057 | { |
1988 | - foreach ($smileyRows as $rowIndex => $smileys) |
|
1989 | - $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
2058 | + foreach ($smileyRows as $rowIndex => $smileys) { |
|
2059 | + $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; |
|
2060 | + } |
|
1990 | 2061 | |
1991 | - if (!empty($smileyRows)) |
|
1992 | - $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
2062 | + if (!empty($smileyRows)) { |
|
2063 | + $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true; |
|
2064 | + } |
|
1993 | 2065 | } |
1994 | 2066 | |
1995 | 2067 | cache_put_data('posting_smileys', $context['smileys'], 480); |
2068 | + } else { |
|
2069 | + $context['smileys'] = $temp; |
|
1996 | 2070 | } |
1997 | - else |
|
1998 | - $context['smileys'] = $temp; |
|
1999 | 2071 | } |
2000 | 2072 | } |
2001 | 2073 | |
@@ -2021,8 +2093,9 @@ discard block |
||
2021 | 2093 | loadTemplate('GenericControls'); |
2022 | 2094 | |
2023 | 2095 | // Some javascript ma'am? |
2024 | - if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) |
|
2025 | - loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
2096 | + if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) { |
|
2097 | + loadJavaScriptFile('captcha.js', array(), 'smf_captcha'); |
|
2098 | + } |
|
2026 | 2099 | |
2027 | 2100 | $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); |
2028 | 2101 | |
@@ -2035,8 +2108,8 @@ discard block |
||
2035 | 2108 | $isNew = !isset($context['controls']['verification'][$verificationOptions['id']]); |
2036 | 2109 | |
2037 | 2110 | // Log this into our collection. |
2038 | - if ($isNew) |
|
2039 | - $context['controls']['verification'][$verificationOptions['id']] = array( |
|
2111 | + if ($isNew) { |
|
2112 | + $context['controls']['verification'][$verificationOptions['id']] = array( |
|
2040 | 2113 | 'id' => $verificationOptions['id'], |
2041 | 2114 | 'empty_field' => empty($verificationOptions['no_empty_field']), |
2042 | 2115 | 'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])), |
@@ -2047,13 +2120,15 @@ discard block |
||
2047 | 2120 | 'questions' => array(), |
2048 | 2121 | 'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']), |
2049 | 2122 | ); |
2123 | + } |
|
2050 | 2124 | $thisVerification = &$context['controls']['verification'][$verificationOptions['id']]; |
2051 | 2125 | |
2052 | 2126 | // Is there actually going to be anything? |
2053 | - if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) |
|
2054 | - return false; |
|
2055 | - elseif (!$isNew && !$do_test) |
|
2056 | - return true; |
|
2127 | + if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) { |
|
2128 | + return false; |
|
2129 | + } elseif (!$isNew && !$do_test) { |
|
2130 | + return true; |
|
2131 | + } |
|
2057 | 2132 | |
2058 | 2133 | // Sanitize reCAPTCHA fields? |
2059 | 2134 | if ($thisVerification['can_recaptcha']) |
@@ -2066,11 +2141,12 @@ discard block |
||
2066 | 2141 | } |
2067 | 2142 | |
2068 | 2143 | // Add javascript for the object. |
2069 | - if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) |
|
2070 | - $context['insert_after_template'] .= ' |
|
2144 | + if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) { |
|
2145 | + $context['insert_after_template'] .= ' |
|
2071 | 2146 | <script> |
2072 | 2147 | var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . '); |
2073 | 2148 | </script>'; |
2149 | + } |
|
2074 | 2150 | |
2075 | 2151 | // If we want questions do we have a cache of all the IDs? |
2076 | 2152 | if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache'])) |
@@ -2093,8 +2169,9 @@ discard block |
||
2093 | 2169 | unset ($row['id_question']); |
2094 | 2170 | // Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh? |
2095 | 2171 | $row['answers'] = smf_json_decode($row['answers'], true); |
2096 | - foreach ($row['answers'] as $k => $v) |
|
2097 | - $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
2172 | + foreach ($row['answers'] as $k => $v) { |
|
2173 | + $row['answers'][$k] = $smcFunc['strtolower']($v); |
|
2174 | + } |
|
2098 | 2175 | |
2099 | 2176 | $modSettings['question_id_cache']['questions'][$id_question] = $row; |
2100 | 2177 | $modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question; |
@@ -2105,35 +2182,42 @@ discard block |
||
2105 | 2182 | } |
2106 | 2183 | } |
2107 | 2184 | |
2108 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) |
|
2109 | - $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
2185 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) { |
|
2186 | + $_SESSION[$verificationOptions['id'] . '_vv'] = array(); |
|
2187 | + } |
|
2110 | 2188 | |
2111 | 2189 | // Do we need to refresh the verification? |
2112 | - if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) |
|
2113 | - $force_refresh = true; |
|
2114 | - else |
|
2115 | - $force_refresh = false; |
|
2190 | + if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) { |
|
2191 | + $force_refresh = true; |
|
2192 | + } else { |
|
2193 | + $force_refresh = false; |
|
2194 | + } |
|
2116 | 2195 | |
2117 | 2196 | // This can also force a fresh, although unlikely. |
2118 | - if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) |
|
2119 | - $force_refresh = true; |
|
2197 | + if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) { |
|
2198 | + $force_refresh = true; |
|
2199 | + } |
|
2120 | 2200 | |
2121 | 2201 | $verification_errors = array(); |
2122 | 2202 | // Start with any testing. |
2123 | 2203 | if ($do_test) |
2124 | 2204 | { |
2125 | 2205 | // This cannot happen! |
2126 | - if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) |
|
2127 | - fatal_lang_error('no_access', false); |
|
2206 | + if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) { |
|
2207 | + fatal_lang_error('no_access', false); |
|
2208 | + } |
|
2128 | 2209 | // ... nor this! |
2129 | - if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) |
|
2130 | - fatal_lang_error('no_access', false); |
|
2210 | + if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) { |
|
2211 | + fatal_lang_error('no_access', false); |
|
2212 | + } |
|
2131 | 2213 | // Hmm, it's requested but not actually declared. This shouldn't happen. |
2132 | - if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
|
2133 | - fatal_lang_error('no_access', false); |
|
2214 | + if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) { |
|
2215 | + fatal_lang_error('no_access', false); |
|
2216 | + } |
|
2134 | 2217 | // While we're here, did the user do something bad? |
2135 | - if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) |
|
2136 | - $verification_errors[] = 'wrong_verification_answer'; |
|
2218 | + if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) { |
|
2219 | + $verification_errors[] = 'wrong_verification_answer'; |
|
2220 | + } |
|
2137 | 2221 | |
2138 | 2222 | if ($thisVerification['can_recaptcha']) |
2139 | 2223 | { |
@@ -2144,22 +2228,25 @@ discard block |
||
2144 | 2228 | { |
2145 | 2229 | $resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']); |
2146 | 2230 | |
2147 | - if (!$resp->isSuccess()) |
|
2148 | - $verification_errors[] = 'wrong_verification_code'; |
|
2231 | + if (!$resp->isSuccess()) { |
|
2232 | + $verification_errors[] = 'wrong_verification_code'; |
|
2233 | + } |
|
2234 | + } else { |
|
2235 | + $verification_errors[] = 'wrong_verification_code'; |
|
2149 | 2236 | } |
2150 | - else |
|
2151 | - $verification_errors[] = 'wrong_verification_code'; |
|
2152 | 2237 | } |
2153 | - if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) |
|
2154 | - $verification_errors[] = 'wrong_verification_code'; |
|
2238 | + if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) { |
|
2239 | + $verification_errors[] = 'wrong_verification_code'; |
|
2240 | + } |
|
2155 | 2241 | if ($thisVerification['number_questions']) |
2156 | 2242 | { |
2157 | 2243 | $incorrectQuestions = array(); |
2158 | 2244 | foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q) |
2159 | 2245 | { |
2160 | 2246 | // We don't have this question any more, thus no answers. |
2161 | - if (!isset($modSettings['question_id_cache']['questions'][$q])) |
|
2162 | - continue; |
|
2247 | + if (!isset($modSettings['question_id_cache']['questions'][$q])) { |
|
2248 | + continue; |
|
2249 | + } |
|
2163 | 2250 | // This is quite complex. We have our question but it might have multiple answers. |
2164 | 2251 | // First, did they actually answer this question? |
2165 | 2252 | if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '') |
@@ -2171,24 +2258,28 @@ discard block |
||
2171 | 2258 | else |
2172 | 2259 | { |
2173 | 2260 | $given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]))); |
2174 | - if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) |
|
2175 | - $incorrectQuestions[] = $q; |
|
2261 | + if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) { |
|
2262 | + $incorrectQuestions[] = $q; |
|
2263 | + } |
|
2176 | 2264 | } |
2177 | 2265 | } |
2178 | 2266 | |
2179 | - if (!empty($incorrectQuestions)) |
|
2180 | - $verification_errors[] = 'wrong_verification_answer'; |
|
2267 | + if (!empty($incorrectQuestions)) { |
|
2268 | + $verification_errors[] = 'wrong_verification_answer'; |
|
2269 | + } |
|
2181 | 2270 | } |
2182 | 2271 | } |
2183 | 2272 | |
2184 | 2273 | // Any errors means we refresh potentially. |
2185 | 2274 | if (!empty($verification_errors)) |
2186 | 2275 | { |
2187 | - if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) |
|
2188 | - $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
2276 | + if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) { |
|
2277 | + $_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0; |
|
2278 | + } |
|
2189 | 2279 | // Too many errors? |
2190 | - elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) |
|
2191 | - $force_refresh = true; |
|
2280 | + elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) { |
|
2281 | + $force_refresh = true; |
|
2282 | + } |
|
2192 | 2283 | |
2193 | 2284 | // Keep a track of these. |
2194 | 2285 | $_SESSION[$verificationOptions['id'] . '_vv']['errors']++; |
@@ -2221,8 +2312,9 @@ discard block |
||
2221 | 2312 | // Are we overriding the range? |
2222 | 2313 | $character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range']; |
2223 | 2314 | |
2224 | - for ($i = 0; $i < 6; $i++) |
|
2225 | - $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
2315 | + for ($i = 0; $i < 6; $i++) { |
|
2316 | + $_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)]; |
|
2317 | + } |
|
2226 | 2318 | } |
2227 | 2319 | |
2228 | 2320 | // Getting some new questions? |
@@ -2230,8 +2322,9 @@ discard block |
||
2230 | 2322 | { |
2231 | 2323 | // Attempt to try the current page's language, followed by the user's preference, followed by the site default. |
2232 | 2324 | $possible_langs = array(); |
2233 | - if (isset($_SESSION['language'])) |
|
2234 | - $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
2325 | + if (isset($_SESSION['language'])) { |
|
2326 | + $possible_langs[] = strtr($_SESSION['language'], array('-utf8' => '')); |
|
2327 | + } |
|
2235 | 2328 | if (!empty($user_info['language'])); |
2236 | 2329 | $possible_langs[] = $user_info['language']; |
2237 | 2330 | $possible_langs[] = $language; |
@@ -2250,8 +2343,7 @@ discard block |
||
2250 | 2343 | } |
2251 | 2344 | } |
2252 | 2345 | } |
2253 | - } |
|
2254 | - else |
|
2346 | + } else |
|
2255 | 2347 | { |
2256 | 2348 | // Same questions as before. |
2257 | 2349 | $questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array(); |
@@ -2261,8 +2353,9 @@ discard block |
||
2261 | 2353 | // If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway. |
2262 | 2354 | if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) |
2263 | 2355 | { |
2264 | - if (!isset($context['html_headers'])) |
|
2265 | - $context['html_headers'] = ''; |
|
2356 | + if (!isset($context['html_headers'])) { |
|
2357 | + $context['html_headers'] = ''; |
|
2358 | + } |
|
2266 | 2359 | $context['html_headers'] .= '<style>.vv_special { display:none; }</style>'; |
2267 | 2360 | } |
2268 | 2361 | |
@@ -2288,11 +2381,13 @@ discard block |
||
2288 | 2381 | $_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1; |
2289 | 2382 | |
2290 | 2383 | // Return errors if we have them. |
2291 | - if (!empty($verification_errors)) |
|
2292 | - return $verification_errors; |
|
2384 | + if (!empty($verification_errors)) { |
|
2385 | + return $verification_errors; |
|
2386 | + } |
|
2293 | 2387 | // If we had a test that one, make a note. |
2294 | - elseif ($do_test) |
|
2295 | - $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
2388 | + elseif ($do_test) { |
|
2389 | + $_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true; |
|
2390 | + } |
|
2296 | 2391 | |
2297 | 2392 | // Say that everything went well chaps. |
2298 | 2393 | return true; |
@@ -2317,8 +2412,9 @@ discard block |
||
2317 | 2412 | call_integration_hook('integrate_autosuggest', array(&$searchTypes)); |
2318 | 2413 | |
2319 | 2414 | // If we're just checking the callback function is registered return true or false. |
2320 | - if ($checkRegistered != null) |
|
2321 | - return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
2415 | + if ($checkRegistered != null) { |
|
2416 | + return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered); |
|
2417 | + } |
|
2322 | 2418 | |
2323 | 2419 | checkSession('get'); |
2324 | 2420 | loadTemplate('Xml'); |
@@ -2469,24 +2565,27 @@ discard block |
||
2469 | 2565 | foreach ($possible_versions as $ver) |
2470 | 2566 | { |
2471 | 2567 | $ver = trim($ver); |
2472 | - if (strpos($ver, 'SMF') === 0) |
|
2473 | - $versions[] = $ver; |
|
2568 | + if (strpos($ver, 'SMF') === 0) { |
|
2569 | + $versions[] = $ver; |
|
2570 | + } |
|
2474 | 2571 | } |
2475 | 2572 | } |
2476 | 2573 | $smcFunc['db_free_result']($request); |
2477 | 2574 | |
2478 | 2575 | // Just in case we don't have ANYthing. |
2479 | - if (empty($versions)) |
|
2480 | - $versions = array('SMF 2.0'); |
|
2576 | + if (empty($versions)) { |
|
2577 | + $versions = array('SMF 2.0'); |
|
2578 | + } |
|
2481 | 2579 | |
2482 | - foreach ($versions as $id => $version) |
|
2483 | - if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
2580 | + foreach ($versions as $id => $version) { |
|
2581 | + if (strpos($version, strtoupper($_REQUEST['search'])) !== false) |
|
2484 | 2582 | $xml_data['items']['children'][] = array( |
2485 | 2583 | 'attributes' => array( |
2486 | 2584 | 'id' => $id, |
2487 | 2585 | ), |
2488 | 2586 | 'value' => $version, |
2489 | 2587 | ); |
2588 | + } |
|
2490 | 2589 | |
2491 | 2590 | return $xml_data; |
2492 | 2591 | } |
@@ -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 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
110 | 111 | |
111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
112 | 113 | |
113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
116 | + } |
|
115 | 117 | |
116 | 118 | $context['colspan'] = 0; |
117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
148 | 150 | |
149 | 151 | // Jump to the sub action. |
150 | - if (isset($subActions[$context['listing_by']])) |
|
151 | - call_helper($subActions[$context['listing_by']][1]); |
|
152 | - |
|
153 | - else |
|
154 | - call_helper($subActions['all'][1]); |
|
155 | -} |
|
152 | + if (isset($subActions[$context['listing_by']])) { |
|
153 | + call_helper($subActions[$context['listing_by']][1]); |
|
154 | + } else { |
|
155 | + call_helper($subActions['all'][1]); |
|
156 | + } |
|
157 | + } |
|
156 | 158 | |
157 | 159 | /** |
158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | if ($use_cache) |
178 | 180 | { |
179 | 181 | // Maybe there's something cached already. |
180 | - if (!empty($modSettings['memberlist_cache'])) |
|
181 | - $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
183 | + $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
184 | + } |
|
182 | 185 | |
183 | 186 | // The chunk size for the cached index. |
184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
234 | 237 | } |
235 | 238 | |
236 | 239 | // Set defaults for sort (real_name) and start. (0) |
237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
238 | - $_REQUEST['sort'] = 'real_name'; |
|
240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
241 | + $_REQUEST['sort'] = 'real_name'; |
|
242 | + } |
|
239 | 243 | |
240 | 244 | if (!is_numeric($_REQUEST['start'])) |
241 | 245 | { |
242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
243 | - fatal_error('Hacker?', false); |
|
246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
247 | + fatal_error('Hacker?', false); |
|
248 | + } |
|
244 | 249 | |
245 | 250 | $_REQUEST['start'] = $match[0]; |
246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
259 | 264 | } |
260 | 265 | |
261 | 266 | $context['letter_links'] = ''; |
262 | - for ($i = 97; $i < 123; $i++) |
|
263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
267 | + for ($i = 97; $i < 123; $i++) { |
|
268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
269 | + } |
|
264 | 270 | |
265 | 271 | // Sort out the column information. |
266 | 272 | foreach ($context['columns'] as $col => $column_details) |
267 | 273 | { |
268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
269 | 275 | |
270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
278 | + } |
|
272 | 279 | |
273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
318 | 325 | { |
319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
320 | - if ($first_offset < 0) |
|
321 | - $first_offset = 0; |
|
327 | + if ($first_offset < 0) { |
|
328 | + $first_offset = 0; |
|
329 | + } |
|
322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
323 | 331 | |
324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -328,8 +336,9 @@ discard block |
||
328 | 336 | } |
329 | 337 | |
330 | 338 | $custom_fields_qry = ''; |
331 | - if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) |
|
332 | - $custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']]; |
|
339 | + if (!empty($context['custom_profile_fields']['join'][$_REQUEST['sort']])) { |
|
340 | + $custom_fields_qry = $context['custom_profile_fields']['join'][$_REQUEST['sort']]; |
|
341 | + } |
|
333 | 342 | |
334 | 343 | // Select the members from the database. |
335 | 344 | $request = $smcFunc['db_query']('', ' |
@@ -399,12 +408,13 @@ discard block |
||
399 | 408 | ) |
400 | 409 | ); |
401 | 410 | $context['custom_search_fields'] = array(); |
402 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
403 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
411 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
412 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
404 | 413 | 'colname' => $row['col_name'], |
405 | 414 | 'name' => $row['field_name'], |
406 | 415 | 'desc' => $row['field_desc'], |
407 | 416 | ); |
417 | + } |
|
408 | 418 | $smcFunc['db_free_result']($request); |
409 | 419 | |
410 | 420 | // They're searching.. |
@@ -417,23 +427,27 @@ discard block |
||
417 | 427 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
418 | 428 | |
419 | 429 | // No fields? Use default... |
420 | - if (empty($_POST['fields'])) |
|
421 | - $_POST['fields'] = array('name'); |
|
430 | + if (empty($_POST['fields'])) { |
|
431 | + $_POST['fields'] = array('name'); |
|
432 | + } |
|
422 | 433 | |
423 | 434 | // Set defaults for how the results are sorted |
424 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
425 | - $_REQUEST['sort'] = 'real_name'; |
|
435 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
436 | + $_REQUEST['sort'] = 'real_name'; |
|
437 | + } |
|
426 | 438 | |
427 | 439 | // Build the column link / sort information. |
428 | 440 | foreach ($context['columns'] as $col => $column_details) |
429 | 441 | { |
430 | 442 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
431 | 443 | |
432 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
433 | - $context['columns'][$col]['href'] .= ';desc'; |
|
444 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
445 | + $context['columns'][$col]['href'] .= ';desc'; |
|
446 | + } |
|
434 | 447 | |
435 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
436 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
448 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
449 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
450 | + } |
|
437 | 451 | |
438 | 452 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
439 | 453 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -456,8 +470,7 @@ discard block |
||
456 | 470 | { |
457 | 471 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
458 | 472 | $search_fields[] = 'name'; |
459 | - } |
|
460 | - else |
|
473 | + } else |
|
461 | 474 | { |
462 | 475 | $fields = array(); |
463 | 476 | $search_fields = array(); |
@@ -482,9 +495,10 @@ discard block |
||
482 | 495 | $search_fields[] = 'email'; |
483 | 496 | } |
484 | 497 | |
485 | - if ($smcFunc['db_case_sensitive']) |
|
486 | - foreach ($fields as $key => $field) |
|
498 | + if ($smcFunc['db_case_sensitive']) { |
|
499 | + foreach ($fields as $key => $field) |
|
487 | 500 | $fields[$key] = 'LOWER(' . $field . ')'; |
501 | + } |
|
488 | 502 | |
489 | 503 | $customJoin = array(); |
490 | 504 | $customCount = 10; |
@@ -503,8 +517,9 @@ discard block |
||
503 | 517 | } |
504 | 518 | |
505 | 519 | // No search fields? That means you're trying to hack things |
506 | - if (empty($search_fields)) |
|
507 | - fatal_lang_error('invalid_search_string', false); |
|
520 | + if (empty($search_fields)) { |
|
521 | + fatal_lang_error('invalid_search_string', false); |
|
522 | + } |
|
508 | 523 | |
509 | 524 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
510 | 525 | |
@@ -542,8 +557,7 @@ discard block |
||
542 | 557 | ); |
543 | 558 | printMemberListRows($request); |
544 | 559 | $smcFunc['db_free_result']($request); |
545 | - } |
|
546 | - else |
|
560 | + } else |
|
547 | 561 | { |
548 | 562 | // These are all the possible fields. |
549 | 563 | $context['search_fields'] = array( |
@@ -558,14 +572,14 @@ discard block |
||
558 | 572 | { |
559 | 573 | unset($context['search_fields']['email']); |
560 | 574 | $context['search_defaults'] = array('name'); |
561 | - } |
|
562 | - else |
|
575 | + } else |
|
563 | 576 | { |
564 | 577 | $context['search_defaults'] = array('name', 'email'); |
565 | 578 | } |
566 | 579 | |
567 | - foreach ($context['custom_search_fields'] as $field) |
|
568 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
580 | + foreach ($context['custom_search_fields'] as $field) { |
|
581 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
582 | + } |
|
569 | 583 | |
570 | 584 | $context['sub_template'] = 'search'; |
571 | 585 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -607,12 +621,14 @@ discard block |
||
607 | 621 | $smcFunc['db_free_result']($result); |
608 | 622 | |
609 | 623 | // Avoid division by zero... |
610 | - if ($most_posts == 0) |
|
611 | - $most_posts = 1; |
|
624 | + if ($most_posts == 0) { |
|
625 | + $most_posts = 1; |
|
626 | + } |
|
612 | 627 | |
613 | 628 | $members = array(); |
614 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
615 | - $members[] = $row['id_member']; |
|
629 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
630 | + $members[] = $row['id_member']; |
|
631 | + } |
|
616 | 632 | |
617 | 633 | // Load all the members for display. |
618 | 634 | loadMemberData($members); |
@@ -620,8 +636,9 @@ discard block |
||
620 | 636 | $context['members'] = array(); |
621 | 637 | foreach ($members as $member) |
622 | 638 | { |
623 | - if (!loadMemberContext($member)) |
|
624 | - continue; |
|
639 | + if (!loadMemberContext($member)) { |
|
640 | + continue; |
|
641 | + } |
|
625 | 642 | |
626 | 643 | $context['members'][$member] = $memberContext[$member]; |
627 | 644 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -638,20 +655,21 @@ discard block |
||
638 | 655 | continue; |
639 | 656 | } |
640 | 657 | |
641 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
642 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
643 | - |
|
644 | - elseif ($column['type'] == 'check') |
|
645 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
658 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
659 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
660 | + } elseif ($column['type'] == 'check') { |
|
661 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
662 | + } |
|
646 | 663 | |
647 | 664 | // Enclosing the user input within some other text? |
648 | - if (!empty($column['enclose'])) |
|
649 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
665 | + if (!empty($column['enclose'])) { |
|
666 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
650 | 667 | '{SCRIPTURL}' => $scripturl, |
651 | 668 | '{IMAGES_URL}' => $settings['images_url'], |
652 | 669 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
653 | 670 | '{INPUT}' => $context['members'][$member]['options'][$key], |
654 | 671 | )); |
672 | + } |
|
655 | 673 | } |
656 | 674 | } |
657 | 675 | } |
@@ -692,17 +710,17 @@ discard block |
||
692 | 710 | ); |
693 | 711 | |
694 | 712 | // Get the right sort method depending on the cust field type. |
695 | - if ($row['field_type'] != 'check') |
|
696 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
713 | + if ($row['field_type'] != 'check') { |
|
714 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
697 | 715 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, \'\') DESC', |
698 | 716 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, \'\') ASC' |
699 | 717 | ); |
700 | - |
|
701 | - else |
|
702 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
718 | + } else { |
|
719 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
703 | 720 | 'down' => 't' . $row['col_name'] . '.value DESC', |
704 | 721 | 'up' => 't' . $row['col_name'] . '.value ASC' |
705 | 722 | ); |
723 | + } |
|
706 | 724 | |
707 | 725 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
708 | 726 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | /** |
20 | 20 | * Truncate the GET array to a specified length |
21 | 21 | * @param array $arr The array to truncate |
22 | - * @param max_length $max_length The upperbound on the length |
|
22 | + * @param integer $max_length The upperbound on the length |
|
23 | 23 | * |
24 | 24 | * @return array The truncated array |
25 | 25 | */ |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array The truncated array |
25 | 25 | */ |
26 | -function truncateArray($arr, $max_length=1900) |
|
26 | +function truncateArray($arr, $max_length = 1900) |
|
27 | 27 | { |
28 | 28 | $curr_length = array_sum(array_map("strlen", $arr)); |
29 | 29 | if ($curr_length <= $max_length) |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | else |
32 | 32 | { |
33 | 33 | // Truncate each element's value to a reasonable length |
34 | - $param_max = floor($max_length/count($arr)); |
|
34 | + $param_max = floor($max_length / count($arr)); |
|
35 | 35 | foreach ($arr as $key => &$value) |
36 | 36 | $value = substr($value, 0, $param_max - strlen($key) - 5); |
37 | 37 | return $arr; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if (filemtime($boarddir . '/db_last_error.php') === $last_db_error_change) |
198 | 198 | { |
199 | 199 | // Write the change |
200 | - $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
200 | + $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
201 | 201 | $written_bytes = file_put_contents($boarddir . '/db_last_error.php', $write_db_change, LOCK_EX); |
202 | 202 | |
203 | 203 | // survey says ... |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br> |
271 | 271 | ', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br> |
272 | 272 | ', $txt['debug_hooks'], empty($context['debug']['hooks']) ? 0 : count($context['debug']['hooks']) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_hooks\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_hooks" style="display: none;"><em>' . implode('</em>, <em>', $context['debug']['hooks']), '</em></span>)', '<br> |
273 | - ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
|
273 | + ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">' . $txt['debug_show'] . '</a><span id="debug_instances" style="display: none;"><em>' . implode('</em>, <em>', array_keys($context['debug']['instances'])) . '</em></span>)' . '<br>') : ''), ' |
|
274 | 274 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
275 | 275 | |
276 | 276 | if (function_exists('memory_get_peak_usage')) |
@@ -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 | * Truncate the GET array to a specified length |
@@ -26,14 +27,15 @@ discard block |
||
26 | 27 | function truncateArray($arr, $max_length=1900) |
27 | 28 | { |
28 | 29 | $curr_length = array_sum(array_map("strlen", $arr)); |
29 | - if ($curr_length <= $max_length) |
|
30 | - return $arr; |
|
31 | - else |
|
30 | + if ($curr_length <= $max_length) { |
|
31 | + return $arr; |
|
32 | + } else |
|
32 | 33 | { |
33 | 34 | // Truncate each element's value to a reasonable length |
34 | 35 | $param_max = floor($max_length/count($arr)); |
35 | - foreach ($arr as $key => &$value) |
|
36 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
36 | + foreach ($arr as $key => &$value) { |
|
37 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
38 | + } |
|
37 | 39 | return $arr; |
38 | 40 | } |
39 | 41 | } |
@@ -55,8 +57,9 @@ discard block |
||
55 | 57 | // Don't update for every page - this isn't wholly accurate but who cares. |
56 | 58 | if ($topic) |
57 | 59 | { |
58 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
59 | - $force = false; |
|
60 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
61 | + $force = false; |
|
62 | + } |
|
60 | 63 | $_SESSION['last_topic_id'] = $topic; |
61 | 64 | } |
62 | 65 | } |
@@ -69,22 +72,24 @@ discard block |
||
69 | 72 | } |
70 | 73 | |
71 | 74 | // Don't mark them as online more than every so often. |
72 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
73 | - return; |
|
75 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
76 | + return; |
|
77 | + } |
|
74 | 78 | |
75 | 79 | if (!empty($modSettings['who_enabled'])) |
76 | 80 | { |
77 | 81 | $serialized = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
78 | 82 | |
79 | 83 | // In the case of a dlattach action, session_var may not be set. |
80 | - if (!isset($context['session_var'])) |
|
81 | - $context['session_var'] = $_SESSION['session_var']; |
|
84 | + if (!isset($context['session_var'])) { |
|
85 | + $context['session_var'] = $_SESSION['session_var']; |
|
86 | + } |
|
82 | 87 | |
83 | 88 | unset($serialized['sesc'], $serialized[$context['session_var']]); |
84 | 89 | $serialized = json_encode($serialized); |
90 | + } else { |
|
91 | + $serialized = ''; |
|
85 | 92 | } |
86 | - else |
|
87 | - $serialized = ''; |
|
88 | 93 | |
89 | 94 | // Guests use 0, members use their session ID. |
90 | 95 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -124,17 +129,18 @@ discard block |
||
124 | 129 | ); |
125 | 130 | |
126 | 131 | // Guess it got deleted. |
127 | - if ($smcFunc['db_affected_rows']() == 0) |
|
132 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
133 | + $_SESSION['log_time'] = 0; |
|
134 | + } |
|
135 | + } else { |
|
128 | 136 | $_SESSION['log_time'] = 0; |
129 | 137 | } |
130 | - else |
|
131 | - $_SESSION['log_time'] = 0; |
|
132 | 138 | |
133 | 139 | // Otherwise, we have to delete and insert. |
134 | 140 | if (empty($_SESSION['log_time'])) |
135 | 141 | { |
136 | - if ($do_delete || !empty($user_info['id'])) |
|
137 | - $smcFunc['db_query']('', ' |
|
142 | + if ($do_delete || !empty($user_info['id'])) { |
|
143 | + $smcFunc['db_query']('', ' |
|
138 | 144 | DELETE FROM {db_prefix}log_online |
139 | 145 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
140 | 146 | array( |
@@ -142,6 +148,7 @@ discard block |
||
142 | 148 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
143 | 149 | ) |
144 | 150 | ); |
151 | + } |
|
145 | 152 | |
146 | 153 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
147 | 154 | '{db_prefix}log_online', |
@@ -155,21 +162,24 @@ discard block |
||
155 | 162 | $_SESSION['log_time'] = time(); |
156 | 163 | |
157 | 164 | // Well, they are online now. |
158 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
159 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
165 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
166 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
167 | + } |
|
160 | 168 | |
161 | 169 | // Set their login time, if not already done within the last minute. |
162 | 170 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
163 | 171 | { |
164 | 172 | // Don't count longer than 15 minutes. |
165 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
166 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
173 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
174 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
175 | + } |
|
167 | 176 | |
168 | 177 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
169 | 178 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
170 | 179 | |
171 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
172 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
180 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
181 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
182 | + } |
|
173 | 183 | |
174 | 184 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
175 | 185 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -206,8 +216,7 @@ discard block |
||
206 | 216 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
207 | 217 | // Copy the file back and run for your life! |
208 | 218 | @copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php'); |
209 | - } |
|
210 | - else |
|
219 | + } else |
|
211 | 220 | { |
212 | 221 | @touch($boarddir . '/' . 'Settings.php'); |
213 | 222 | return true; |
@@ -227,22 +236,27 @@ discard block |
||
227 | 236 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
228 | 237 | |
229 | 238 | // Add to Settings.php if you want to show the debugging information. |
230 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
231 | - return; |
|
239 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
240 | + return; |
|
241 | + } |
|
232 | 242 | |
233 | - if (empty($_SESSION['view_queries'])) |
|
234 | - $_SESSION['view_queries'] = 0; |
|
235 | - if (empty($context['debug']['language_files'])) |
|
236 | - $context['debug']['language_files'] = array(); |
|
237 | - if (empty($context['debug']['sheets'])) |
|
238 | - $context['debug']['sheets'] = array(); |
|
243 | + if (empty($_SESSION['view_queries'])) { |
|
244 | + $_SESSION['view_queries'] = 0; |
|
245 | + } |
|
246 | + if (empty($context['debug']['language_files'])) { |
|
247 | + $context['debug']['language_files'] = array(); |
|
248 | + } |
|
249 | + if (empty($context['debug']['sheets'])) { |
|
250 | + $context['debug']['sheets'] = array(); |
|
251 | + } |
|
239 | 252 | |
240 | 253 | $files = get_included_files(); |
241 | 254 | $total_size = 0; |
242 | 255 | for ($i = 0, $n = count($files); $i < $n; $i++) |
243 | 256 | { |
244 | - if (file_exists($files[$i])) |
|
245 | - $total_size += filesize($files[$i]); |
|
257 | + if (file_exists($files[$i])) { |
|
258 | + $total_size += filesize($files[$i]); |
|
259 | + } |
|
246 | 260 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
247 | 261 | } |
248 | 262 | |
@@ -251,8 +265,9 @@ discard block |
||
251 | 265 | { |
252 | 266 | foreach ($db_cache as $q => $qq) |
253 | 267 | { |
254 | - if (!empty($qq['w'])) |
|
255 | - $warnings += count($qq['w']); |
|
268 | + if (!empty($qq['w'])) { |
|
269 | + $warnings += count($qq['w']); |
|
270 | + } |
|
256 | 271 | } |
257 | 272 | |
258 | 273 | $_SESSION['debug'] = &$db_cache; |
@@ -273,12 +288,14 @@ discard block |
||
273 | 288 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
274 | 289 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
275 | 290 | |
276 | - if (function_exists('memory_get_peak_usage')) |
|
277 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
291 | + if (function_exists('memory_get_peak_usage')) { |
|
292 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
293 | + } |
|
278 | 294 | |
279 | 295 | // What tokens are active? |
280 | - if (isset($_SESSION['token'])) |
|
281 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
296 | + if (isset($_SESSION['token'])) { |
|
297 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
298 | + } |
|
282 | 299 | |
283 | 300 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
284 | 301 | { |
@@ -292,10 +309,12 @@ discard block |
||
292 | 309 | $total_t += $cache_hit['t']; |
293 | 310 | $total_s += $cache_hit['s']; |
294 | 311 | } |
295 | - if (!isset($cache_misses)) |
|
296 | - $cache_misses = array(); |
|
297 | - foreach ($cache_misses as $missed) |
|
298 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
312 | + if (!isset($cache_misses)) { |
|
313 | + $cache_misses = array(); |
|
314 | + } |
|
315 | + foreach ($cache_misses as $missed) { |
|
316 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
317 | + } |
|
299 | 318 | |
300 | 319 | echo ' |
301 | 320 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -306,38 +325,44 @@ discard block |
||
306 | 325 | <a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
307 | 326 | <br>'; |
308 | 327 | |
309 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
310 | - foreach ($db_cache as $q => $qq) |
|
328 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
329 | + foreach ($db_cache as $q => $qq) |
|
311 | 330 | { |
312 | 331 | $is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; |
332 | + } |
|
313 | 333 | // Temporary tables created in earlier queries are not explainable. |
314 | 334 | if ($is_select) |
315 | 335 | { |
316 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
317 | - if (strpos(trim($qq['q']), $tmp) !== false) |
|
336 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
337 | + if (strpos(trim($qq['q']), $tmp) !== false) |
|
318 | 338 | { |
319 | 339 | $is_select = false; |
340 | + } |
|
320 | 341 | break; |
321 | 342 | } |
322 | 343 | } |
323 | 344 | // But actual creation of the temporary tables are. |
324 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) |
|
325 | - $is_select = true; |
|
345 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) { |
|
346 | + $is_select = true; |
|
347 | + } |
|
326 | 348 | |
327 | 349 | // Make the filenames look a bit better. |
328 | - if (isset($qq['f'])) |
|
329 | - $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
350 | + if (isset($qq['f'])) { |
|
351 | + $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
352 | + } |
|
330 | 353 | |
331 | 354 | echo ' |
332 | 355 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
333 | 356 | '; |
334 | - if (!empty($qq['f']) && !empty($qq['l'])) |
|
335 | - echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
357 | + if (!empty($qq['f']) && !empty($qq['l'])) { |
|
358 | + echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
359 | + } |
|
336 | 360 | |
337 | - if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) |
|
338 | - echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
339 | - elseif (isset($qq['t'])) |
|
340 | - echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
361 | + if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) { |
|
362 | + echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
363 | + } elseif (isset($qq['t'])) { |
|
364 | + echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
365 | + } |
|
341 | 366 | echo ' |
342 | 367 | <br>'; |
343 | 368 | } |
@@ -362,12 +387,14 @@ discard block |
||
362 | 387 | global $modSettings, $smcFunc; |
363 | 388 | static $cache_stats = array(); |
364 | 389 | |
365 | - if (empty($modSettings['trackStats'])) |
|
366 | - return false; |
|
367 | - if (!empty($stats)) |
|
368 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
369 | - elseif (empty($cache_stats)) |
|
370 | - return false; |
|
390 | + if (empty($modSettings['trackStats'])) { |
|
391 | + return false; |
|
392 | + } |
|
393 | + if (!empty($stats)) { |
|
394 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
395 | + } elseif (empty($cache_stats)) { |
|
396 | + return false; |
|
397 | + } |
|
371 | 398 | |
372 | 399 | $setStringUpdate = ''; |
373 | 400 | $insert_keys = array(); |
@@ -380,10 +407,11 @@ discard block |
||
380 | 407 | $setStringUpdate .= ' |
381 | 408 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
382 | 409 | |
383 | - if ($change === '+') |
|
384 | - $cache_stats[$field] = 1; |
|
385 | - else |
|
386 | - $update_parameters[$field] = $change; |
|
410 | + if ($change === '+') { |
|
411 | + $cache_stats[$field] = 1; |
|
412 | + } else { |
|
413 | + $update_parameters[$field] = $change; |
|
414 | + } |
|
387 | 415 | $insert_keys[$field] = 'int'; |
388 | 416 | } |
389 | 417 | |
@@ -447,43 +475,50 @@ discard block |
||
447 | 475 | ); |
448 | 476 | |
449 | 477 | // Make sure this particular log is enabled first... |
450 | - if (empty($modSettings['modlog_enabled'])) |
|
451 | - unset ($log_types['moderate']); |
|
452 | - if (empty($modSettings['userlog_enabled'])) |
|
453 | - unset ($log_types['user']); |
|
454 | - if (empty($modSettings['adminlog_enabled'])) |
|
455 | - unset ($log_types['admin']); |
|
478 | + if (empty($modSettings['modlog_enabled'])) { |
|
479 | + unset ($log_types['moderate']); |
|
480 | + } |
|
481 | + if (empty($modSettings['userlog_enabled'])) { |
|
482 | + unset ($log_types['user']); |
|
483 | + } |
|
484 | + if (empty($modSettings['adminlog_enabled'])) { |
|
485 | + unset ($log_types['admin']); |
|
486 | + } |
|
456 | 487 | |
457 | 488 | call_integration_hook('integrate_log_types', array(&$log_types)); |
458 | 489 | |
459 | 490 | foreach ($logs as $log) |
460 | 491 | { |
461 | - if (!isset($log_types[$log['log_type']])) |
|
462 | - return false; |
|
492 | + if (!isset($log_types[$log['log_type']])) { |
|
493 | + return false; |
|
494 | + } |
|
463 | 495 | |
464 | - if (!is_array($log['extra'])) |
|
465 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
496 | + if (!is_array($log['extra'])) { |
|
497 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
498 | + } |
|
466 | 499 | |
467 | 500 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
468 | 501 | if (isset($log['extra']['topic'])) |
469 | 502 | { |
470 | - if (!is_numeric($log['extra']['topic'])) |
|
471 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
503 | + if (!is_numeric($log['extra']['topic'])) { |
|
504 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
505 | + } |
|
472 | 506 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
473 | 507 | unset($log['extra']['topic']); |
508 | + } else { |
|
509 | + $topic_id = 0; |
|
474 | 510 | } |
475 | - else |
|
476 | - $topic_id = 0; |
|
477 | 511 | |
478 | 512 | if (isset($log['extra']['message'])) |
479 | 513 | { |
480 | - if (!is_numeric($log['extra']['message'])) |
|
481 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
514 | + if (!is_numeric($log['extra']['message'])) { |
|
515 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
516 | + } |
|
482 | 517 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
483 | 518 | unset($log['extra']['message']); |
519 | + } else { |
|
520 | + $msg_id = 0; |
|
484 | 521 | } |
485 | - else |
|
486 | - $msg_id = 0; |
|
487 | 522 | |
488 | 523 | // @todo cache this? |
489 | 524 | // Is there an associated report on this? |
@@ -510,23 +545,26 @@ discard block |
||
510 | 545 | $smcFunc['db_free_result']($request); |
511 | 546 | } |
512 | 547 | |
513 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
514 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
548 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
549 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
550 | + } |
|
515 | 551 | |
516 | 552 | if (isset($log['extra']['board'])) |
517 | 553 | { |
518 | - if (!is_numeric($log['extra']['board'])) |
|
519 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
554 | + if (!is_numeric($log['extra']['board'])) { |
|
555 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
556 | + } |
|
520 | 557 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
521 | 558 | unset($log['extra']['board']); |
559 | + } else { |
|
560 | + $board_id = 0; |
|
522 | 561 | } |
523 | - else |
|
524 | - $board_id = 0; |
|
525 | 562 | |
526 | 563 | if (isset($log['extra']['board_to'])) |
527 | 564 | { |
528 | - if (!is_numeric($log['extra']['board_to'])) |
|
529 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
565 | + if (!is_numeric($log['extra']['board_to'])) { |
|
566 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
567 | + } |
|
530 | 568 | if (empty($board_id)) |
531 | 569 | { |
532 | 570 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -534,10 +572,11 @@ discard block |
||
534 | 572 | } |
535 | 573 | } |
536 | 574 | |
537 | - if (isset($log['extra']['member_affected'])) |
|
538 | - $memID = $log['extra']['member_affected']; |
|
539 | - else |
|
540 | - $memID = $user_info['id']; |
|
575 | + if (isset($log['extra']['member_affected'])) { |
|
576 | + $memID = $log['extra']['member_affected']; |
|
577 | + } else { |
|
578 | + $memID = $user_info['id']; |
|
579 | + } |
|
541 | 580 | |
542 | 581 | $inserts[] = array( |
543 | 582 | time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'], |