@@ -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; |
@@ -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 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param bool $single_file If true returns the contents of the file specified by destination if it exists |
29 | 29 | * @param bool $overwrite Whether to overwrite existing files |
30 | 30 | * @param null|array $files_to_extract Specific files to extract |
31 | - * @return array|false An array of information about extracted files or false on failure |
|
31 | + * @return string An array of information about extracted files or false on failure |
|
32 | 32 | */ |
33 | 33 | function read_tgz_file($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
34 | 34 | { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param bool $single_file Whether to only extract a single file |
60 | 60 | * @param bool $overwrite Whether to overwrite existing data |
61 | 61 | * @param null|array $files_to_extract If set, only extracts the specified files |
62 | - * @return array|false An array of information about the extracted files or false on failure |
|
62 | + * @return string An array of information about the extracted files or false on failure |
|
63 | 63 | */ |
64 | 64 | function read_tgz_data($gzfilename, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
65 | 65 | { |
@@ -3255,7 +3255,7 @@ discard block |
||
3255 | 3255 | * https://php.net/crc32#79567 |
3256 | 3256 | * |
3257 | 3257 | * @param string $number |
3258 | - * @return string The crc32 |
|
3258 | + * @return integer The crc32 |
|
3259 | 3259 | */ |
3260 | 3260 | function smf_crc32($number) |
3261 | 3261 | { |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | * @version 2.1 Beta 3 |
17 | 17 | */ |
18 | 18 | |
19 | -if (!defined('SMF')) |
|
19 | +if (!defined('SMF')) { |
|
20 | 20 | die('No direct access...'); |
21 | +} |
|
21 | 22 | |
22 | 23 | /** |
23 | 24 | * Reads a .tar.gz file, filename, in and extracts file(s) from it. |
@@ -67,47 +68,53 @@ discard block |
||
67 | 68 | loadLanguage('Packages'); |
68 | 69 | |
69 | 70 | // This function sorta needs gzinflate! |
70 | - if (!function_exists('gzinflate')) |
|
71 | - fatal_lang_error('package_no_zlib', 'critical'); |
|
71 | + if (!function_exists('gzinflate')) { |
|
72 | + fatal_lang_error('package_no_zlib', 'critical'); |
|
73 | + } |
|
72 | 74 | |
73 | 75 | if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://') |
74 | 76 | { |
75 | 77 | $data = fetch_web_data($gzfilename); |
76 | 78 | |
77 | - if ($data === false) |
|
78 | - return false; |
|
79 | - } |
|
80 | - else |
|
79 | + if ($data === false) { |
|
80 | + return false; |
|
81 | + } |
|
82 | + } else |
|
81 | 83 | { |
82 | 84 | $data = @file_get_contents($gzfilename); |
83 | 85 | |
84 | - if ($data === false) |
|
85 | - return false; |
|
86 | + if ($data === false) { |
|
87 | + return false; |
|
88 | + } |
|
86 | 89 | } |
87 | 90 | |
88 | 91 | umask(0); |
89 | - if (!$single_file && $destination !== null && !file_exists($destination)) |
|
90 | - mktree($destination, 0777); |
|
92 | + if (!$single_file && $destination !== null && !file_exists($destination)) { |
|
93 | + mktree($destination, 0777); |
|
94 | + } |
|
91 | 95 | |
92 | 96 | // No signature? |
93 | - if (strlen($data) < 2) |
|
94 | - return false; |
|
97 | + if (strlen($data) < 2) { |
|
98 | + return false; |
|
99 | + } |
|
95 | 100 | |
96 | 101 | $id = unpack('H2a/H2b', substr($data, 0, 2)); |
97 | 102 | if (strtolower($id['a'] . $id['b']) != '1f8b') |
98 | 103 | { |
99 | 104 | // Okay, this ain't no tar.gz, but maybe it's a zip file. |
100 | - if (substr($data, 0, 2) == 'PK') |
|
101 | - return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
102 | - else |
|
103 | - return false; |
|
105 | + if (substr($data, 0, 2) == 'PK') { |
|
106 | + return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
107 | + } else { |
|
108 | + return false; |
|
109 | + } |
|
104 | 110 | } |
105 | 111 | |
106 | 112 | $flags = unpack('Ct/Cf', substr($data, 2, 2)); |
107 | 113 | |
108 | 114 | // Not deflate! |
109 | - if ($flags['t'] != 8) |
|
110 | - return false; |
|
115 | + if ($flags['t'] != 8) { |
|
116 | + return false; |
|
117 | + } |
|
111 | 118 | $flags = $flags['f']; |
112 | 119 | |
113 | 120 | $offset = 10; |
@@ -117,18 +124,21 @@ discard block |
||
117 | 124 | // @todo Might be mussed. |
118 | 125 | if ($flags & 12) |
119 | 126 | { |
120 | - while ($flags & 8 && $data{$offset++} != "\0") |
|
121 | - continue; |
|
122 | - while ($flags & 4 && $data{$offset++} != "\0") |
|
123 | - continue; |
|
127 | + while ($flags & 8 && $data{$offset++} != "\0") { |
|
128 | + continue; |
|
129 | + } |
|
130 | + while ($flags & 4 && $data{$offset++} != "\0") { |
|
131 | + continue; |
|
132 | + } |
|
124 | 133 | } |
125 | 134 | |
126 | 135 | $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); |
127 | 136 | $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); |
128 | 137 | |
129 | 138 | // smf_crc32 and crc32 may not return the same results, so we accept either. |
130 | - if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) |
|
131 | - return false; |
|
139 | + if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) { |
|
140 | + return false; |
|
141 | + } |
|
132 | 142 | |
133 | 143 | $blocks = strlen($data) / 512 - 1; |
134 | 144 | $offset = 0; |
@@ -149,83 +159,98 @@ discard block |
||
149 | 159 | |
150 | 160 | foreach ($current as $k => $v) |
151 | 161 | { |
152 | - if (in_array($k, $octdec)) |
|
153 | - $current[$k] = octdec(trim($v)); |
|
154 | - else |
|
155 | - $current[$k] = trim($v); |
|
162 | + if (in_array($k, $octdec)) { |
|
163 | + $current[$k] = octdec(trim($v)); |
|
164 | + } else { |
|
165 | + $current[$k] = trim($v); |
|
166 | + } |
|
156 | 167 | } |
157 | 168 | |
158 | - if ($current['type'] == 5 && substr($current['filename'], -1) != '/') |
|
159 | - $current['filename'] .= '/'; |
|
169 | + if ($current['type'] == 5 && substr($current['filename'], -1) != '/') { |
|
170 | + $current['filename'] .= '/'; |
|
171 | + } |
|
160 | 172 | |
161 | 173 | $checksum = 256; |
162 | - for ($i = 0; $i < 148; $i++) |
|
163 | - $checksum += ord($header{$i}); |
|
164 | - for ($i = 156; $i < 512; $i++) |
|
165 | - $checksum += ord($header{$i}); |
|
174 | + for ($i = 0; $i < 148; $i++) { |
|
175 | + $checksum += ord($header{$i}); |
|
176 | + } |
|
177 | + for ($i = 156; $i < 512; $i++) { |
|
178 | + $checksum += ord($header{$i}); |
|
179 | + } |
|
166 | 180 | |
167 | - if ($current['checksum'] != $checksum) |
|
168 | - break; |
|
181 | + if ($current['checksum'] != $checksum) { |
|
182 | + break; |
|
183 | + } |
|
169 | 184 | |
170 | 185 | $size = ceil($current['size'] / 512); |
171 | 186 | $current['data'] = substr($data, ++$offset << 9, $current['size']); |
172 | 187 | $offset += $size; |
173 | 188 | |
174 | 189 | // Not a directory and doesn't exist already... |
175 | - if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) |
|
176 | - $write_this = true; |
|
190 | + if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) { |
|
191 | + $write_this = true; |
|
192 | + } |
|
177 | 193 | // File exists... check if it is newer. |
178 | - elseif (substr($current['filename'], -1, 1) != '/') |
|
179 | - $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
194 | + elseif (substr($current['filename'], -1, 1) != '/') { |
|
195 | + $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
196 | + } |
|
180 | 197 | // Folder... create. |
181 | 198 | elseif ($destination !== null && !$single_file) |
182 | 199 | { |
183 | 200 | // Protect from accidental parent directory writing... |
184 | 201 | $current['filename'] = strtr($current['filename'], array('../' => '', '/..' => '')); |
185 | 202 | |
186 | - if (!file_exists($destination . '/' . $current['filename'])) |
|
187 | - mktree($destination . '/' . $current['filename'], 0777); |
|
203 | + if (!file_exists($destination . '/' . $current['filename'])) { |
|
204 | + mktree($destination . '/' . $current['filename'], 0777); |
|
205 | + } |
|
188 | 206 | $write_this = false; |
207 | + } else { |
|
208 | + $write_this = false; |
|
189 | 209 | } |
190 | - else |
|
191 | - $write_this = false; |
|
192 | 210 | |
193 | 211 | if ($write_this && $destination !== null) |
194 | 212 | { |
195 | - if (strpos($current['filename'], '/') !== false && !$single_file) |
|
196 | - mktree($destination . '/' . dirname($current['filename']), 0777); |
|
213 | + if (strpos($current['filename'], '/') !== false && !$single_file) { |
|
214 | + mktree($destination . '/' . dirname($current['filename']), 0777); |
|
215 | + } |
|
197 | 216 | |
198 | 217 | // Is this the file we're looking for? |
199 | - if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) |
|
200 | - return $current['data']; |
|
218 | + if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) { |
|
219 | + return $current['data']; |
|
220 | + } |
|
201 | 221 | // If we're looking for another file, keep going. |
202 | - elseif ($single_file) |
|
203 | - continue; |
|
222 | + elseif ($single_file) { |
|
223 | + continue; |
|
224 | + } |
|
204 | 225 | // Looking for restricted files? |
205 | - elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) |
|
206 | - continue; |
|
226 | + elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { |
|
227 | + continue; |
|
228 | + } |
|
207 | 229 | |
208 | 230 | package_put_contents($destination . '/' . $current['filename'], $current['data']); |
209 | 231 | } |
210 | 232 | |
211 | - if (substr($current['filename'], -1, 1) != '/') |
|
212 | - $return[] = array( |
|
233 | + if (substr($current['filename'], -1, 1) != '/') { |
|
234 | + $return[] = array( |
|
213 | 235 | 'filename' => $current['filename'], |
214 | 236 | 'md5' => md5($current['data']), |
215 | 237 | 'preview' => substr($current['data'], 0, 100), |
216 | 238 | 'size' => $current['size'], |
217 | 239 | 'skipped' => false |
218 | 240 | ); |
241 | + } |
|
219 | 242 | } |
220 | 243 | |
221 | - if ($destination !== null && !$single_file) |
|
222 | - package_flush_cache(); |
|
244 | + if ($destination !== null && !$single_file) { |
|
245 | + package_flush_cache(); |
|
246 | + } |
|
223 | 247 | |
224 | - if ($single_file) |
|
225 | - return false; |
|
226 | - else |
|
227 | - return $return; |
|
228 | -} |
|
248 | + if ($single_file) { |
|
249 | + return false; |
|
250 | + } else { |
|
251 | + return $return; |
|
252 | + } |
|
253 | + } |
|
229 | 254 | |
230 | 255 | /** |
231 | 256 | * Extract zip data. A functional copy of {@list read_zip_data()}. |
@@ -254,65 +279,74 @@ discard block |
||
254 | 279 | { |
255 | 280 | $i = $iterator->getSubPathname(); |
256 | 281 | // If this is a file, and it doesn't exist.... happy days! |
257 | - if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) |
|
258 | - $write_this = true; |
|
282 | + if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) { |
|
283 | + $write_this = true; |
|
284 | + } |
|
259 | 285 | // If the file exists, we may not want to overwrite it. |
260 | - elseif (substr($i, -1) != '/') |
|
261 | - $write_this = $overwrite; |
|
262 | - else |
|
263 | - $write_this = false; |
|
286 | + elseif (substr($i, -1) != '/') { |
|
287 | + $write_this = $overwrite; |
|
288 | + } else { |
|
289 | + $write_this = false; |
|
290 | + } |
|
264 | 291 | |
265 | 292 | // Get the actual compressed data. |
266 | - if (!$file_info->isDir()) |
|
267 | - $file_data = file_get_contents($file_info); |
|
268 | - elseif ($destination !== null && !$single_file) |
|
293 | + if (!$file_info->isDir()) { |
|
294 | + $file_data = file_get_contents($file_info); |
|
295 | + } elseif ($destination !== null && !$single_file) |
|
269 | 296 | { |
270 | 297 | // Folder... create. |
271 | - if (!file_exists($destination . '/' . $i)) |
|
272 | - mktree($destination . '/' . $i, 0777); |
|
298 | + if (!file_exists($destination . '/' . $i)) { |
|
299 | + mktree($destination . '/' . $i, 0777); |
|
300 | + } |
|
273 | 301 | $file_data = null; |
302 | + } else { |
|
303 | + $file_data = null; |
|
274 | 304 | } |
275 | - else |
|
276 | - $file_data = null; |
|
277 | 305 | |
278 | 306 | // Okay! We can write this file, looks good from here... |
279 | 307 | if ($write_this && $destination !== null) |
280 | 308 | { |
281 | - if (!$single_file && !is_dir($destination . '/' . dirname($i))) |
|
282 | - mktree($destination . '/' . dirname($i), 0777); |
|
309 | + if (!$single_file && !is_dir($destination . '/' . dirname($i))) { |
|
310 | + mktree($destination . '/' . dirname($i), 0777); |
|
311 | + } |
|
283 | 312 | |
284 | 313 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
285 | - if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) |
|
286 | - return $file_data; |
|
314 | + if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) { |
|
315 | + return $file_data; |
|
316 | + } |
|
287 | 317 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
288 | - elseif ($single_file) |
|
289 | - continue; |
|
318 | + elseif ($single_file) { |
|
319 | + continue; |
|
320 | + } |
|
290 | 321 | // Don't really want this? |
291 | - elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) |
|
292 | - continue; |
|
322 | + elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) { |
|
323 | + continue; |
|
324 | + } |
|
293 | 325 | |
294 | 326 | package_put_contents($destination . '/' . $i, $file_data); |
295 | 327 | } |
296 | 328 | |
297 | - if (substr($i, -1, 1) != '/') |
|
298 | - $return[] = array( |
|
329 | + if (substr($i, -1, 1) != '/') { |
|
330 | + $return[] = array( |
|
299 | 331 | 'filename' => $i, |
300 | 332 | 'md5' => md5($file_data), |
301 | 333 | 'preview' => substr($file_data, 0, 100), |
302 | 334 | 'size' => strlen($file_data), |
303 | 335 | 'skipped' => false |
304 | 336 | ); |
337 | + } |
|
305 | 338 | } |
306 | 339 | |
307 | - if ($destination !== null && !$single_file) |
|
308 | - package_flush_cache(); |
|
340 | + if ($destination !== null && !$single_file) { |
|
341 | + package_flush_cache(); |
|
342 | + } |
|
309 | 343 | |
310 | - if ($single_file) |
|
311 | - return false; |
|
312 | - else |
|
313 | - return $return; |
|
314 | - } |
|
315 | - catch (Exception $e) |
|
344 | + if ($single_file) { |
|
345 | + return false; |
|
346 | + } else { |
|
347 | + return $return; |
|
348 | + } |
|
349 | + } catch (Exception $e) |
|
316 | 350 | { |
317 | 351 | return false; |
318 | 352 | } |
@@ -334,13 +368,15 @@ discard block |
||
334 | 368 | function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
335 | 369 | { |
336 | 370 | umask(0); |
337 | - if ($destination !== null && !file_exists($destination) && !$single_file) |
|
338 | - mktree($destination, 0777); |
|
371 | + if ($destination !== null && !file_exists($destination) && !$single_file) { |
|
372 | + mktree($destination, 0777); |
|
373 | + } |
|
339 | 374 | |
340 | 375 | // Look for the end of directory signature 0x06054b50 |
341 | 376 | $data_ecr = explode("\x50\x4b\x05\x06", $data); |
342 | - if (!isset($data_ecr[1])) |
|
343 | - return false; |
|
377 | + if (!isset($data_ecr[1])) { |
|
378 | + return false; |
|
379 | + } |
|
344 | 380 | |
345 | 381 | $return = array(); |
346 | 382 | |
@@ -355,8 +391,9 @@ discard block |
||
355 | 391 | array_shift($file_sections); |
356 | 392 | |
357 | 393 | // sections and count from the signature must match or the zip file is bad |
358 | - if (count($file_sections) != $zip_info['files']) |
|
359 | - return false; |
|
394 | + if (count($file_sections) != $zip_info['files']) { |
|
395 | + return false; |
|
396 | + } |
|
360 | 397 | |
361 | 398 | // go though each file in the archive |
362 | 399 | foreach ($file_sections as $data) |
@@ -378,68 +415,79 @@ discard block |
||
378 | 415 | } |
379 | 416 | |
380 | 417 | // If this is a file, and it doesn't exist.... happy days! |
381 | - if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) |
|
382 | - $write_this = true; |
|
418 | + if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) { |
|
419 | + $write_this = true; |
|
420 | + } |
|
383 | 421 | // If the file exists, we may not want to overwrite it. |
384 | - elseif (substr($file_info['filename'], -1) != '/') |
|
385 | - $write_this = $overwrite; |
|
422 | + elseif (substr($file_info['filename'], -1) != '/') { |
|
423 | + $write_this = $overwrite; |
|
424 | + } |
|
386 | 425 | // This is a directory, so we're gonna want to create it. (probably...) |
387 | 426 | elseif ($destination !== null && !$single_file) |
388 | 427 | { |
389 | 428 | // Just a little accident prevention, don't mind me. |
390 | 429 | $file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => '')); |
391 | 430 | |
392 | - if (!file_exists($destination . '/' . $file_info['filename'])) |
|
393 | - mktree($destination . '/' . $file_info['filename'], 0777); |
|
431 | + if (!file_exists($destination . '/' . $file_info['filename'])) { |
|
432 | + mktree($destination . '/' . $file_info['filename'], 0777); |
|
433 | + } |
|
394 | 434 | $write_this = false; |
435 | + } else { |
|
436 | + $write_this = false; |
|
395 | 437 | } |
396 | - else |
|
397 | - $write_this = false; |
|
398 | 438 | |
399 | 439 | // Get the actual compressed data. |
400 | 440 | $file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']); |
401 | 441 | |
402 | 442 | // Only inflate it if we need to ;) |
403 | - if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) |
|
404 | - $file_info['data'] = gzinflate($file_info['data']); |
|
443 | + if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) { |
|
444 | + $file_info['data'] = gzinflate($file_info['data']); |
|
445 | + } |
|
405 | 446 | |
406 | 447 | // Okay! We can write this file, looks good from here... |
407 | 448 | if ($write_this && $destination !== null) |
408 | 449 | { |
409 | - if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) |
|
410 | - mktree($file_info['dir'], 0777); |
|
450 | + if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) { |
|
451 | + mktree($file_info['dir'], 0777); |
|
452 | + } |
|
411 | 453 | |
412 | 454 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
413 | - if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) |
|
414 | - return $file_info['data']; |
|
455 | + if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) { |
|
456 | + return $file_info['data']; |
|
457 | + } |
|
415 | 458 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
416 | - elseif ($single_file) |
|
417 | - continue; |
|
459 | + elseif ($single_file) { |
|
460 | + continue; |
|
461 | + } |
|
418 | 462 | // Don't really want this? |
419 | - elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) |
|
420 | - continue; |
|
463 | + elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) { |
|
464 | + continue; |
|
465 | + } |
|
421 | 466 | |
422 | 467 | package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']); |
423 | 468 | } |
424 | 469 | |
425 | - if (substr($file_info['filename'], -1, 1) != '/') |
|
426 | - $return[] = array( |
|
470 | + if (substr($file_info['filename'], -1, 1) != '/') { |
|
471 | + $return[] = array( |
|
427 | 472 | 'filename' => $file_info['filename'], |
428 | 473 | 'md5' => md5($file_info['data']), |
429 | 474 | 'preview' => substr($file_info['data'], 0, 100), |
430 | 475 | 'size' => $file_info['size'], |
431 | 476 | 'skipped' => false |
432 | 477 | ); |
478 | + } |
|
433 | 479 | } |
434 | 480 | |
435 | - if ($destination !== null && !$single_file) |
|
436 | - package_flush_cache(); |
|
481 | + if ($destination !== null && !$single_file) { |
|
482 | + package_flush_cache(); |
|
483 | + } |
|
437 | 484 | |
438 | - if ($single_file) |
|
439 | - return false; |
|
440 | - else |
|
441 | - return $return; |
|
442 | -} |
|
485 | + if ($single_file) { |
|
486 | + return false; |
|
487 | + } else { |
|
488 | + return $return; |
|
489 | + } |
|
490 | + } |
|
443 | 491 | |
444 | 492 | /** |
445 | 493 | * Checks the existence of a remote file since file_exists() does not do remote. |
@@ -451,14 +499,16 @@ discard block |
||
451 | 499 | { |
452 | 500 | $a_url = parse_url($url); |
453 | 501 | |
454 | - if (!isset($a_url['scheme'])) |
|
455 | - return false; |
|
502 | + if (!isset($a_url['scheme'])) { |
|
503 | + return false; |
|
504 | + } |
|
456 | 505 | |
457 | 506 | // Attempt to connect... |
458 | 507 | $temp = ''; |
459 | 508 | $fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8); |
460 | - if (!$fid) |
|
461 | - return false; |
|
509 | + if (!$fid) { |
|
510 | + return false; |
|
511 | + } |
|
462 | 512 | |
463 | 513 | fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n"); |
464 | 514 | $head = fread($fid, 1024); |
@@ -493,8 +543,9 @@ discard block |
||
493 | 543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
494 | 544 | { |
495 | 545 | // Already found this? If so don't add it twice! |
496 | - if (in_array($row['package_id'], $found)) |
|
497 | - continue; |
|
546 | + if (in_array($row['package_id'], $found)) { |
|
547 | + continue; |
|
548 | + } |
|
498 | 549 | |
499 | 550 | $found[] = $row['package_id']; |
500 | 551 | |
@@ -529,19 +580,21 @@ discard block |
||
529 | 580 | global $sourcedir, $packagesdir; |
530 | 581 | |
531 | 582 | // Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.) |
532 | - if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) |
|
533 | - $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
534 | - else |
|
583 | + if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) { |
|
584 | + $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
585 | + } else |
|
535 | 586 | { |
536 | - if (!file_exists($packagesdir . '/' . $gzfilename)) |
|
537 | - return 'package_get_error_not_found'; |
|
587 | + if (!file_exists($packagesdir . '/' . $gzfilename)) { |
|
588 | + return 'package_get_error_not_found'; |
|
589 | + } |
|
538 | 590 | |
539 | - if (is_file($packagesdir . '/' . $gzfilename)) |
|
540 | - $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
541 | - elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) |
|
542 | - $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
543 | - else |
|
544 | - return 'package_get_error_missing_xml'; |
|
591 | + if (is_file($packagesdir . '/' . $gzfilename)) { |
|
592 | + $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
593 | + } elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) { |
|
594 | + $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
595 | + } else { |
|
596 | + return 'package_get_error_missing_xml'; |
|
597 | + } |
|
545 | 598 | } |
546 | 599 | |
547 | 600 | // Nothing? |
@@ -549,10 +602,11 @@ discard block |
||
549 | 602 | { |
550 | 603 | // Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function |
551 | 604 | $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true); |
552 | - if (!empty($packageInfo)) |
|
553 | - return 'package_get_error_is_theme'; |
|
554 | - else |
|
555 | - return 'package_get_error_is_zero'; |
|
605 | + if (!empty($packageInfo)) { |
|
606 | + return 'package_get_error_is_theme'; |
|
607 | + } else { |
|
608 | + return 'package_get_error_is_zero'; |
|
609 | + } |
|
556 | 610 | } |
557 | 611 | |
558 | 612 | // Parse package-info.xml into an xmlArray. |
@@ -560,8 +614,9 @@ discard block |
||
560 | 614 | $packageInfo = new xmlArray($packageInfo); |
561 | 615 | |
562 | 616 | // @todo Error message of some sort? |
563 | - if (!$packageInfo->exists('package-info[0]')) |
|
564 | - return 'package_get_error_packageinfo_corrupt'; |
|
617 | + if (!$packageInfo->exists('package-info[0]')) { |
|
618 | + return 'package_get_error_packageinfo_corrupt'; |
|
619 | + } |
|
565 | 620 | |
566 | 621 | $packageInfo = $packageInfo->path('package-info[0]'); |
567 | 622 | |
@@ -580,8 +635,9 @@ discard block |
||
580 | 635 | } |
581 | 636 | } |
582 | 637 | |
583 | - if (!isset($package['type'])) |
|
584 | - $package['type'] = 'modification'; |
|
638 | + if (!isset($package['type'])) { |
|
639 | + $package['type'] = 'modification'; |
|
640 | + } |
|
585 | 641 | |
586 | 642 | return $package; |
587 | 643 | } |
@@ -634,15 +690,14 @@ discard block |
||
634 | 690 | { |
635 | 691 | $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => '')); |
636 | 692 | $package_ftp->chmod($ftp_file, $perms); |
693 | + } else { |
|
694 | + smf_chmod($file, $perms); |
|
637 | 695 | } |
638 | - else |
|
639 | - smf_chmod($file, $perms); |
|
640 | 696 | |
641 | 697 | $new_permissions = @fileperms($file); |
642 | 698 | $result = $new_permissions == $perms ? 'success' : 'failure'; |
643 | 699 | unset($_SESSION['pack_ftp']['original_perms'][$file]); |
644 | - } |
|
645 | - elseif ($do_change) |
|
700 | + } elseif ($do_change) |
|
646 | 701 | { |
647 | 702 | $new_permissions = ''; |
648 | 703 | $result = 'skipped'; |
@@ -758,8 +813,7 @@ discard block |
||
758 | 813 | |
759 | 814 | $context['sub_template'] = 'show_list'; |
760 | 815 | $context['default_list'] = 'restore_file_permissions'; |
761 | - } |
|
762 | - else |
|
816 | + } else |
|
763 | 817 | { |
764 | 818 | unset($listOptions['columns']['result']); |
765 | 819 | } |
@@ -769,12 +823,14 @@ discard block |
||
769 | 823 | createList($listOptions); |
770 | 824 | |
771 | 825 | // If we just restored permissions then whereever we are, we are now done and dusted. |
772 | - if (!empty($_POST['restore_perms'])) |
|
773 | - obExit(); |
|
826 | + if (!empty($_POST['restore_perms'])) { |
|
827 | + obExit(); |
|
828 | + } |
|
774 | 829 | } |
775 | 830 | // Otherwise, it's entirely irrelevant? |
776 | - elseif ($restore_write_status) |
|
777 | - return true; |
|
831 | + elseif ($restore_write_status) { |
|
832 | + return true; |
|
833 | + } |
|
778 | 834 | |
779 | 835 | // This is where we report what we got up to. |
780 | 836 | $return_data = array( |
@@ -812,11 +868,12 @@ discard block |
||
812 | 868 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
813 | 869 | { |
814 | 870 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
815 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) |
|
816 | - $ftp_root = substr($ftp_root, 0, -1); |
|
871 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) { |
|
872 | + $ftp_root = substr($ftp_root, 0, -1); |
|
873 | + } |
|
874 | + } else { |
|
875 | + $ftp_root = $boarddir; |
|
817 | 876 | } |
818 | - else |
|
819 | - $ftp_root = $boarddir; |
|
820 | 877 | |
821 | 878 | $_SESSION['pack_ftp'] = array( |
822 | 879 | 'server' => $_POST['ftp_server'], |
@@ -828,8 +885,9 @@ discard block |
||
828 | 885 | 'connected' => true, |
829 | 886 | ); |
830 | 887 | |
831 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
832 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
888 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
889 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
890 | + } |
|
833 | 891 | |
834 | 892 | // This is now the primary connection. |
835 | 893 | $package_ftp = $ftp; |
@@ -842,12 +900,13 @@ discard block |
||
842 | 900 | foreach ($chmodFiles as $k => $file) |
843 | 901 | { |
844 | 902 | // Sometimes this can somehow happen maybe? |
845 | - if (empty($file)) |
|
846 | - unset($chmodFiles[$k]); |
|
903 | + if (empty($file)) { |
|
904 | + unset($chmodFiles[$k]); |
|
905 | + } |
|
847 | 906 | // Already writable? |
848 | - elseif (@is_writable($file)) |
|
849 | - $return_data['files']['writable'][] = $file; |
|
850 | - else |
|
907 | + elseif (@is_writable($file)) { |
|
908 | + $return_data['files']['writable'][] = $file; |
|
909 | + } else |
|
851 | 910 | { |
852 | 911 | // Now try to change that. |
853 | 912 | $return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file; |
@@ -864,19 +923,21 @@ discard block |
||
864 | 923 | { |
865 | 924 | require_once($sourcedir . '/Class-Package.php'); |
866 | 925 | $ftp = new ftp_connection(null); |
926 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
927 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
867 | 928 | } |
868 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
869 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
870 | 929 | |
871 | 930 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
872 | 931 | |
873 | - if ($found_path) |
|
874 | - $_POST['ftp_path'] = $detect_path; |
|
875 | - elseif (!isset($_POST['ftp_path'])) |
|
876 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
932 | + if ($found_path) { |
|
933 | + $_POST['ftp_path'] = $detect_path; |
|
934 | + } elseif (!isset($_POST['ftp_path'])) { |
|
935 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
936 | + } |
|
877 | 937 | |
878 | - if (!isset($_POST['ftp_username'])) |
|
879 | - $_POST['ftp_username'] = $username; |
|
938 | + if (!isset($_POST['ftp_username'])) { |
|
939 | + $_POST['ftp_username'] = $username; |
|
940 | + } |
|
880 | 941 | } |
881 | 942 | |
882 | 943 | $context['package_ftp'] = array( |
@@ -889,8 +950,9 @@ discard block |
||
889 | 950 | ); |
890 | 951 | |
891 | 952 | // Which files failed? |
892 | - if (!isset($context['notwritable_files'])) |
|
893 | - $context['notwritable_files'] = array(); |
|
953 | + if (!isset($context['notwritable_files'])) { |
|
954 | + $context['notwritable_files'] = array(); |
|
955 | + } |
|
894 | 956 | $context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']); |
895 | 957 | |
896 | 958 | // Sent here to die? |
@@ -923,40 +985,48 @@ discard block |
||
923 | 985 | foreach ($files as $k => $file) |
924 | 986 | { |
925 | 987 | // If this file doesn't exist, then we actually want to look at the directory, no? |
926 | - if (!file_exists($file)) |
|
927 | - $file = dirname($file); |
|
988 | + if (!file_exists($file)) { |
|
989 | + $file = dirname($file); |
|
990 | + } |
|
928 | 991 | |
929 | 992 | // This looks odd, but it's an attempt to work around PHP suExec. |
930 | - if (!@is_writable($file)) |
|
931 | - smf_chmod($file, 0755); |
|
932 | - if (!@is_writable($file)) |
|
933 | - smf_chmod($file, 0777); |
|
934 | - if (!@is_writable(dirname($file))) |
|
935 | - smf_chmod($file, 0755); |
|
936 | - if (!@is_writable(dirname($file))) |
|
937 | - smf_chmod($file, 0777); |
|
993 | + if (!@is_writable($file)) { |
|
994 | + smf_chmod($file, 0755); |
|
995 | + } |
|
996 | + if (!@is_writable($file)) { |
|
997 | + smf_chmod($file, 0777); |
|
998 | + } |
|
999 | + if (!@is_writable(dirname($file))) { |
|
1000 | + smf_chmod($file, 0755); |
|
1001 | + } |
|
1002 | + if (!@is_writable(dirname($file))) { |
|
1003 | + smf_chmod($file, 0777); |
|
1004 | + } |
|
938 | 1005 | |
939 | 1006 | $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb'); |
940 | 1007 | if (@is_writable($file) && $fp) |
941 | 1008 | { |
942 | 1009 | unset($files[$k]); |
943 | - if (!is_dir($file)) |
|
944 | - fclose($fp); |
|
945 | - else |
|
946 | - closedir($fp); |
|
1010 | + if (!is_dir($file)) { |
|
1011 | + fclose($fp); |
|
1012 | + } else { |
|
1013 | + closedir($fp); |
|
1014 | + } |
|
947 | 1015 | } |
948 | 1016 | } |
949 | 1017 | |
950 | 1018 | // No FTP required! |
951 | - if (empty($files)) |
|
952 | - return array(); |
|
1019 | + if (empty($files)) { |
|
1020 | + return array(); |
|
1021 | + } |
|
953 | 1022 | } |
954 | 1023 | |
955 | 1024 | // They've opted to not use FTP, and try anyway. |
956 | 1025 | if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) |
957 | 1026 | { |
958 | - if ($files === null) |
|
959 | - return array(); |
|
1027 | + if ($files === null) { |
|
1028 | + return array(); |
|
1029 | + } |
|
960 | 1030 | |
961 | 1031 | foreach ($files as $k => $file) |
962 | 1032 | { |
@@ -968,26 +1038,29 @@ discard block |
||
968 | 1038 | smf_chmod($file, 0755); |
969 | 1039 | } |
970 | 1040 | |
971 | - if (!@is_writable($file)) |
|
972 | - smf_chmod($file, 0777); |
|
973 | - if (!@is_writable(dirname($file))) |
|
974 | - smf_chmod(dirname($file), 0777); |
|
1041 | + if (!@is_writable($file)) { |
|
1042 | + smf_chmod($file, 0777); |
|
1043 | + } |
|
1044 | + if (!@is_writable(dirname($file))) { |
|
1045 | + smf_chmod(dirname($file), 0777); |
|
1046 | + } |
|
975 | 1047 | |
976 | - if (@is_writable($file)) |
|
977 | - unset($files[$k]); |
|
1048 | + if (@is_writable($file)) { |
|
1049 | + unset($files[$k]); |
|
1050 | + } |
|
978 | 1051 | } |
979 | 1052 | |
980 | 1053 | return $files; |
981 | - } |
|
982 | - elseif (isset($_SESSION['pack_ftp'])) |
|
1054 | + } elseif (isset($_SESSION['pack_ftp'])) |
|
983 | 1055 | { |
984 | 1056 | // Load the file containing the ftp_connection class. |
985 | 1057 | require_once($sourcedir . '/Class-Package.php'); |
986 | 1058 | |
987 | 1059 | $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password'])); |
988 | 1060 | |
989 | - if ($files === null) |
|
990 | - return array(); |
|
1061 | + if ($files === null) { |
|
1062 | + return array(); |
|
1063 | + } |
|
991 | 1064 | |
992 | 1065 | foreach ($files as $k => $file) |
993 | 1066 | { |
@@ -1001,13 +1074,16 @@ discard block |
||
1001 | 1074 | $package_ftp->chmod($ftp_file, 0755); |
1002 | 1075 | } |
1003 | 1076 | |
1004 | - if (!@is_writable($file)) |
|
1005 | - $package_ftp->chmod($ftp_file, 0777); |
|
1006 | - if (!@is_writable(dirname($file))) |
|
1007 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
1077 | + if (!@is_writable($file)) { |
|
1078 | + $package_ftp->chmod($ftp_file, 0777); |
|
1079 | + } |
|
1080 | + if (!@is_writable(dirname($file))) { |
|
1081 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
1082 | + } |
|
1008 | 1083 | |
1009 | - if (@is_writable($file)) |
|
1010 | - unset($files[$k]); |
|
1084 | + if (@is_writable($file)) { |
|
1085 | + unset($files[$k]); |
|
1086 | + } |
|
1011 | 1087 | } |
1012 | 1088 | |
1013 | 1089 | return $files; |
@@ -1019,8 +1095,7 @@ discard block |
||
1019 | 1095 | |
1020 | 1096 | $files = packageRequireFTP($destination_url, $files, $return); |
1021 | 1097 | return $files; |
1022 | - } |
|
1023 | - elseif (isset($_POST['ftp_username'])) |
|
1098 | + } elseif (isset($_POST['ftp_username'])) |
|
1024 | 1099 | { |
1025 | 1100 | require_once($sourcedir . '/Class-Package.php'); |
1026 | 1101 | $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); |
@@ -1042,19 +1117,21 @@ discard block |
||
1042 | 1117 | { |
1043 | 1118 | require_once($sourcedir . '/Class-Package.php'); |
1044 | 1119 | $ftp = new ftp_connection(null); |
1120 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
1121 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
1045 | 1122 | } |
1046 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
1047 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
1048 | 1123 | |
1049 | 1124 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
1050 | 1125 | |
1051 | - if ($found_path) |
|
1052 | - $_POST['ftp_path'] = $detect_path; |
|
1053 | - elseif (!isset($_POST['ftp_path'])) |
|
1054 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
1126 | + if ($found_path) { |
|
1127 | + $_POST['ftp_path'] = $detect_path; |
|
1128 | + } elseif (!isset($_POST['ftp_path'])) { |
|
1129 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
1130 | + } |
|
1055 | 1131 | |
1056 | - if (!isset($_POST['ftp_username'])) |
|
1057 | - $_POST['ftp_username'] = $username; |
|
1132 | + if (!isset($_POST['ftp_username'])) { |
|
1133 | + $_POST['ftp_username'] = $username; |
|
1134 | + } |
|
1058 | 1135 | |
1059 | 1136 | $context['package_ftp'] = array( |
1060 | 1137 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -1066,23 +1143,24 @@ discard block |
||
1066 | 1143 | ); |
1067 | 1144 | |
1068 | 1145 | // If we're returning dump out here. |
1069 | - if ($return) |
|
1070 | - return $files; |
|
1146 | + if ($return) { |
|
1147 | + return $files; |
|
1148 | + } |
|
1071 | 1149 | |
1072 | 1150 | $context['page_title'] = $txt['package_ftp_necessary']; |
1073 | 1151 | $context['sub_template'] = 'ftp_required'; |
1074 | 1152 | obExit(); |
1075 | - } |
|
1076 | - else |
|
1153 | + } else |
|
1077 | 1154 | { |
1078 | 1155 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
1079 | 1156 | { |
1080 | 1157 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
1081 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) |
|
1082 | - $ftp_root = substr($ftp_root, 0, -1); |
|
1158 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { |
|
1159 | + $ftp_root = substr($ftp_root, 0, -1); |
|
1160 | + } |
|
1161 | + } else { |
|
1162 | + $ftp_root = $boarddir; |
|
1083 | 1163 | } |
1084 | - else |
|
1085 | - $ftp_root = $boarddir; |
|
1086 | 1164 | |
1087 | 1165 | $_SESSION['pack_ftp'] = array( |
1088 | 1166 | 'server' => $_POST['ftp_server'], |
@@ -1093,8 +1171,9 @@ discard block |
||
1093 | 1171 | 'root' => $ftp_root, |
1094 | 1172 | ); |
1095 | 1173 | |
1096 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
1097 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
1174 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
1175 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
1176 | + } |
|
1098 | 1177 | |
1099 | 1178 | $files = packageRequireFTP($destination_url, $files, $return); |
1100 | 1179 | } |
@@ -1122,16 +1201,18 @@ discard block |
||
1122 | 1201 | global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc; |
1123 | 1202 | |
1124 | 1203 | // Mayday! That action doesn't exist!! |
1125 | - if (empty($packageXML) || !$packageXML->exists($method)) |
|
1126 | - return array(); |
|
1204 | + if (empty($packageXML) || !$packageXML->exists($method)) { |
|
1205 | + return array(); |
|
1206 | + } |
|
1127 | 1207 | |
1128 | 1208 | // We haven't found the package script yet... |
1129 | 1209 | $script = false; |
1130 | 1210 | $the_version = strtr($forum_version, array('SMF ' => '')); |
1131 | 1211 | |
1132 | 1212 | // Emulation support... |
1133 | - if (!empty($_SESSION['version_emulate'])) |
|
1134 | - $the_version = $_SESSION['version_emulate']; |
|
1213 | + if (!empty($_SESSION['version_emulate'])) { |
|
1214 | + $the_version = $_SESSION['version_emulate']; |
|
1215 | + } |
|
1135 | 1216 | |
1136 | 1217 | // Single package emulation |
1137 | 1218 | if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package'])) |
@@ -1139,8 +1220,9 @@ discard block |
||
1139 | 1220 | $the_version = $_REQUEST['ve']; |
1140 | 1221 | $_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version; |
1141 | 1222 | } |
1142 | - if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) |
|
1143 | - $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
1223 | + if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) { |
|
1224 | + $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
1225 | + } |
|
1144 | 1226 | |
1145 | 1227 | // Get all the versions of this method and find the right one. |
1146 | 1228 | $these_methods = $packageXML->set($method); |
@@ -1150,16 +1232,18 @@ discard block |
||
1150 | 1232 | if ($this_method->exists('@for')) |
1151 | 1233 | { |
1152 | 1234 | // Don't keep going if this won't work for this version of SMF. |
1153 | - if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) |
|
1154 | - continue; |
|
1235 | + if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) { |
|
1236 | + continue; |
|
1237 | + } |
|
1155 | 1238 | } |
1156 | 1239 | |
1157 | 1240 | // Upgrades may go from a certain old version of the mod. |
1158 | 1241 | if ($method == 'upgrade' && $this_method->exists('@from')) |
1159 | 1242 | { |
1160 | 1243 | // Well, this is for the wrong old version... |
1161 | - if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) |
|
1162 | - continue; |
|
1244 | + if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) { |
|
1245 | + continue; |
|
1246 | + } |
|
1163 | 1247 | } |
1164 | 1248 | |
1165 | 1249 | // We've found it! |
@@ -1168,8 +1252,9 @@ discard block |
||
1168 | 1252 | } |
1169 | 1253 | |
1170 | 1254 | // Bad news, a matching script wasn't found! |
1171 | - if (!($script instanceof xmlArray)) |
|
1172 | - return array(); |
|
1255 | + if (!($script instanceof xmlArray)) { |
|
1256 | + return array(); |
|
1257 | + } |
|
1173 | 1258 | |
1174 | 1259 | // Find all the actions in this method - in theory, these should only be allowed actions. (* means all.) |
1175 | 1260 | $actions = $script->set('*'); |
@@ -1198,12 +1283,12 @@ discard block |
||
1198 | 1283 | if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
1199 | 1284 | { |
1200 | 1285 | // In case the user put the blocks in the wrong order. |
1201 | - if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
|
1202 | - $context[$type][] = 'default'; |
|
1286 | + if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') { |
|
1287 | + $context[$type][] = 'default'; |
|
1288 | + } |
|
1203 | 1289 | |
1204 | 1290 | $context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
1205 | - } |
|
1206 | - else |
|
1291 | + } else |
|
1207 | 1292 | { |
1208 | 1293 | // We don't want this now, but we'll allow the user to select to read it. |
1209 | 1294 | $context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
@@ -1218,9 +1303,9 @@ discard block |
||
1218 | 1303 | { |
1219 | 1304 | $context[$type][] = 'default'; |
1220 | 1305 | continue; |
1306 | + } else { |
|
1307 | + $context[$type]['selected'] = 'default'; |
|
1221 | 1308 | } |
1222 | - else |
|
1223 | - $context[$type]['selected'] = 'default'; |
|
1224 | 1309 | } |
1225 | 1310 | } |
1226 | 1311 | |
@@ -1230,9 +1315,9 @@ discard block |
||
1230 | 1315 | $filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); |
1231 | 1316 | package_put_contents($filename, $action->fetch('.')); |
1232 | 1317 | $filename = strtr($filename, array($temp_path => '')); |
1318 | + } else { |
|
1319 | + $filename = $action->fetch('.'); |
|
1233 | 1320 | } |
1234 | - else |
|
1235 | - $filename = $action->fetch('.'); |
|
1236 | 1321 | |
1237 | 1322 | $return[] = array( |
1238 | 1323 | 'type' => $actionType, |
@@ -1247,8 +1332,7 @@ discard block |
||
1247 | 1332 | ); |
1248 | 1333 | |
1249 | 1334 | continue; |
1250 | - } |
|
1251 | - elseif ($actionType == 'hook') |
|
1335 | + } elseif ($actionType == 'hook') |
|
1252 | 1336 | { |
1253 | 1337 | $return[] = array( |
1254 | 1338 | 'type' => $actionType, |
@@ -1260,16 +1344,16 @@ discard block |
||
1260 | 1344 | 'description' => '', |
1261 | 1345 | ); |
1262 | 1346 | continue; |
1263 | - } |
|
1264 | - elseif ($actionType == 'credits') |
|
1347 | + } elseif ($actionType == 'credits') |
|
1265 | 1348 | { |
1266 | 1349 | // quick check of any supplied url |
1267 | 1350 | $url = $action->exists('@url') ? $action->fetch('@url') : ''; |
1268 | 1351 | if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://') |
1269 | 1352 | { |
1270 | 1353 | $url = 'http://' . $url; |
1271 | - if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) |
|
1272 | - $url = ''; |
|
1354 | + if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) { |
|
1355 | + $url = ''; |
|
1356 | + } |
|
1273 | 1357 | } |
1274 | 1358 | |
1275 | 1359 | $return[] = array( |
@@ -1281,8 +1365,7 @@ discard block |
||
1281 | 1365 | 'title' => $action->fetch('.'), |
1282 | 1366 | ); |
1283 | 1367 | continue; |
1284 | - } |
|
1285 | - elseif ($actionType == 'requires') |
|
1368 | + } elseif ($actionType == 'requires') |
|
1286 | 1369 | { |
1287 | 1370 | $return[] = array( |
1288 | 1371 | 'type' => $actionType, |
@@ -1291,14 +1374,12 @@ discard block |
||
1291 | 1374 | 'description' => '', |
1292 | 1375 | ); |
1293 | 1376 | continue; |
1294 | - } |
|
1295 | - elseif ($actionType == 'error') |
|
1377 | + } elseif ($actionType == 'error') |
|
1296 | 1378 | { |
1297 | 1379 | $return[] = array( |
1298 | 1380 | 'type' => 'error', |
1299 | 1381 | ); |
1300 | - } |
|
1301 | - elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
1382 | + } elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
1302 | 1383 | { |
1303 | 1384 | $this_action = &$return[]; |
1304 | 1385 | $this_action = array( |
@@ -1312,8 +1393,7 @@ discard block |
||
1312 | 1393 | { |
1313 | 1394 | $this_action['unparsed_destination'] = $action->fetch('@destination'); |
1314 | 1395 | $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); |
1315 | - } |
|
1316 | - else |
|
1396 | + } else |
|
1317 | 1397 | { |
1318 | 1398 | $this_action['unparsed_filename'] = $this_action['filename']; |
1319 | 1399 | $this_action['filename'] = parse_path($this_action['filename']); |
@@ -1322,10 +1402,11 @@ discard block |
||
1322 | 1402 | // If we're moving or requiring (copying) a file. |
1323 | 1403 | if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') |
1324 | 1404 | { |
1325 | - if ($action->exists('@from')) |
|
1326 | - $this_action['source'] = parse_path($action->fetch('@from')); |
|
1327 | - else |
|
1328 | - $this_action['source'] = $temp_path . $this_action['filename']; |
|
1405 | + if ($action->exists('@from')) { |
|
1406 | + $this_action['source'] = parse_path($action->fetch('@from')); |
|
1407 | + } else { |
|
1408 | + $this_action['source'] = $temp_path . $this_action['filename']; |
|
1409 | + } |
|
1329 | 1410 | } |
1330 | 1411 | |
1331 | 1412 | // Check if these things can be done. (chmod's etc.) |
@@ -1334,22 +1415,23 @@ discard block |
||
1334 | 1415 | if (!mktree($this_action['destination'], false)) |
1335 | 1416 | { |
1336 | 1417 | $temp = $this_action['destination']; |
1337 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
1338 | - $temp = dirname($temp); |
|
1418 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
1419 | + $temp = dirname($temp); |
|
1420 | + } |
|
1339 | 1421 | |
1340 | 1422 | $return[] = array( |
1341 | 1423 | 'type' => 'chmod', |
1342 | 1424 | 'filename' => $temp |
1343 | 1425 | ); |
1344 | 1426 | } |
1345 | - } |
|
1346 | - elseif ($actionType == 'create-file') |
|
1427 | + } elseif ($actionType == 'create-file') |
|
1347 | 1428 | { |
1348 | 1429 | if (!mktree(dirname($this_action['destination']), false)) |
1349 | 1430 | { |
1350 | 1431 | $temp = dirname($this_action['destination']); |
1351 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
1352 | - $temp = dirname($temp); |
|
1432 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
1433 | + $temp = dirname($temp); |
|
1434 | + } |
|
1353 | 1435 | |
1354 | 1436 | $return[] = array( |
1355 | 1437 | 'type' => 'chmod', |
@@ -1357,36 +1439,38 @@ discard block |
||
1357 | 1439 | ); |
1358 | 1440 | } |
1359 | 1441 | |
1360 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
1361 | - $return[] = array( |
|
1442 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
1443 | + $return[] = array( |
|
1362 | 1444 | 'type' => 'chmod', |
1363 | 1445 | 'filename' => $this_action['destination'] |
1364 | 1446 | ); |
1365 | - } |
|
1366 | - elseif ($actionType == 'require-dir') |
|
1447 | + } |
|
1448 | + } elseif ($actionType == 'require-dir') |
|
1367 | 1449 | { |
1368 | 1450 | if (!mktree($this_action['destination'], false)) |
1369 | 1451 | { |
1370 | 1452 | $temp = $this_action['destination']; |
1371 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
1372 | - $temp = dirname($temp); |
|
1453 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
1454 | + $temp = dirname($temp); |
|
1455 | + } |
|
1373 | 1456 | |
1374 | 1457 | $return[] = array( |
1375 | 1458 | 'type' => 'chmod', |
1376 | 1459 | 'filename' => $temp |
1377 | 1460 | ); |
1378 | 1461 | } |
1379 | - } |
|
1380 | - elseif ($actionType == 'require-file') |
|
1462 | + } elseif ($actionType == 'require-file') |
|
1381 | 1463 | { |
1382 | - if ($action->exists('@theme')) |
|
1383 | - $this_action['theme_action'] = $action->fetch('@theme'); |
|
1464 | + if ($action->exists('@theme')) { |
|
1465 | + $this_action['theme_action'] = $action->fetch('@theme'); |
|
1466 | + } |
|
1384 | 1467 | |
1385 | 1468 | if (!mktree(dirname($this_action['destination']), false)) |
1386 | 1469 | { |
1387 | 1470 | $temp = dirname($this_action['destination']); |
1388 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
1389 | - $temp = dirname($temp); |
|
1471 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
1472 | + $temp = dirname($temp); |
|
1473 | + } |
|
1390 | 1474 | |
1391 | 1475 | $return[] = array( |
1392 | 1476 | 'type' => 'chmod', |
@@ -1394,19 +1478,20 @@ discard block |
||
1394 | 1478 | ); |
1395 | 1479 | } |
1396 | 1480 | |
1397 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
1398 | - $return[] = array( |
|
1481 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
1482 | + $return[] = array( |
|
1399 | 1483 | 'type' => 'chmod', |
1400 | 1484 | 'filename' => $this_action['destination'] |
1401 | 1485 | ); |
1402 | - } |
|
1403 | - elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
1486 | + } |
|
1487 | + } elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
1404 | 1488 | { |
1405 | 1489 | if (!mktree(dirname($this_action['destination']), false)) |
1406 | 1490 | { |
1407 | 1491 | $temp = dirname($this_action['destination']); |
1408 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
1409 | - $temp = dirname($temp); |
|
1492 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
1493 | + $temp = dirname($temp); |
|
1494 | + } |
|
1410 | 1495 | |
1411 | 1496 | $return[] = array( |
1412 | 1497 | 'type' => 'chmod', |
@@ -1414,30 +1499,30 @@ discard block |
||
1414 | 1499 | ); |
1415 | 1500 | } |
1416 | 1501 | |
1417 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
1418 | - $return[] = array( |
|
1502 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
1503 | + $return[] = array( |
|
1419 | 1504 | 'type' => 'chmod', |
1420 | 1505 | 'filename' => $this_action['destination'] |
1421 | 1506 | ); |
1422 | - } |
|
1423 | - elseif ($actionType == 'remove-dir') |
|
1507 | + } |
|
1508 | + } elseif ($actionType == 'remove-dir') |
|
1424 | 1509 | { |
1425 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
1426 | - $return[] = array( |
|
1510 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
1511 | + $return[] = array( |
|
1427 | 1512 | 'type' => 'chmod', |
1428 | 1513 | 'filename' => $this_action['filename'] |
1429 | 1514 | ); |
1430 | - } |
|
1431 | - elseif ($actionType == 'remove-file') |
|
1515 | + } |
|
1516 | + } elseif ($actionType == 'remove-file') |
|
1432 | 1517 | { |
1433 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
1434 | - $return[] = array( |
|
1518 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
1519 | + $return[] = array( |
|
1435 | 1520 | 'type' => 'chmod', |
1436 | 1521 | 'filename' => $this_action['filename'] |
1437 | 1522 | ); |
1523 | + } |
|
1438 | 1524 | } |
1439 | - } |
|
1440 | - else |
|
1525 | + } else |
|
1441 | 1526 | { |
1442 | 1527 | $return[] = array( |
1443 | 1528 | 'type' => 'error', |
@@ -1448,8 +1533,9 @@ discard block |
||
1448 | 1533 | } |
1449 | 1534 | |
1450 | 1535 | // Only testing - just return a list of things to be done. |
1451 | - if ($testing_only) |
|
1452 | - return $return; |
|
1536 | + if ($testing_only) { |
|
1537 | + return $return; |
|
1538 | + } |
|
1453 | 1539 | |
1454 | 1540 | umask(0); |
1455 | 1541 | |
@@ -1457,78 +1543,81 @@ discard block |
||
1457 | 1543 | $not_done = array(array('type' => '!')); |
1458 | 1544 | foreach ($return as $action) |
1459 | 1545 | { |
1460 | - if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) |
|
1461 | - $not_done[] = $action; |
|
1546 | + if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) { |
|
1547 | + $not_done[] = $action; |
|
1548 | + } |
|
1462 | 1549 | |
1463 | 1550 | if ($action['type'] == 'create-dir') |
1464 | 1551 | { |
1465 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
1466 | - $failure |= !mktree($action['destination'], 0777); |
|
1467 | - } |
|
1468 | - elseif ($action['type'] == 'create-file') |
|
1552 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
1553 | + $failure |= !mktree($action['destination'], 0777); |
|
1554 | + } |
|
1555 | + } elseif ($action['type'] == 'create-file') |
|
1469 | 1556 | { |
1470 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
1471 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
1557 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
1558 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
1559 | + } |
|
1472 | 1560 | |
1473 | 1561 | // Create an empty file. |
1474 | 1562 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
1475 | 1563 | |
1476 | - if (!file_exists($action['destination'])) |
|
1477 | - $failure = true; |
|
1478 | - } |
|
1479 | - elseif ($action['type'] == 'require-dir') |
|
1564 | + if (!file_exists($action['destination'])) { |
|
1565 | + $failure = true; |
|
1566 | + } |
|
1567 | + } elseif ($action['type'] == 'require-dir') |
|
1480 | 1568 | { |
1481 | 1569 | copytree($action['source'], $action['destination']); |
1482 | 1570 | // Any other theme folders? |
1483 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
1484 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
1571 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
1572 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
1485 | 1573 | copytree($action['source'], $theme_destination); |
1486 | - } |
|
1487 | - elseif ($action['type'] == 'require-file') |
|
1574 | + } |
|
1575 | + } elseif ($action['type'] == 'require-file') |
|
1488 | 1576 | { |
1489 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
1490 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
1577 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
1578 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
1579 | + } |
|
1491 | 1580 | |
1492 | 1581 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
1493 | 1582 | |
1494 | 1583 | $failure |= !copy($action['source'], $action['destination']); |
1495 | 1584 | |
1496 | 1585 | // Any other theme files? |
1497 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
1498 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
1586 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
1587 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
1499 | 1588 | { |
1500 | 1589 | if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) |
1501 | 1590 | $failure |= !mktree(dirname($theme_destination), 0777); |
1591 | + } |
|
1502 | 1592 | |
1503 | 1593 | package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only); |
1504 | 1594 | |
1505 | 1595 | $failure |= !copy($action['source'], $theme_destination); |
1506 | 1596 | } |
1507 | - } |
|
1508 | - elseif ($action['type'] == 'move-file') |
|
1597 | + } elseif ($action['type'] == 'move-file') |
|
1509 | 1598 | { |
1510 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
1511 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
1599 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
1600 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
1601 | + } |
|
1512 | 1602 | |
1513 | 1603 | $failure |= !rename($action['source'], $action['destination']); |
1514 | - } |
|
1515 | - elseif ($action['type'] == 'move-dir') |
|
1604 | + } elseif ($action['type'] == 'move-dir') |
|
1516 | 1605 | { |
1517 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
1518 | - $failure |= !mktree($action['destination'], 0777); |
|
1606 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
1607 | + $failure |= !mktree($action['destination'], 0777); |
|
1608 | + } |
|
1519 | 1609 | |
1520 | 1610 | $failure |= !rename($action['source'], $action['destination']); |
1521 | - } |
|
1522 | - elseif ($action['type'] == 'remove-dir') |
|
1611 | + } elseif ($action['type'] == 'remove-dir') |
|
1523 | 1612 | { |
1524 | 1613 | deltree($action['filename']); |
1525 | 1614 | |
1526 | 1615 | // Any other theme folders? |
1527 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
1528 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
1616 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
1617 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
1529 | 1618 | deltree($theme_destination); |
1530 | - } |
|
1531 | - elseif ($action['type'] == 'remove-file') |
|
1619 | + } |
|
1620 | + } elseif ($action['type'] == 'remove-file') |
|
1532 | 1621 | { |
1533 | 1622 | // Make sure the file exists before deleting it. |
1534 | 1623 | if (file_exists($action['filename'])) |
@@ -1537,16 +1626,18 @@ discard block |
||
1537 | 1626 | $failure |= !unlink($action['filename']); |
1538 | 1627 | } |
1539 | 1628 | // The file that was supposed to be deleted couldn't be found. |
1540 | - else |
|
1541 | - $failure = true; |
|
1629 | + else { |
|
1630 | + $failure = true; |
|
1631 | + } |
|
1542 | 1632 | |
1543 | 1633 | // Any other theme folders? |
1544 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
1545 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
1634 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
1635 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
1546 | 1636 | if (file_exists($theme_destination)) |
1547 | 1637 | $failure |= !unlink($theme_destination); |
1548 | - else |
|
1549 | - $failure = true; |
|
1638 | + } else { |
|
1639 | + $failure = true; |
|
1640 | + } |
|
1550 | 1641 | } |
1551 | 1642 | } |
1552 | 1643 | |
@@ -1568,8 +1659,9 @@ discard block |
||
1568 | 1659 | { |
1569 | 1660 | static $near_version = 0; |
1570 | 1661 | |
1571 | - if ($reset) |
|
1572 | - $near_version = 0; |
|
1662 | + if ($reset) { |
|
1663 | + $near_version = 0; |
|
1664 | + } |
|
1573 | 1665 | |
1574 | 1666 | // Normalize the $versions while we remove our previous Doh! |
1575 | 1667 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
@@ -1578,16 +1670,19 @@ discard block |
||
1578 | 1670 | foreach ($versions as $for) |
1579 | 1671 | { |
1580 | 1672 | // Adjust for those wild cards |
1581 | - if (strpos($for, '*') !== false) |
|
1582 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
1673 | + if (strpos($for, '*') !== false) { |
|
1674 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
1675 | + } |
|
1583 | 1676 | |
1584 | 1677 | // If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99 |
1585 | - if (strpos($for, '-') !== false) |
|
1586 | - list ($for, $higher) = explode('-', $for); |
|
1678 | + if (strpos($for, '-') !== false) { |
|
1679 | + list ($for, $higher) = explode('-', $for); |
|
1680 | + } |
|
1587 | 1681 | |
1588 | 1682 | // Do the compare, if the for is greater, than what we have but not greater than what we are running ..... |
1589 | - if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) |
|
1590 | - $near_version = $for; |
|
1683 | + if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) { |
|
1684 | + $near_version = $for; |
|
1685 | + } |
|
1591 | 1686 | } |
1592 | 1687 | |
1593 | 1688 | return !empty($near_version) ? $near_version : false; |
@@ -1610,15 +1705,17 @@ discard block |
||
1610 | 1705 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
1611 | 1706 | |
1612 | 1707 | // Perhaps we do accept anything? |
1613 | - if (in_array('all', $versions)) |
|
1614 | - return true; |
|
1708 | + if (in_array('all', $versions)) { |
|
1709 | + return true; |
|
1710 | + } |
|
1615 | 1711 | |
1616 | 1712 | // Loop through each version. |
1617 | 1713 | foreach ($versions as $for) |
1618 | 1714 | { |
1619 | 1715 | // Wild card spotted? |
1620 | - if (strpos($for, '*') !== false) |
|
1621 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
1716 | + if (strpos($for, '*') !== false) { |
|
1717 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
1718 | + } |
|
1622 | 1719 | |
1623 | 1720 | // Do we have a range? |
1624 | 1721 | if (strpos($for, '-') !== false) |
@@ -1626,12 +1723,14 @@ discard block |
||
1626 | 1723 | list ($lower, $upper) = explode('-', $for); |
1627 | 1724 | |
1628 | 1725 | // Compare the version against lower and upper bounds. |
1629 | - if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) |
|
1630 | - return true; |
|
1726 | + if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) { |
|
1727 | + return true; |
|
1728 | + } |
|
1631 | 1729 | } |
1632 | 1730 | // Otherwise check if they are equal... |
1633 | - elseif (compareVersions($version, $for) === 0) |
|
1634 | - return true; |
|
1731 | + elseif (compareVersions($version, $for) === 0) { |
|
1732 | + return true; |
|
1733 | + } |
|
1635 | 1734 | } |
1636 | 1735 | |
1637 | 1736 | return false; |
@@ -1671,12 +1770,14 @@ discard block |
||
1671 | 1770 | } |
1672 | 1771 | |
1673 | 1772 | // Are they the same, perhaps? |
1674 | - if ($versions[1] === $versions[2]) |
|
1675 | - return 0; |
|
1773 | + if ($versions[1] === $versions[2]) { |
|
1774 | + return 0; |
|
1775 | + } |
|
1676 | 1776 | |
1677 | 1777 | // Get version numbering categories... |
1678 | - if (!isset($categories)) |
|
1679 | - $categories = array_keys($versions[1]); |
|
1778 | + if (!isset($categories)) { |
|
1779 | + $categories = array_keys($versions[1]); |
|
1780 | + } |
|
1680 | 1781 | |
1681 | 1782 | // Loop through each category. |
1682 | 1783 | foreach ($categories as $category) |
@@ -1686,13 +1787,15 @@ discard block |
||
1686 | 1787 | { |
1687 | 1788 | // Dev builds are a problematic exception. |
1688 | 1789 | // (stable) dev < (stable) but (unstable) dev = (unstable) |
1689 | - if ($category == 'type') |
|
1690 | - return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
1691 | - elseif ($category == 'dev') |
|
1692 | - return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
1790 | + if ($category == 'type') { |
|
1791 | + return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
1792 | + } elseif ($category == 'dev') { |
|
1793 | + return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
1794 | + } |
|
1693 | 1795 | // Otherwise a simple comparison. |
1694 | - else |
|
1695 | - return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
1796 | + else { |
|
1797 | + return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
1798 | + } |
|
1696 | 1799 | } |
1697 | 1800 | } |
1698 | 1801 | |
@@ -1726,11 +1829,13 @@ discard block |
||
1726 | 1829 | ); |
1727 | 1830 | |
1728 | 1831 | // do we parse in a package directory? |
1729 | - if (!empty($temp_path)) |
|
1730 | - $dirs['$package'] = $temp_path; |
|
1832 | + if (!empty($temp_path)) { |
|
1833 | + $dirs['$package'] = $temp_path; |
|
1834 | + } |
|
1731 | 1835 | |
1732 | - if (strlen($path) == 0) |
|
1733 | - trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
1836 | + if (strlen($path) == 0) { |
|
1837 | + trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
1838 | + } |
|
1734 | 1839 | |
1735 | 1840 | return strtr($path, $dirs); |
1736 | 1841 | } |
@@ -1747,8 +1852,9 @@ discard block |
||
1747 | 1852 | /** @var ftp_connection $package_ftp */ |
1748 | 1853 | global $package_ftp; |
1749 | 1854 | |
1750 | - if (!file_exists($dir)) |
|
1751 | - return; |
|
1855 | + if (!file_exists($dir)) { |
|
1856 | + return; |
|
1857 | + } |
|
1752 | 1858 | |
1753 | 1859 | $current_dir = @opendir($dir); |
1754 | 1860 | if ($current_dir == false) |
@@ -1756,8 +1862,9 @@ discard block |
||
1756 | 1862 | if ($delete_dir && isset($package_ftp)) |
1757 | 1863 | { |
1758 | 1864 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
1759 | - if (!is_dir($dir)) |
|
1760 | - $package_ftp->chmod($ftp_file, 0777); |
|
1865 | + if (!is_dir($dir)) { |
|
1866 | + $package_ftp->chmod($ftp_file, 0777); |
|
1867 | + } |
|
1761 | 1868 | $package_ftp->unlink($ftp_file); |
1762 | 1869 | } |
1763 | 1870 | |
@@ -1766,26 +1873,28 @@ discard block |
||
1766 | 1873 | |
1767 | 1874 | while ($entryname = readdir($current_dir)) |
1768 | 1875 | { |
1769 | - if (in_array($entryname, array('.', '..'))) |
|
1770 | - continue; |
|
1876 | + if (in_array($entryname, array('.', '..'))) { |
|
1877 | + continue; |
|
1878 | + } |
|
1771 | 1879 | |
1772 | - if (is_dir($dir . '/' . $entryname)) |
|
1773 | - deltree($dir . '/' . $entryname); |
|
1774 | - else |
|
1880 | + if (is_dir($dir . '/' . $entryname)) { |
|
1881 | + deltree($dir . '/' . $entryname); |
|
1882 | + } else |
|
1775 | 1883 | { |
1776 | 1884 | // Here, 755 doesn't really matter since we're deleting it anyway. |
1777 | 1885 | if (isset($package_ftp)) |
1778 | 1886 | { |
1779 | 1887 | $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
1780 | 1888 | |
1781 | - if (!is_writable($dir . '/' . $entryname)) |
|
1782 | - $package_ftp->chmod($ftp_file, 0777); |
|
1889 | + if (!is_writable($dir . '/' . $entryname)) { |
|
1890 | + $package_ftp->chmod($ftp_file, 0777); |
|
1891 | + } |
|
1783 | 1892 | $package_ftp->unlink($ftp_file); |
1784 | - } |
|
1785 | - else |
|
1893 | + } else |
|
1786 | 1894 | { |
1787 | - if (!is_writable($dir . '/' . $entryname)) |
|
1788 | - smf_chmod($dir . '/' . $entryname, 0777); |
|
1895 | + if (!is_writable($dir . '/' . $entryname)) { |
|
1896 | + smf_chmod($dir . '/' . $entryname, 0777); |
|
1897 | + } |
|
1789 | 1898 | unlink($dir . '/' . $entryname); |
1790 | 1899 | } |
1791 | 1900 | } |
@@ -1798,14 +1907,15 @@ discard block |
||
1798 | 1907 | if (isset($package_ftp)) |
1799 | 1908 | { |
1800 | 1909 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
1801 | - if (!is_writable($dir . '/' . $entryname)) |
|
1802 | - $package_ftp->chmod($ftp_file, 0777); |
|
1910 | + if (!is_writable($dir . '/' . $entryname)) { |
|
1911 | + $package_ftp->chmod($ftp_file, 0777); |
|
1912 | + } |
|
1803 | 1913 | $package_ftp->unlink($ftp_file); |
1804 | - } |
|
1805 | - else |
|
1914 | + } else |
|
1806 | 1915 | { |
1807 | - if (!is_writable($dir)) |
|
1808 | - smf_chmod($dir, 0777); |
|
1916 | + if (!is_writable($dir)) { |
|
1917 | + smf_chmod($dir, 0777); |
|
1918 | + } |
|
1809 | 1919 | @rmdir($dir); |
1810 | 1920 | } |
1811 | 1921 | } |
@@ -1828,10 +1938,11 @@ discard block |
||
1828 | 1938 | { |
1829 | 1939 | if (!is_writable($strPath) && $mode !== false) |
1830 | 1940 | { |
1831 | - if (isset($package_ftp)) |
|
1832 | - $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
1833 | - else |
|
1834 | - smf_chmod($strPath, $mode); |
|
1941 | + if (isset($package_ftp)) { |
|
1942 | + $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
1943 | + } else { |
|
1944 | + smf_chmod($strPath, $mode); |
|
1945 | + } |
|
1835 | 1946 | } |
1836 | 1947 | |
1837 | 1948 | $test = @opendir($strPath); |
@@ -1839,36 +1950,37 @@ discard block |
||
1839 | 1950 | { |
1840 | 1951 | closedir($test); |
1841 | 1952 | return is_writable($strPath); |
1953 | + } else { |
|
1954 | + return false; |
|
1842 | 1955 | } |
1843 | - else |
|
1844 | - return false; |
|
1845 | 1956 | } |
1846 | 1957 | // Is this an invalid path and/or we can't make the directory? |
1847 | - if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) |
|
1848 | - return false; |
|
1958 | + if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) { |
|
1959 | + return false; |
|
1960 | + } |
|
1849 | 1961 | |
1850 | 1962 | if (!is_writable(dirname($strPath)) && $mode !== false) |
1851 | 1963 | { |
1852 | - if (isset($package_ftp)) |
|
1853 | - $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
1854 | - else |
|
1855 | - smf_chmod(dirname($strPath), $mode); |
|
1964 | + if (isset($package_ftp)) { |
|
1965 | + $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
1966 | + } else { |
|
1967 | + smf_chmod(dirname($strPath), $mode); |
|
1968 | + } |
|
1856 | 1969 | } |
1857 | 1970 | |
1858 | - if ($mode !== false && isset($package_ftp)) |
|
1859 | - return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
1860 | - elseif ($mode === false) |
|
1971 | + if ($mode !== false && isset($package_ftp)) { |
|
1972 | + return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
1973 | + } elseif ($mode === false) |
|
1861 | 1974 | { |
1862 | 1975 | $test = @opendir(dirname($strPath)); |
1863 | 1976 | if ($test) |
1864 | 1977 | { |
1865 | 1978 | closedir($test); |
1866 | 1979 | return true; |
1980 | + } else { |
|
1981 | + return false; |
|
1867 | 1982 | } |
1868 | - else |
|
1869 | - return false; |
|
1870 | - } |
|
1871 | - else |
|
1983 | + } else |
|
1872 | 1984 | { |
1873 | 1985 | @mkdir($strPath, $mode); |
1874 | 1986 | $test = @opendir($strPath); |
@@ -1876,9 +1988,9 @@ discard block |
||
1876 | 1988 | { |
1877 | 1989 | closedir($test); |
1878 | 1990 | return true; |
1991 | + } else { |
|
1992 | + return false; |
|
1879 | 1993 | } |
1880 | - else |
|
1881 | - return false; |
|
1882 | 1994 | } |
1883 | 1995 | } |
1884 | 1996 | |
@@ -1894,39 +2006,46 @@ discard block |
||
1894 | 2006 | /** @var ftp_connection $package_ftp */ |
1895 | 2007 | global $package_ftp; |
1896 | 2008 | |
1897 | - if (!file_exists($destination) || !is_writable($destination)) |
|
1898 | - mktree($destination, 0755); |
|
1899 | - if (!is_writable($destination)) |
|
1900 | - mktree($destination, 0777); |
|
2009 | + if (!file_exists($destination) || !is_writable($destination)) { |
|
2010 | + mktree($destination, 0755); |
|
2011 | + } |
|
2012 | + if (!is_writable($destination)) { |
|
2013 | + mktree($destination, 0777); |
|
2014 | + } |
|
1901 | 2015 | |
1902 | 2016 | $current_dir = opendir($source); |
1903 | - if ($current_dir == false) |
|
1904 | - return; |
|
2017 | + if ($current_dir == false) { |
|
2018 | + return; |
|
2019 | + } |
|
1905 | 2020 | |
1906 | 2021 | while ($entryname = readdir($current_dir)) |
1907 | 2022 | { |
1908 | - if (in_array($entryname, array('.', '..'))) |
|
1909 | - continue; |
|
2023 | + if (in_array($entryname, array('.', '..'))) { |
|
2024 | + continue; |
|
2025 | + } |
|
1910 | 2026 | |
1911 | - if (isset($package_ftp)) |
|
1912 | - $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
2027 | + if (isset($package_ftp)) { |
|
2028 | + $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
2029 | + } |
|
1913 | 2030 | |
1914 | 2031 | if (is_file($source . '/' . $entryname)) |
1915 | 2032 | { |
1916 | - if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) |
|
1917 | - $package_ftp->create_file($ftp_file); |
|
1918 | - elseif (!file_exists($destination . '/' . $entryname)) |
|
1919 | - @touch($destination . '/' . $entryname); |
|
2033 | + if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) { |
|
2034 | + $package_ftp->create_file($ftp_file); |
|
2035 | + } elseif (!file_exists($destination . '/' . $entryname)) { |
|
2036 | + @touch($destination . '/' . $entryname); |
|
2037 | + } |
|
1920 | 2038 | } |
1921 | 2039 | |
1922 | 2040 | package_chmod($destination . '/' . $entryname); |
1923 | 2041 | |
1924 | - if (is_dir($source . '/' . $entryname)) |
|
1925 | - copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
1926 | - elseif (file_exists($destination . '/' . $entryname)) |
|
1927 | - package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
1928 | - else |
|
1929 | - copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
2042 | + if (is_dir($source . '/' . $entryname)) { |
|
2043 | + copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
2044 | + } elseif (file_exists($destination . '/' . $entryname)) { |
|
2045 | + package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
2046 | + } else { |
|
2047 | + copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
2048 | + } |
|
1930 | 2049 | } |
1931 | 2050 | |
1932 | 2051 | closedir($current_dir); |
@@ -1944,21 +2063,24 @@ discard block |
||
1944 | 2063 | $data = array(); |
1945 | 2064 | |
1946 | 2065 | $dir = @dir($path . $sub_path); |
1947 | - if (!$dir) |
|
1948 | - return array(); |
|
2066 | + if (!$dir) { |
|
2067 | + return array(); |
|
2068 | + } |
|
1949 | 2069 | while ($entry = $dir->read()) |
1950 | 2070 | { |
1951 | - if ($entry == '.' || $entry == '..') |
|
1952 | - continue; |
|
2071 | + if ($entry == '.' || $entry == '..') { |
|
2072 | + continue; |
|
2073 | + } |
|
1953 | 2074 | |
1954 | - if (is_dir($path . $sub_path . '/' . $entry)) |
|
1955 | - $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
1956 | - else |
|
1957 | - $data[] = array( |
|
2075 | + if (is_dir($path . $sub_path . '/' . $entry)) { |
|
2076 | + $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
2077 | + } else { |
|
2078 | + $data[] = array( |
|
1958 | 2079 | 'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, |
1959 | 2080 | 'size' => filesize($path . $sub_path . '/' . $entry), |
1960 | 2081 | 'skipped' => false, |
1961 | 2082 | ); |
2083 | + } |
|
1962 | 2084 | } |
1963 | 2085 | $dir->close(); |
1964 | 2086 | |
@@ -2013,8 +2135,9 @@ discard block |
||
2013 | 2135 | { |
2014 | 2136 | // If this filename is relative, if so take a guess at what it should be. |
2015 | 2137 | $real_filename = $filename; |
2016 | - if (strpos($filename, 'Themes') === 0) |
|
2017 | - $real_filename = $boarddir . '/' . $filename; |
|
2138 | + if (strpos($filename, 'Themes') === 0) { |
|
2139 | + $real_filename = $boarddir . '/' . $filename; |
|
2140 | + } |
|
2018 | 2141 | |
2019 | 2142 | if (strpos($real_filename, $theme['theme_dir']) === 0) |
2020 | 2143 | { |
@@ -2033,8 +2156,9 @@ discard block |
||
2033 | 2156 | foreach ($theme_paths as $id => $theme) |
2034 | 2157 | { |
2035 | 2158 | // Default is getting done anyway, so no need for involvement here. |
2036 | - if ($id == 1) |
|
2037 | - continue; |
|
2159 | + if ($id == 1) { |
|
2160 | + continue; |
|
2161 | + } |
|
2038 | 2162 | |
2039 | 2163 | // For every template, do we want it? Yea, no, maybe? |
2040 | 2164 | foreach ($template_changes[1] as $index => $template_file) |
@@ -2057,8 +2181,9 @@ discard block |
||
2057 | 2181 | ); |
2058 | 2182 | |
2059 | 2183 | // Sometimes though, we have some additional files for other themes, if we have add them to the mix. |
2060 | - if (isset($custom_themes_add[$files_to_change[1]])) |
|
2061 | - $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
2184 | + if (isset($custom_themes_add[$files_to_change[1]])) { |
|
2185 | + $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
2186 | + } |
|
2062 | 2187 | |
2063 | 2188 | // Now, loop through all the files we're changing, and, well, change them ;) |
2064 | 2189 | foreach ($files_to_change as $theme => $working_file) |
@@ -2092,11 +2217,13 @@ discard block |
||
2092 | 2217 | continue; |
2093 | 2218 | } |
2094 | 2219 | // Okay, we're creating this file then...? |
2095 | - elseif (!file_exists($working_file)) |
|
2096 | - $working_data = ''; |
|
2220 | + elseif (!file_exists($working_file)) { |
|
2221 | + $working_data = ''; |
|
2222 | + } |
|
2097 | 2223 | // Phew, it exists! Load 'er up! |
2098 | - else |
|
2099 | - $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
2224 | + else { |
|
2225 | + $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
2226 | + } |
|
2100 | 2227 | |
2101 | 2228 | $actions[] = array( |
2102 | 2229 | 'type' => 'opened', |
@@ -2117,8 +2244,8 @@ discard block |
||
2117 | 2244 | |
2118 | 2245 | // Grab all search items of this operation (in most cases just 1). |
2119 | 2246 | $searches = $operation->set('search'); |
2120 | - foreach ($searches as $i => $search) |
|
2121 | - $actual_operation['searches'][] = array( |
|
2247 | + foreach ($searches as $i => $search) { |
|
2248 | + $actual_operation['searches'][] = array( |
|
2122 | 2249 | 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace', |
2123 | 2250 | 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', |
2124 | 2251 | 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', |
@@ -2127,6 +2254,7 @@ discard block |
||
2127 | 2254 | 'preg_search' => '', |
2128 | 2255 | 'preg_replace' => '', |
2129 | 2256 | ); |
2257 | + } |
|
2130 | 2258 | |
2131 | 2259 | // At least one search should be defined. |
2132 | 2260 | if (empty($actual_operation['searches'])) |
@@ -2151,30 +2279,32 @@ discard block |
||
2151 | 2279 | // Reverse modification of regular expressions are not allowed. |
2152 | 2280 | if ($search['is_reg_exp']) |
2153 | 2281 | { |
2154 | - if ($actual_operation['error'] === 'fatal') |
|
2155 | - $actions[] = array( |
|
2282 | + if ($actual_operation['error'] === 'fatal') { |
|
2283 | + $actions[] = array( |
|
2156 | 2284 | 'type' => 'failure', |
2157 | 2285 | 'filename' => $working_file, |
2158 | 2286 | 'search' => $search['search'], |
2159 | 2287 | 'is_custom' => $theme > 1 ? $theme : 0, |
2160 | 2288 | ); |
2289 | + } |
|
2161 | 2290 | |
2162 | 2291 | // Continue to the next operation. |
2163 | 2292 | continue 2; |
2164 | 2293 | } |
2165 | 2294 | |
2166 | 2295 | // The replacement is now the search subject... |
2167 | - if ($search['position'] === 'replace' || $search['position'] === 'end') |
|
2168 | - $actual_operation['searches'][$i]['search'] = $search['add']; |
|
2169 | - else |
|
2296 | + if ($search['position'] === 'replace' || $search['position'] === 'end') { |
|
2297 | + $actual_operation['searches'][$i]['search'] = $search['add']; |
|
2298 | + } else |
|
2170 | 2299 | { |
2171 | 2300 | // Reversing a before/after modification becomes a replacement. |
2172 | 2301 | $actual_operation['searches'][$i]['position'] = 'replace'; |
2173 | 2302 | |
2174 | - if ($search['position'] === 'before') |
|
2175 | - $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
2176 | - elseif ($search['position'] === 'after') |
|
2177 | - $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
2303 | + if ($search['position'] === 'before') { |
|
2304 | + $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
2305 | + } elseif ($search['position'] === 'after') { |
|
2306 | + $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
2307 | + } |
|
2178 | 2308 | } |
2179 | 2309 | |
2180 | 2310 | // ...and the search subject is now the replacement. |
@@ -2202,16 +2332,17 @@ discard block |
||
2202 | 2332 | foreach ($actual_operation['searches'] as $i => $search) |
2203 | 2333 | { |
2204 | 2334 | // Not much needed if the search subject is already a regexp. |
2205 | - if ($search['is_reg_exp']) |
|
2206 | - $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
2207 | - else |
|
2335 | + if ($search['is_reg_exp']) { |
|
2336 | + $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
2337 | + } else |
|
2208 | 2338 | { |
2209 | 2339 | // Make the search subject fit into a regular expression. |
2210 | 2340 | $actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~'); |
2211 | 2341 | |
2212 | 2342 | // Using 'loose', a random amount of tabs and spaces may be used. |
2213 | - if ($search['loose_whitespace']) |
|
2214 | - $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
2343 | + if ($search['loose_whitespace']) { |
|
2344 | + $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
2345 | + } |
|
2215 | 2346 | } |
2216 | 2347 | |
2217 | 2348 | // Shuzzup. This is done so we can safely use a regular expression. ($0 is bad!!) |
@@ -2237,8 +2368,7 @@ discard block |
||
2237 | 2368 | if ($undo) |
2238 | 2369 | { |
2239 | 2370 | $actual_operation['searches'][$i]['preg_replace'] = ''; |
2240 | - } |
|
2241 | - else |
|
2371 | + } else |
|
2242 | 2372 | { |
2243 | 2373 | $actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$'; |
2244 | 2374 | $actual_operation['searches'][$i]['preg_replace'] .= '$1'; |
@@ -2285,8 +2415,9 @@ discard block |
||
2285 | 2415 | } |
2286 | 2416 | |
2287 | 2417 | // Replace it into nothing? That's not an option...unless it's an undoing end. |
2288 | - if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) |
|
2289 | - continue; |
|
2418 | + if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) { |
|
2419 | + continue; |
|
2420 | + } |
|
2290 | 2421 | |
2291 | 2422 | // Finally, we're doing some replacements. |
2292 | 2423 | $working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1); |
@@ -2311,22 +2442,25 @@ discard block |
||
2311 | 2442 | |
2312 | 2443 | package_chmod($working_file); |
2313 | 2444 | |
2314 | - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) |
|
2315 | - $actions[] = array( |
|
2445 | + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { |
|
2446 | + $actions[] = array( |
|
2316 | 2447 | 'type' => 'chmod', |
2317 | 2448 | 'filename' => $working_file |
2318 | 2449 | ); |
2450 | + } |
|
2319 | 2451 | |
2320 | - if (basename($working_file) == 'Settings_bak.php') |
|
2321 | - continue; |
|
2452 | + if (basename($working_file) == 'Settings_bak.php') { |
|
2453 | + continue; |
|
2454 | + } |
|
2322 | 2455 | |
2323 | 2456 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
2324 | 2457 | { |
2325 | 2458 | // No, no, not Settings.php! |
2326 | - if (basename($working_file) == 'Settings.php') |
|
2327 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2328 | - else |
|
2329 | - @copy($working_file, $working_file . '~'); |
|
2459 | + if (basename($working_file) == 'Settings.php') { |
|
2460 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2461 | + } else { |
|
2462 | + @copy($working_file, $working_file . '~'); |
|
2463 | + } |
|
2330 | 2464 | } |
2331 | 2465 | |
2332 | 2466 | // Always call this, even if in testing, because it won't really be written in testing mode. |
@@ -2393,8 +2527,9 @@ discard block |
||
2393 | 2527 | if ($code_match[1] != 'edit file' && $code_match[1] != 'file') |
2394 | 2528 | { |
2395 | 2529 | // It's a step, let's add that to the current steps. |
2396 | - if (isset($temp_changes[$step_counter])) |
|
2397 | - $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
2530 | + if (isset($temp_changes[$step_counter])) { |
|
2531 | + $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
2532 | + } |
|
2398 | 2533 | continue; |
2399 | 2534 | } |
2400 | 2535 | |
@@ -2411,11 +2546,13 @@ discard block |
||
2411 | 2546 | foreach ($theme_paths as $id => $theme) |
2412 | 2547 | { |
2413 | 2548 | // If this filename is relative, if so take a guess at what it should be. |
2414 | - if (strpos($filename, 'Themes') === 0) |
|
2415 | - $filename = $boarddir . '/' . $filename; |
|
2549 | + if (strpos($filename, 'Themes') === 0) { |
|
2550 | + $filename = $boarddir . '/' . $filename; |
|
2551 | + } |
|
2416 | 2552 | |
2417 | - if (strpos($filename, $theme['theme_dir']) === 0) |
|
2418 | - $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
2553 | + if (strpos($filename, $theme['theme_dir']) === 0) { |
|
2554 | + $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
2555 | + } |
|
2419 | 2556 | } |
2420 | 2557 | } |
2421 | 2558 | |
@@ -2428,8 +2565,9 @@ discard block |
||
2428 | 2565 | foreach ($theme_paths as $id => $theme) |
2429 | 2566 | { |
2430 | 2567 | // Don't do default, it means nothing to me. |
2431 | - if ($id == 1) |
|
2432 | - continue; |
|
2568 | + if ($id == 1) { |
|
2569 | + continue; |
|
2570 | + } |
|
2433 | 2571 | |
2434 | 2572 | // Now, for each file do we need to edit it? |
2435 | 2573 | foreach ($template_changes[1] as $pos => $template_file) |
@@ -2465,32 +2603,36 @@ discard block |
||
2465 | 2603 | package_chmod($working_file); |
2466 | 2604 | |
2467 | 2605 | // Don't even dare. |
2468 | - if (basename($working_file) == 'Settings_bak.php') |
|
2469 | - continue; |
|
2606 | + if (basename($working_file) == 'Settings_bak.php') { |
|
2607 | + continue; |
|
2608 | + } |
|
2470 | 2609 | |
2471 | - if (!is_writable($working_file)) |
|
2472 | - $actions[] = array( |
|
2610 | + if (!is_writable($working_file)) { |
|
2611 | + $actions[] = array( |
|
2473 | 2612 | 'type' => 'chmod', |
2474 | 2613 | 'filename' => $working_file |
2475 | 2614 | ); |
2615 | + } |
|
2476 | 2616 | |
2477 | 2617 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
2478 | 2618 | { |
2479 | - if (basename($working_file) == 'Settings.php') |
|
2480 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2481 | - else |
|
2482 | - @copy($working_file, $working_file . '~'); |
|
2619 | + if (basename($working_file) == 'Settings.php') { |
|
2620 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2621 | + } else { |
|
2622 | + @copy($working_file, $working_file . '~'); |
|
2623 | + } |
|
2483 | 2624 | } |
2484 | 2625 | |
2485 | 2626 | package_put_contents($working_file, $working_data, $testing); |
2486 | 2627 | } |
2487 | 2628 | |
2488 | - if ($working_file !== null) |
|
2489 | - $actions[] = array( |
|
2629 | + if ($working_file !== null) { |
|
2630 | + $actions[] = array( |
|
2490 | 2631 | 'type' => 'saved', |
2491 | 2632 | 'filename' => $working_file, |
2492 | 2633 | 'is_custom' => $is_custom, |
2493 | 2634 | ); |
2635 | + } |
|
2494 | 2636 | |
2495 | 2637 | // Is this "now working on" file a theme specific one? |
2496 | 2638 | $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0; |
@@ -2509,10 +2651,11 @@ discard block |
||
2509 | 2651 | { |
2510 | 2652 | $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages'); |
2511 | 2653 | |
2512 | - foreach ($places_to_check as $place) |
|
2513 | - if (file_exists($place . '/' . $working_file)) |
|
2654 | + foreach ($places_to_check as $place) { |
|
2655 | + if (file_exists($place . '/' . $working_file)) |
|
2514 | 2656 | { |
2515 | 2657 | $working_file = $place . '/' . $working_file; |
2658 | + } |
|
2516 | 2659 | break; |
2517 | 2660 | } |
2518 | 2661 | } |
@@ -2526,8 +2669,7 @@ discard block |
||
2526 | 2669 | 'type' => 'opened', |
2527 | 2670 | 'filename' => $working_file |
2528 | 2671 | ); |
2529 | - } |
|
2530 | - else |
|
2672 | + } else |
|
2531 | 2673 | { |
2532 | 2674 | $actions[] = array( |
2533 | 2675 | 'type' => 'missing', |
@@ -2563,11 +2705,13 @@ discard block |
||
2563 | 2705 | $replace_with = $code_match[2]; |
2564 | 2706 | |
2565 | 2707 | // Add this afterward... |
2566 | - if ($code_match[1] == 'add' || $code_match[1] == 'add after') |
|
2567 | - $replace_with = $working_search . "\n" . $replace_with; |
|
2708 | + if ($code_match[1] == 'add' || $code_match[1] == 'add after') { |
|
2709 | + $replace_with = $working_search . "\n" . $replace_with; |
|
2710 | + } |
|
2568 | 2711 | // Add this beforehand. |
2569 | - elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') |
|
2570 | - $replace_with .= "\n" . $working_search; |
|
2712 | + elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') { |
|
2713 | + $replace_with .= "\n" . $working_search; |
|
2714 | + } |
|
2571 | 2715 | // Otherwise.. replace with $replace_with ;). |
2572 | 2716 | } |
2573 | 2717 | |
@@ -2630,29 +2774,32 @@ discard block |
||
2630 | 2774 | { |
2631 | 2775 | package_chmod($working_file); |
2632 | 2776 | |
2633 | - if (!is_writable($working_file)) |
|
2634 | - $actions[] = array( |
|
2777 | + if (!is_writable($working_file)) { |
|
2778 | + $actions[] = array( |
|
2635 | 2779 | 'type' => 'chmod', |
2636 | 2780 | 'filename' => $working_file |
2637 | 2781 | ); |
2782 | + } |
|
2638 | 2783 | |
2639 | 2784 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
2640 | 2785 | { |
2641 | - if (basename($working_file) == 'Settings.php') |
|
2642 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2643 | - else |
|
2644 | - @copy($working_file, $working_file . '~'); |
|
2786 | + if (basename($working_file) == 'Settings.php') { |
|
2787 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
2788 | + } else { |
|
2789 | + @copy($working_file, $working_file . '~'); |
|
2790 | + } |
|
2645 | 2791 | } |
2646 | 2792 | |
2647 | 2793 | package_put_contents($working_file, $working_data, $testing); |
2648 | 2794 | } |
2649 | 2795 | |
2650 | - if ($working_file !== null) |
|
2651 | - $actions[] = array( |
|
2796 | + if ($working_file !== null) { |
|
2797 | + $actions[] = array( |
|
2652 | 2798 | 'type' => 'saved', |
2653 | 2799 | 'filename' => $working_file, |
2654 | 2800 | 'is_custom' => $is_custom, |
2655 | 2801 | ); |
2802 | + } |
|
2656 | 2803 | |
2657 | 2804 | $actions[] = array( |
2658 | 2805 | 'type' => 'result', |
@@ -2678,17 +2825,19 @@ discard block |
||
2678 | 2825 | $mem_check = setMemoryLimit('128M'); |
2679 | 2826 | |
2680 | 2827 | // Windows doesn't seem to care about the memory_limit. |
2681 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
2682 | - $package_cache = array(); |
|
2683 | - else |
|
2684 | - $package_cache = false; |
|
2828 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
2829 | + $package_cache = array(); |
|
2830 | + } else { |
|
2831 | + $package_cache = false; |
|
2832 | + } |
|
2685 | 2833 | } |
2686 | 2834 | |
2687 | - if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) |
|
2688 | - return file_get_contents($filename); |
|
2689 | - else |
|
2690 | - return $package_cache[$filename]; |
|
2691 | -} |
|
2835 | + if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) { |
|
2836 | + return file_get_contents($filename); |
|
2837 | + } else { |
|
2838 | + return $package_cache[$filename]; |
|
2839 | + } |
|
2840 | + } |
|
2692 | 2841 | |
2693 | 2842 | /** |
2694 | 2843 | * Writes data to a file, almost exactly like the file_put_contents() function. |
@@ -2712,19 +2861,22 @@ discard block |
||
2712 | 2861 | // Try to increase the memory limit - we don't want to run out of ram! |
2713 | 2862 | $mem_check = setMemoryLimit('128M'); |
2714 | 2863 | |
2715 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
2716 | - $package_cache = array(); |
|
2717 | - else |
|
2718 | - $package_cache = false; |
|
2864 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
2865 | + $package_cache = array(); |
|
2866 | + } else { |
|
2867 | + $package_cache = false; |
|
2868 | + } |
|
2719 | 2869 | } |
2720 | 2870 | |
2721 | - if (isset($package_ftp)) |
|
2722 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
2871 | + if (isset($package_ftp)) { |
|
2872 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
2873 | + } |
|
2723 | 2874 | |
2724 | - if (!file_exists($filename) && isset($package_ftp)) |
|
2725 | - $package_ftp->create_file($ftp_file); |
|
2726 | - elseif (!file_exists($filename)) |
|
2727 | - @touch($filename); |
|
2875 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
2876 | + $package_ftp->create_file($ftp_file); |
|
2877 | + } elseif (!file_exists($filename)) { |
|
2878 | + @touch($filename); |
|
2879 | + } |
|
2728 | 2880 | |
2729 | 2881 | package_chmod($filename); |
2730 | 2882 | |
@@ -2733,22 +2885,23 @@ discard block |
||
2733 | 2885 | $fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); |
2734 | 2886 | |
2735 | 2887 | // We should show an error message or attempt a rollback, no? |
2736 | - if (!$fp) |
|
2737 | - return false; |
|
2888 | + if (!$fp) { |
|
2889 | + return false; |
|
2890 | + } |
|
2738 | 2891 | |
2739 | 2892 | fwrite($fp, $data); |
2740 | 2893 | fclose($fp); |
2741 | - } |
|
2742 | - elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) |
|
2743 | - return strlen($data); |
|
2744 | - else |
|
2894 | + } elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) { |
|
2895 | + return strlen($data); |
|
2896 | + } else |
|
2745 | 2897 | { |
2746 | 2898 | $package_cache[$filename] = $data; |
2747 | 2899 | |
2748 | 2900 | // Permission denied, eh? |
2749 | 2901 | $fp = @fopen($filename, 'r+'); |
2750 | - if (!$fp) |
|
2751 | - return false; |
|
2902 | + if (!$fp) { |
|
2903 | + return false; |
|
2904 | + } |
|
2752 | 2905 | fclose($fp); |
2753 | 2906 | } |
2754 | 2907 | |
@@ -2766,19 +2919,22 @@ discard block |
||
2766 | 2919 | global $package_ftp, $package_cache; |
2767 | 2920 | static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm'); |
2768 | 2921 | |
2769 | - if (empty($package_cache)) |
|
2770 | - return; |
|
2922 | + if (empty($package_cache)) { |
|
2923 | + return; |
|
2924 | + } |
|
2771 | 2925 | |
2772 | 2926 | // First, let's check permissions! |
2773 | 2927 | foreach ($package_cache as $filename => $data) |
2774 | 2928 | { |
2775 | - if (isset($package_ftp)) |
|
2776 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
2929 | + if (isset($package_ftp)) { |
|
2930 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
2931 | + } |
|
2777 | 2932 | |
2778 | - if (!file_exists($filename) && isset($package_ftp)) |
|
2779 | - $package_ftp->create_file($ftp_file); |
|
2780 | - elseif (!file_exists($filename)) |
|
2781 | - @touch($filename); |
|
2933 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
2934 | + $package_ftp->create_file($ftp_file); |
|
2935 | + } elseif (!file_exists($filename)) { |
|
2936 | + @touch($filename); |
|
2937 | + } |
|
2782 | 2938 | |
2783 | 2939 | $result = package_chmod($filename); |
2784 | 2940 | |
@@ -2832,8 +2988,9 @@ discard block |
||
2832 | 2988 | /** @var ftp_connection $package_ftp */ |
2833 | 2989 | global $package_ftp; |
2834 | 2990 | |
2835 | - if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') |
|
2836 | - return true; |
|
2991 | + if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') { |
|
2992 | + return true; |
|
2993 | + } |
|
2837 | 2994 | |
2838 | 2995 | // Start off checking without FTP. |
2839 | 2996 | if (!isset($package_ftp) || $package_ftp === false) |
@@ -2855,8 +3012,7 @@ discard block |
||
2855 | 3012 | |
2856 | 3013 | // Keep track of the writable status here. |
2857 | 3014 | $file_permissions = @fileperms($chmod_file); |
2858 | - } |
|
2859 | - else |
|
3015 | + } else |
|
2860 | 3016 | { |
2861 | 3017 | // This looks odd, but it's an attempt to work around PHP suExec. |
2862 | 3018 | if (!file_exists($chmod_file) && $perm_state == 'writable') |
@@ -2866,24 +3022,28 @@ discard block |
||
2866 | 3022 | mktree(dirname($chmod_file), 0755); |
2867 | 3023 | @touch($chmod_file); |
2868 | 3024 | smf_chmod($chmod_file, 0755); |
3025 | + } else { |
|
3026 | + $file_permissions = @fileperms($chmod_file); |
|
2869 | 3027 | } |
2870 | - else |
|
2871 | - $file_permissions = @fileperms($chmod_file); |
|
2872 | 3028 | } |
2873 | 3029 | |
2874 | 3030 | // This looks odd, but it's another attempt to work around PHP suExec. |
2875 | - if ($perm_state != 'writable') |
|
2876 | - smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
2877 | - else |
|
3031 | + if ($perm_state != 'writable') { |
|
3032 | + smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
3033 | + } else |
|
2878 | 3034 | { |
2879 | - if (!@is_writable($chmod_file)) |
|
2880 | - smf_chmod($chmod_file, 0755); |
|
2881 | - if (!@is_writable($chmod_file)) |
|
2882 | - smf_chmod($chmod_file, 0777); |
|
2883 | - if (!@is_writable(dirname($chmod_file))) |
|
2884 | - smf_chmod($chmod_file, 0755); |
|
2885 | - if (!@is_writable(dirname($chmod_file))) |
|
2886 | - smf_chmod($chmod_file, 0777); |
|
3035 | + if (!@is_writable($chmod_file)) { |
|
3036 | + smf_chmod($chmod_file, 0755); |
|
3037 | + } |
|
3038 | + if (!@is_writable($chmod_file)) { |
|
3039 | + smf_chmod($chmod_file, 0777); |
|
3040 | + } |
|
3041 | + if (!@is_writable(dirname($chmod_file))) { |
|
3042 | + smf_chmod($chmod_file, 0755); |
|
3043 | + } |
|
3044 | + if (!@is_writable(dirname($chmod_file))) { |
|
3045 | + smf_chmod($chmod_file, 0777); |
|
3046 | + } |
|
2887 | 3047 | } |
2888 | 3048 | |
2889 | 3049 | // The ultimate writable test. |
@@ -2892,20 +3052,22 @@ discard block |
||
2892 | 3052 | $fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb'); |
2893 | 3053 | if (@is_writable($chmod_file) && $fp) |
2894 | 3054 | { |
2895 | - if (!is_dir($chmod_file)) |
|
2896 | - fclose($fp); |
|
2897 | - else |
|
2898 | - closedir($fp); |
|
3055 | + if (!is_dir($chmod_file)) { |
|
3056 | + fclose($fp); |
|
3057 | + } else { |
|
3058 | + closedir($fp); |
|
3059 | + } |
|
2899 | 3060 | |
2900 | 3061 | // It worked! |
2901 | - if ($track_change) |
|
2902 | - $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
3062 | + if ($track_change) { |
|
3063 | + $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
3064 | + } |
|
2903 | 3065 | |
2904 | 3066 | return true; |
2905 | 3067 | } |
3068 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) { |
|
3069 | + unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
2906 | 3070 | } |
2907 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) |
|
2908 | - unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
2909 | 3071 | } |
2910 | 3072 | |
2911 | 3073 | // If we're here we're a failure. |
@@ -2924,31 +3086,33 @@ discard block |
||
2924 | 3086 | mktree(dirname($filename), 0755); |
2925 | 3087 | $package_ftp->create_file($ftp_file); |
2926 | 3088 | $package_ftp->chmod($ftp_file, 0755); |
3089 | + } else { |
|
3090 | + $file_permissions = @fileperms($filename); |
|
2927 | 3091 | } |
2928 | - else |
|
2929 | - $file_permissions = @fileperms($filename); |
|
2930 | 3092 | |
2931 | 3093 | if ($perm_state != 'writable') |
2932 | 3094 | { |
2933 | 3095 | $package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644); |
2934 | - } |
|
2935 | - else |
|
3096 | + } else |
|
2936 | 3097 | { |
2937 | - if (!@is_writable($filename)) |
|
2938 | - $package_ftp->chmod($ftp_file, 0777); |
|
2939 | - if (!@is_writable(dirname($filename))) |
|
2940 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
3098 | + if (!@is_writable($filename)) { |
|
3099 | + $package_ftp->chmod($ftp_file, 0777); |
|
3100 | + } |
|
3101 | + if (!@is_writable(dirname($filename))) { |
|
3102 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
3103 | + } |
|
2941 | 3104 | } |
2942 | 3105 | |
2943 | 3106 | if (@is_writable($filename)) |
2944 | 3107 | { |
2945 | - if ($track_change) |
|
2946 | - $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
3108 | + if ($track_change) { |
|
3109 | + $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
3110 | + } |
|
2947 | 3111 | |
2948 | 3112 | return true; |
3113 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) { |
|
3114 | + unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
2949 | 3115 | } |
2950 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) |
|
2951 | - unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
2952 | 3116 | } |
2953 | 3117 | |
2954 | 3118 | // Oh dear, we failed if we get here. |
@@ -2966,11 +3130,13 @@ discard block |
||
2966 | 3130 | $n = strlen($pass); |
2967 | 3131 | |
2968 | 3132 | $salt = session_id(); |
2969 | - while (strlen($salt) < $n) |
|
2970 | - $salt .= session_id(); |
|
3133 | + while (strlen($salt) < $n) { |
|
3134 | + $salt .= session_id(); |
|
3135 | + } |
|
2971 | 3136 | |
2972 | - for ($i = 0; $i < $n; $i++) |
|
2973 | - $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
3137 | + for ($i = 0; $i < $n; $i++) { |
|
3138 | + $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
3139 | + } |
|
2974 | 3140 | |
2975 | 3141 | return $pass; |
2976 | 3142 | } |
@@ -2989,8 +3155,9 @@ discard block |
||
2989 | 3155 | $base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php'); |
2990 | 3156 | foreach ($base_files as $file) |
2991 | 3157 | { |
2992 | - if (file_exists($boarddir . '/' . $file)) |
|
2993 | - $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
3158 | + if (file_exists($boarddir . '/' . $file)) { |
|
3159 | + $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
3160 | + } |
|
2994 | 3161 | } |
2995 | 3162 | |
2996 | 3163 | $dirs = array( |
@@ -3007,8 +3174,9 @@ discard block |
||
3007 | 3174 | 'theme_dir' => 'theme_dir', |
3008 | 3175 | ) |
3009 | 3176 | ); |
3010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
3011 | - $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
3177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
3178 | + $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
3179 | + } |
|
3012 | 3180 | $smcFunc['db_free_result']($request); |
3013 | 3181 | |
3014 | 3182 | try |
@@ -3023,11 +3191,13 @@ discard block |
||
3023 | 3191 | |
3024 | 3192 | foreach ($iter as $entry => $dir) |
3025 | 3193 | { |
3026 | - if ($dir->isDir()) |
|
3027 | - continue; |
|
3194 | + if ($dir->isDir()) { |
|
3195 | + continue; |
|
3196 | + } |
|
3028 | 3197 | |
3029 | - if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) |
|
3030 | - continue; |
|
3198 | + if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) { |
|
3199 | + continue; |
|
3200 | + } |
|
3031 | 3201 | |
3032 | 3202 | $files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry; |
3033 | 3203 | } |
@@ -3035,10 +3205,12 @@ discard block |
||
3035 | 3205 | $obj = new ArrayObject($files); |
3036 | 3206 | $iterator = $obj->getIterator(); |
3037 | 3207 | |
3038 | - if (!file_exists($packagesdir . '/backups')) |
|
3039 | - mktree($packagesdir . '/backups', 0777); |
|
3040 | - if (!is_writable($packagesdir . '/backups')) |
|
3041 | - package_chmod($packagesdir . '/backups'); |
|
3208 | + if (!file_exists($packagesdir . '/backups')) { |
|
3209 | + mktree($packagesdir . '/backups', 0777); |
|
3210 | + } |
|
3211 | + if (!is_writable($packagesdir . '/backups')) { |
|
3212 | + package_chmod($packagesdir . '/backups'); |
|
3213 | + } |
|
3042 | 3214 | $output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id); |
3043 | 3215 | $output_ext = '.tar'; |
3044 | 3216 | $output_ext_target = '.tar.gz'; |
@@ -3046,16 +3218,18 @@ discard block |
||
3046 | 3218 | if (file_exists($output_file . $output_ext_target)) |
3047 | 3219 | { |
3048 | 3220 | $i = 2; |
3049 | - while (file_exists($output_file . '_' . $i . $output_ext_target)) |
|
3050 | - $i++; |
|
3221 | + while (file_exists($output_file . '_' . $i . $output_ext_target)) { |
|
3222 | + $i++; |
|
3223 | + } |
|
3051 | 3224 | $output_file = $output_file . '_' . $i . $output_ext; |
3225 | + } else { |
|
3226 | + $output_file .= $output_ext; |
|
3052 | 3227 | } |
3053 | - else |
|
3054 | - $output_file .= $output_ext; |
|
3055 | 3228 | |
3056 | 3229 | @set_time_limit(300); |
3057 | - if (function_exists('apache_reset_timeout')) |
|
3058 | - @apache_reset_timeout(); |
|
3230 | + if (function_exists('apache_reset_timeout')) { |
|
3231 | + @apache_reset_timeout(); |
|
3232 | + } |
|
3059 | 3233 | |
3060 | 3234 | $a = new PharData($output_file); |
3061 | 3235 | $a->buildFromIterator($iterator); |
@@ -3067,8 +3241,7 @@ discard block |
||
3067 | 3241 | */ |
3068 | 3242 | unset($a); |
3069 | 3243 | unlink($output_file); |
3070 | - } |
|
3071 | - catch (Exception $e) |
|
3244 | + } catch (Exception $e) |
|
3072 | 3245 | { |
3073 | 3246 | log_error($e->getMessage(), 'backup'); |
3074 | 3247 | |
@@ -3100,32 +3273,35 @@ discard block |
||
3100 | 3273 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
3101 | 3274 | |
3102 | 3275 | // An FTP url. We should try connecting and RETRieving it... |
3103 | - if (empty($match[1])) |
|
3104 | - return false; |
|
3105 | - elseif ($match[1] == 'ftp') |
|
3276 | + if (empty($match[1])) { |
|
3277 | + return false; |
|
3278 | + } elseif ($match[1] == 'ftp') |
|
3106 | 3279 | { |
3107 | 3280 | // Include the file containing the ftp_connection class. |
3108 | 3281 | require_once($sourcedir . '/Class-Package.php'); |
3109 | 3282 | |
3110 | 3283 | // Establish a connection and attempt to enable passive mode. |
3111 | 3284 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
3112 | - if ($ftp->error !== false || !$ftp->passive()) |
|
3113 | - return false; |
|
3285 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
3286 | + return false; |
|
3287 | + } |
|
3114 | 3288 | |
3115 | 3289 | // I want that one *points*! |
3116 | 3290 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
3117 | 3291 | |
3118 | 3292 | // Since passive mode worked (or we would have returned already!) open the connection. |
3119 | 3293 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
3120 | - if (!$fp) |
|
3121 | - return false; |
|
3294 | + if (!$fp) { |
|
3295 | + return false; |
|
3296 | + } |
|
3122 | 3297 | |
3123 | 3298 | // The server should now say something in acknowledgement. |
3124 | 3299 | $ftp->check_response(150); |
3125 | 3300 | |
3126 | 3301 | $data = ''; |
3127 | - while (!feof($fp)) |
|
3128 | - $data .= fread($fp, 4096); |
|
3302 | + while (!feof($fp)) { |
|
3303 | + $data .= fread($fp, 4096); |
|
3304 | + } |
|
3129 | 3305 | fclose($fp); |
3130 | 3306 | |
3131 | 3307 | // All done, right? Good. |
@@ -3142,22 +3318,25 @@ discard block |
||
3142 | 3318 | $fetch_data->get_url_data($url, $post_data); |
3143 | 3319 | |
3144 | 3320 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
3145 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
3146 | - $data = $fetch_data->result('body'); |
|
3147 | - else |
|
3148 | - return false; |
|
3321 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
3322 | + $data = $fetch_data->result('body'); |
|
3323 | + } else { |
|
3324 | + return false; |
|
3325 | + } |
|
3149 | 3326 | } |
3150 | 3327 | // This is more likely; a standard HTTP URL. |
3151 | 3328 | elseif (isset($match[1]) && $match[1] == 'http') |
3152 | 3329 | { |
3153 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
3154 | - $fp = $keep_alive_fp; |
|
3330 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
3331 | + $fp = $keep_alive_fp; |
|
3332 | + } |
|
3155 | 3333 | if (empty($fp)) |
3156 | 3334 | { |
3157 | 3335 | // Open the socket on the port we want... |
3158 | 3336 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
3159 | - if (!$fp) |
|
3160 | - return false; |
|
3337 | + if (!$fp) { |
|
3338 | + return false; |
|
3339 | + } |
|
3161 | 3340 | } |
3162 | 3341 | |
3163 | 3342 | if ($keep_alive) |
@@ -3172,20 +3351,21 @@ discard block |
||
3172 | 3351 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
3173 | 3352 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
3174 | 3353 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
3175 | - if ($keep_alive) |
|
3176 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
3177 | - else |
|
3178 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
3179 | - } |
|
3180 | - else |
|
3354 | + if ($keep_alive) { |
|
3355 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
3356 | + } else { |
|
3357 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
3358 | + } |
|
3359 | + } else |
|
3181 | 3360 | { |
3182 | 3361 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
3183 | 3362 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
3184 | 3363 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
3185 | - if ($keep_alive) |
|
3186 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
3187 | - else |
|
3188 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
3364 | + if ($keep_alive) { |
|
3365 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
3366 | + } else { |
|
3367 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
3368 | + } |
|
3189 | 3369 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
3190 | 3370 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
3191 | 3371 | fwrite($fp, $post_data); |
@@ -3198,30 +3378,33 @@ discard block |
||
3198 | 3378 | { |
3199 | 3379 | $header = ''; |
3200 | 3380 | $location = ''; |
3201 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
3202 | - if (strpos($header, 'Location:') !== false) |
|
3381 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
3382 | + if (strpos($header, 'Location:') !== false) |
|
3203 | 3383 | $location = trim(substr($header, strpos($header, ':') + 1)); |
3384 | + } |
|
3204 | 3385 | |
3205 | - if (empty($location)) |
|
3206 | - return false; |
|
3207 | - else |
|
3386 | + if (empty($location)) { |
|
3387 | + return false; |
|
3388 | + } else |
|
3208 | 3389 | { |
3209 | - if (!$keep_alive) |
|
3210 | - fclose($fp); |
|
3390 | + if (!$keep_alive) { |
|
3391 | + fclose($fp); |
|
3392 | + } |
|
3211 | 3393 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
3212 | 3394 | } |
3213 | 3395 | } |
3214 | 3396 | |
3215 | 3397 | // Make sure we get a 200 OK. |
3216 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
3217 | - return false; |
|
3398 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
3399 | + return false; |
|
3400 | + } |
|
3218 | 3401 | |
3219 | 3402 | // Skip the headers... |
3220 | 3403 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
3221 | 3404 | { |
3222 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
3223 | - $content_length = $match[1]; |
|
3224 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
3405 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
3406 | + $content_length = $match[1]; |
|
3407 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
3225 | 3408 | { |
3226 | 3409 | $keep_alive_dom = null; |
3227 | 3410 | $keep_alive = false; |
@@ -3233,19 +3416,20 @@ discard block |
||
3233 | 3416 | $data = ''; |
3234 | 3417 | if (isset($content_length)) |
3235 | 3418 | { |
3236 | - while (!feof($fp) && strlen($data) < $content_length) |
|
3237 | - $data .= fread($fp, $content_length - strlen($data)); |
|
3238 | - } |
|
3239 | - else |
|
3419 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
3420 | + $data .= fread($fp, $content_length - strlen($data)); |
|
3421 | + } |
|
3422 | + } else |
|
3240 | 3423 | { |
3241 | - while (!feof($fp)) |
|
3242 | - $data .= fread($fp, 4096); |
|
3424 | + while (!feof($fp)) { |
|
3425 | + $data .= fread($fp, 4096); |
|
3426 | + } |
|
3243 | 3427 | } |
3244 | 3428 | |
3245 | - if (!$keep_alive) |
|
3246 | - fclose($fp); |
|
3247 | - } |
|
3248 | - else |
|
3429 | + if (!$keep_alive) { |
|
3430 | + fclose($fp); |
|
3431 | + } |
|
3432 | + } else |
|
3249 | 3433 | { |
3250 | 3434 | // Umm, this shouldn't happen? |
3251 | 3435 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -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 | } |
@@ -22,22 +22,24 @@ discard block |
||
22 | 22 | <script>'; |
23 | 23 | |
24 | 24 | // When using Go Back due to fatal_error, allow the form to be re-submitted with changes. |
25 | - if (isBrowser('is_firefox')) |
|
26 | - echo ' |
|
25 | + if (isBrowser('is_firefox')) { |
|
26 | + echo ' |
|
27 | 27 | window.addEventListener("pageshow", reActivate, false);'; |
28 | + } |
|
28 | 29 | |
29 | 30 | // Start with message icons - and any missing from this theme. |
30 | 31 | echo ' |
31 | 32 | var icon_urls = {'; |
32 | - foreach ($context['icons'] as $icon) |
|
33 | - echo ' |
|
33 | + foreach ($context['icons'] as $icon) { |
|
34 | + echo ' |
|
34 | 35 | \'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ','; |
36 | + } |
|
35 | 37 | echo ' |
36 | 38 | };'; |
37 | 39 | |
38 | 40 | // If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations. |
39 | - if ($context['make_poll']) |
|
40 | - echo ' |
|
41 | + if ($context['make_poll']) { |
|
42 | + echo ' |
|
41 | 43 | var pollOptionNum = 0, pollTabIndex; |
42 | 44 | var pollOptionId = ', $context['last_choice_id'], '; |
43 | 45 | function addPollOption() |
@@ -56,11 +58,13 @@ discard block |
||
56 | 58 | |
57 | 59 | setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), '); |
58 | 60 | }'; |
61 | + } |
|
59 | 62 | |
60 | 63 | // If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here. |
61 | - if ($context['make_event']) |
|
62 | - echo ' |
|
64 | + if ($context['make_event']) { |
|
65 | + echo ' |
|
63 | 66 | var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];'; |
67 | + } |
|
64 | 68 | |
65 | 69 | // End of the javascript, start the form and display the link tree. |
66 | 70 | echo ' |
@@ -80,9 +84,10 @@ discard block |
||
80 | 84 | </div> |
81 | 85 | </div><br>'; |
82 | 86 | |
83 | - if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) |
|
84 | - echo ' |
|
87 | + if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) { |
|
88 | + echo ' |
|
85 | 89 | <input type="hidden" name="eventid" value="', $context['event']['id'], '">'; |
90 | + } |
|
86 | 91 | |
87 | 92 | // Start the main table. |
88 | 93 | echo ' |
@@ -117,18 +122,20 @@ discard block |
||
117 | 122 | } |
118 | 123 | |
119 | 124 | // If it's locked, show a message to warn the replier. |
120 | - if (!empty($context['locked'])) |
|
121 | - echo ' |
|
125 | + if (!empty($context['locked'])) { |
|
126 | + echo ' |
|
122 | 127 | <p class="errorbox"> |
123 | 128 | ', $txt['topic_locked_no_reply'], ' |
124 | 129 | </p>'; |
130 | + } |
|
125 | 131 | |
126 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
127 | - echo ' |
|
132 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
133 | + echo ' |
|
128 | 134 | <div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>', |
129 | 135 | sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), ' |
130 | 136 | ', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), ' |
131 | 137 | </div>'; |
138 | + } |
|
132 | 139 | |
133 | 140 | // The post header... important stuff |
134 | 141 | echo ' |
@@ -180,9 +187,10 @@ discard block |
||
180 | 187 | { |
181 | 188 | echo ' |
182 | 189 | <optgroup label="', $category['name'], '">'; |
183 | - foreach ($category['boards'] as $board) |
|
184 | - echo ' |
|
190 | + foreach ($category['boards'] as $board) { |
|
191 | + echo ' |
|
185 | 192 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>'; |
193 | + } |
|
186 | 194 | echo ' |
187 | 195 | </optgroup>'; |
188 | 196 | } |
@@ -218,9 +226,10 @@ discard block |
||
218 | 226 | <span class="label">', $txt['calendar_timezone'], '</span> |
219 | 227 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
220 | 228 | |
221 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
222 | - echo ' |
|
229 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
230 | + echo ' |
|
223 | 231 | <option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
232 | + } |
|
224 | 233 | |
225 | 234 | echo ' |
226 | 235 | </select> |
@@ -286,14 +295,15 @@ discard block |
||
286 | 295 | <input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check"> |
287 | 296 | </dd>'; |
288 | 297 | |
289 | - if ($context['poll_options']['guest_vote_enabled']) |
|
290 | - echo ' |
|
298 | + if ($context['poll_options']['guest_vote_enabled']) { |
|
299 | + echo ' |
|
291 | 300 | <dt> |
292 | 301 | <label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label> |
293 | 302 | </dt> |
294 | 303 | <dd> |
295 | 304 | <input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check"> |
296 | 305 | </dd>'; |
306 | + } |
|
297 | 307 | |
298 | 308 | echo ' |
299 | 309 | <dt> |
@@ -314,8 +324,8 @@ discard block |
||
314 | 324 | ', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'); |
315 | 325 | |
316 | 326 | // If we're editing and displaying edit details, show a box where they can say why |
317 | - if (isset($context['editing']) && $modSettings['show_modify']) |
|
318 | - echo ' |
|
327 | + if (isset($context['editing']) && $modSettings['show_modify']) { |
|
328 | + echo ' |
|
319 | 329 | <dl> |
320 | 330 | <dt class="clear"> |
321 | 331 | <span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span> |
@@ -324,20 +334,23 @@ discard block |
||
324 | 334 | <input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text"> |
325 | 335 | </dd> |
326 | 336 | </dl>'; |
337 | + } |
|
327 | 338 | |
328 | 339 | // If this message has been edited in the past - display when it was. |
329 | - if (isset($context['last_modified'])) |
|
330 | - echo ' |
|
340 | + if (isset($context['last_modified'])) { |
|
341 | + echo ' |
|
331 | 342 | <div class="padding smalltext"> |
332 | 343 | ', $context['last_modified_text'], ' |
333 | 344 | </div>'; |
345 | + } |
|
334 | 346 | |
335 | 347 | // If the admin has enabled the hiding of the additional options - show a link and image for it. |
336 | - if (!empty($modSettings['additional_options_collapsable'])) |
|
337 | - echo ' |
|
348 | + if (!empty($modSettings['additional_options_collapsable'])) { |
|
349 | + echo ' |
|
338 | 350 | <div id="postAdditionalOptionsHeader"> |
339 | 351 | <strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong> |
340 | 352 | </div>'; |
353 | + } |
|
341 | 354 | |
342 | 355 | echo ' |
343 | 356 | <div id="postAdditionalOptions">'; |
@@ -369,19 +382,21 @@ discard block |
||
369 | 382 | <input type="hidden" name="attach_del[]" value="0"> |
370 | 383 | ', $txt['uncheck_unwatchd_attach'], ': |
371 | 384 | </dd>'; |
372 | - foreach ($context['current_attachments'] as $attachment) |
|
373 | - echo ' |
|
385 | + foreach ($context['current_attachments'] as $attachment) { |
|
386 | + echo ' |
|
374 | 387 | <dd class="smalltext"> |
375 | 388 | <label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''), |
376 | 389 | !empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label> |
377 | 390 | </dd>'; |
391 | + } |
|
378 | 392 | |
379 | 393 | echo ' |
380 | 394 | </dl>'; |
381 | 395 | |
382 | - if (!empty($context['files_in_session_warning'])) |
|
383 | - echo ' |
|
396 | + if (!empty($context['files_in_session_warning'])) { |
|
397 | + echo ' |
|
384 | 398 | <div class="smalltext">', $context['files_in_session_warning'], '</div>'; |
399 | + } |
|
385 | 400 | } |
386 | 401 | |
387 | 402 | // Is the user allowed to post any additional ones? If so give them the boxes to do it! |
@@ -434,8 +449,8 @@ discard block |
||
434 | 449 | ', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">'); |
435 | 450 | |
436 | 451 | // Show more boxes if they aren't approaching that limit. |
437 | - if ($context['num_allowed_attachments'] > 1) |
|
438 | - echo ' |
|
452 | + if ($context['num_allowed_attachments'] > 1) { |
|
453 | + echo ' |
|
439 | 454 | <script> |
440 | 455 | var allowed_attachments = ', $context['num_allowed_attachments'], '; |
441 | 456 | var current_attachment = 1; |
@@ -456,9 +471,10 @@ discard block |
||
456 | 471 | </div> |
457 | 472 | </div> |
458 | 473 | </dd>'; |
459 | - else |
|
460 | - echo ' |
|
474 | + } else { |
|
475 | + echo ' |
|
461 | 476 | </dd>'; |
477 | + } |
|
462 | 478 | |
463 | 479 | // Add any template changes for an alternative upload system here. |
464 | 480 | call_integration_hook('integrate_upload_template'); |
@@ -467,21 +483,25 @@ discard block |
||
467 | 483 | <dd class="smalltext">'; |
468 | 484 | |
469 | 485 | // Show some useful information such as allowed extensions, maximum size and amount of attachments allowed. |
470 | - if (!empty($modSettings['attachmentCheckExtensions'])) |
|
471 | - echo ' |
|
486 | + if (!empty($modSettings['attachmentCheckExtensions'])) { |
|
487 | + echo ' |
|
472 | 488 | ', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>'; |
489 | + } |
|
473 | 490 | |
474 | - if (!empty($context['attachment_restrictions'])) |
|
475 | - echo ' |
|
491 | + if (!empty($context['attachment_restrictions'])) { |
|
492 | + echo ' |
|
476 | 493 | ', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>'; |
494 | + } |
|
477 | 495 | |
478 | - if ($context['num_allowed_attachments'] == 0) |
|
479 | - echo ' |
|
496 | + if ($context['num_allowed_attachments'] == 0) { |
|
497 | + echo ' |
|
480 | 498 | ', $txt['attach_limit_nag'], '<br>'; |
499 | + } |
|
481 | 500 | |
482 | - if (!$context['can_post_attachment_unapproved']) |
|
483 | - echo ' |
|
501 | + if (!$context['can_post_attachment_unapproved']) { |
|
502 | + echo ' |
|
484 | 503 | <span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>'; |
504 | + } |
|
485 | 505 | |
486 | 506 | echo ' |
487 | 507 | </dd> |
@@ -504,10 +524,11 @@ discard block |
||
504 | 524 | <dt><strong>', $txt['subject'], '</strong></dt> |
505 | 525 | <dd><strong>', $txt['draft_saved_on'], '</strong></dd>'; |
506 | 526 | |
507 | - foreach ($context['drafts'] as $draft) |
|
508 | - echo ' |
|
527 | + foreach ($context['drafts'] as $draft) { |
|
528 | + echo ' |
|
509 | 529 | <dt>', $draft['link'], '</dt> |
510 | 530 | <dd>', $draft['poster_time'], '</dd>'; |
531 | + } |
|
511 | 532 | echo ' |
512 | 533 | </dl> |
513 | 534 | </div>'; |
@@ -532,9 +553,10 @@ discard block |
||
532 | 553 | ', template_control_richedit_buttons($context['post_box_name']); |
533 | 554 | |
534 | 555 | // Option to delete an event if user is editing one. |
535 | - if ($context['make_event'] && !$context['event']['new']) |
|
536 | - echo ' |
|
556 | + if ($context['make_event'] && !$context['event']['new']) { |
|
557 | + echo ' |
|
537 | 558 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">'; |
559 | + } |
|
538 | 560 | |
539 | 561 | echo ' |
540 | 562 | </span> |
@@ -543,9 +565,10 @@ discard block |
||
543 | 565 | <br class="clear">'; |
544 | 566 | |
545 | 567 | // Assuming this isn't a new topic pass across the last message id. |
546 | - if (isset($context['topic_last_message'])) |
|
547 | - echo ' |
|
568 | + if (isset($context['topic_last_message'])) { |
|
569 | + echo ' |
|
548 | 570 | <input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">'; |
571 | + } |
|
549 | 572 | |
550 | 573 | echo ' |
551 | 574 | <input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '"> |
@@ -687,9 +710,10 @@ discard block |
||
687 | 710 | |
688 | 711 | newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">« <strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \' »</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';'; |
689 | 712 | |
690 | - if ($context['can_quote']) |
|
691 | - echo ' |
|
713 | + if ($context['can_quote']) { |
|
714 | + echo ' |
|
692 | 715 | newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';'; |
716 | + } |
|
693 | 717 | |
694 | 718 | echo ' |
695 | 719 | newPostsHTML += \'<br class="clear">\'; |
@@ -732,8 +756,8 @@ discard block |
||
732 | 756 | }'; |
733 | 757 | |
734 | 758 | // Code for showing and hiding additional options. |
735 | - if (!empty($modSettings['additional_options_collapsable'])) |
|
736 | - echo ' |
|
759 | + if (!empty($modSettings['additional_options_collapsable'])) { |
|
760 | + echo ' |
|
737 | 761 | var oSwapAdditionalOptions = new smc_Toggle({ |
738 | 762 | bToggleEnabled: true, |
739 | 763 | bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ', |
@@ -761,10 +785,11 @@ discard block |
||
761 | 785 | } |
762 | 786 | ] |
763 | 787 | });'; |
788 | + } |
|
764 | 789 | |
765 | 790 | // Code for showing and hiding drafts |
766 | - if (!empty($context['drafts'])) |
|
767 | - echo ' |
|
791 | + if (!empty($context['drafts'])) { |
|
792 | + echo ' |
|
768 | 793 | var oSwapDraftOptions = new smc_Toggle({ |
769 | 794 | bToggleEnabled: true, |
770 | 795 | bCurrentlyCollapsed: true, |
@@ -786,6 +811,7 @@ discard block |
||
786 | 811 | } |
787 | 812 | ] |
788 | 813 | });'; |
814 | + } |
|
789 | 815 | |
790 | 816 | echo ' |
791 | 817 | var oEditorID = "', $context['post_box_name'] ,'"; |
@@ -806,8 +832,9 @@ discard block |
||
806 | 832 | foreach ($context['previous_posts'] as $post) |
807 | 833 | { |
808 | 834 | $ignoring = false; |
809 | - if (!empty($post['is_ignored'])) |
|
810 | - $ignored_posts[] = $ignoring = $post['id']; |
|
835 | + if (!empty($post['is_ignored'])) { |
|
836 | + $ignored_posts[] = $ignoring = $post['id']; |
|
837 | + } |
|
811 | 838 | |
812 | 839 | echo ' |
813 | 840 | <div class="windowbg"> |
@@ -990,10 +1017,10 @@ discard block |
||
990 | 1017 | <div id="temporary_posting_area" style="display: none;"></div> |
991 | 1018 | <script>'; |
992 | 1019 | |
993 | - if ($context['close_window']) |
|
994 | - echo ' |
|
1020 | + if ($context['close_window']) { |
|
1021 | + echo ' |
|
995 | 1022 | window.close();'; |
996 | - else |
|
1023 | + } else |
|
997 | 1024 | { |
998 | 1025 | // Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;). |
999 | 1026 | echo ' |
@@ -1047,11 +1074,12 @@ discard block |
||
1047 | 1074 | </p> |
1048 | 1075 | <ul>'; |
1049 | 1076 | |
1050 | - foreach ($context['groups'] as $group) |
|
1051 | - echo ' |
|
1077 | + foreach ($context['groups'] as $group) { |
|
1078 | + echo ' |
|
1052 | 1079 | <li> |
1053 | 1080 | <label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em> |
1054 | 1081 | </li>'; |
1082 | + } |
|
1055 | 1083 | |
1056 | 1084 | echo ' |
1057 | 1085 | <li> |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | </div> |
417 | 417 | <div class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></div> |
418 | 418 | <div class="attach-ui"> |
419 | - <a data-dz-remove class="button_submit cancel">', $txt['modify_cancel'] ,'</a> |
|
420 | - <a class="button_submit upload">', $txt['upload'] ,'</a> |
|
419 | + <a data-dz-remove class="button_submit cancel">', $txt['modify_cancel'], '</a> |
|
420 | + <a class="button_submit upload">', $txt['upload'], '</a> |
|
421 | 421 | </div> |
422 | 422 | </div> |
423 | 423 | </div> |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | </dt> |
436 | 436 | <dd class="smalltext fallback"> |
437 | 437 | <div id="attachUpload" class="descbox"> |
438 | - <h5>', $txt['attach_drop_zone'] ,'</h5> |
|
439 | - <a class="button_submit" id="attach-cancelAll">', $txt['attached_cancelAll'] ,'</a> |
|
440 | - <a class="button_submit" id="attach-uploadAll">', $txt['attached_uploadAll'] ,'</a> |
|
441 | - <a class="button_submit fileinput-button">', $txt['attach_add'] ,'</a> |
|
438 | + <h5>', $txt['attach_drop_zone'], '</h5> |
|
439 | + <a class="button_submit" id="attach-cancelAll">', $txt['attached_cancelAll'], '</a> |
|
440 | + <a class="button_submit" id="attach-uploadAll">', $txt['attached_uploadAll'], '</a> |
|
441 | + <a class="button_submit fileinput-button">', $txt['attach_add'], '</a> |
|
442 | 442 | <div id="total-progress" class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></div> |
443 | 443 | <div class="fallback"> |
444 | 444 | <input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="input_file fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>) |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | // Option to delete an event if user is editing one. |
546 | 546 | if ($context['make_event'] && !$context['event']['new']) |
547 | 547 | echo ' |
548 | - <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">'; |
|
548 | + <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'], '" class="button_submit you_sure">'; |
|
549 | 549 | |
550 | 550 | echo ' |
551 | 551 | </span> |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | });'; |
800 | 800 | |
801 | 801 | echo ' |
802 | - var oEditorID = "', $context['post_box_name'] ,'"; |
|
802 | + var oEditorID = "', $context['post_box_name'], '"; |
|
803 | 803 | var oEditorObject = oEditorHandle_', $context['post_box_name'], '; |
804 | 804 | </script>'; |
805 | 805 | |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | { |
832 | 832 | echo ' |
833 | 833 | <ul class="quickbuttons" id="msg_', $post['id'], '_quote"> |
834 | - <li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li> |
|
834 | + <li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'], '</a></li> |
|
835 | 835 | <li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li> |
836 | 836 | </ul>'; |
837 | 837 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | <head> |
919 | 919 | <meta charset="', $context['character_set'], '"> |
920 | 920 | <title>', $txt['spell_check'], '</title> |
921 | - <link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'] ,'"> |
|
921 | + <link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'], '"> |
|
922 | 922 | <style> |
923 | 923 | body, td |
924 | 924 | { |
@@ -951,8 +951,8 @@ discard block |
||
951 | 951 | var spell_formname = window.opener.spell_formname; |
952 | 952 | var spell_fieldname = window.opener.spell_fieldname; |
953 | 953 | </script> |
954 | - <script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'] ,'"></script> |
|
955 | - <script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script> |
|
954 | + <script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'], '"></script> |
|
955 | + <script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'], '"></script> |
|
956 | 956 | <script> |
957 | 957 | ', $context['spell_js'], ' |
958 | 958 | </script> |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | <head> |
995 | 995 | <meta charset="', $context['character_set'], '"> |
996 | 996 | <title>', $txt['retrieving_quote'], '</title> |
997 | - <script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script> |
|
997 | + <script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'], '"></script> |
|
998 | 998 | </head> |
999 | 999 | <body> |
1000 | 1000 | ', $txt['retrieving_quote'], ' |
@@ -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 | } |
@@ -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'], |
@@ -239,7 +239,7 @@ |
||
239 | 239 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
240 | 240 | $fts_language[$row['cfgname']] = $row['cfgname']; |
241 | 241 | |
242 | - $config_vars = array_merge ($config_vars, array( |
|
242 | + $config_vars = array_merge($config_vars, array( |
|
243 | 243 | '', |
244 | 244 | array('search_language', $txt['search_language'], 'db', 'select', $fts_language, 'pgFulltextSearch') |
245 | 245 | ) |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | * @version 2.1 Beta 3 |
60 | 60 | */ |
61 | 61 | |
62 | -if (!defined('SMF')) |
|
62 | +if (!defined('SMF')) { |
|
63 | 63 | die('No direct access...'); |
64 | +} |
|
64 | 65 | |
65 | 66 | /** |
66 | 67 | * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
@@ -111,10 +112,11 @@ discard block |
||
111 | 112 | $settings_not_writable = !is_writable($boarddir . '/Settings.php'); |
112 | 113 | $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
113 | 114 | |
114 | - if ($settings_not_writable) |
|
115 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
116 | - elseif ($settings_backup_fail) |
|
117 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
115 | + if ($settings_not_writable) { |
|
116 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
117 | + } elseif ($settings_backup_fail) { |
|
118 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $context['settings_not_writable'] = $settings_not_writable; |
120 | 122 | |
@@ -168,8 +170,9 @@ discard block |
||
168 | 170 | |
169 | 171 | call_integration_hook('integrate_general_settings', array(&$config_vars)); |
170 | 172 | |
171 | - if ($return_config) |
|
172 | - return $config_vars; |
|
173 | + if ($return_config) { |
|
174 | + return $config_vars; |
|
175 | + } |
|
173 | 176 | |
174 | 177 | // Setup the template stuff. |
175 | 178 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save'; |
@@ -186,8 +189,9 @@ discard block |
||
186 | 189 | $registerSMStats = registerSMStats(); |
187 | 190 | |
188 | 191 | // Failed to register, disable it again. |
189 | - if (empty($registerSMStats)) |
|
190 | - $_POST['enable_sm_stats'] = 0; |
|
192 | + if (empty($registerSMStats)) { |
|
193 | + $_POST['enable_sm_stats'] = 0; |
|
194 | + } |
|
191 | 195 | } |
192 | 196 | |
193 | 197 | saveSettings($config_vars); |
@@ -248,8 +252,9 @@ discard block |
||
248 | 252 | $request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array()); |
249 | 253 | $fts_language = array(); |
250 | 254 | |
251 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
252 | - $fts_language[$row['cfgname']] = $row['cfgname']; |
|
255 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
256 | + $fts_language[$row['cfgname']] = $row['cfgname']; |
|
257 | + } |
|
253 | 258 | |
254 | 259 | $config_vars = array_merge ($config_vars, array( |
255 | 260 | '', |
@@ -261,8 +266,9 @@ discard block |
||
261 | 266 | |
262 | 267 | call_integration_hook('integrate_database_settings', array(&$config_vars)); |
263 | 268 | |
264 | - if ($return_config) |
|
265 | - return $config_vars; |
|
269 | + if ($return_config) { |
|
270 | + return $config_vars; |
|
271 | + } |
|
266 | 272 | |
267 | 273 | // Setup the template stuff. |
268 | 274 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save'; |
@@ -337,13 +343,15 @@ discard block |
||
337 | 343 | hideGlobalCookies(); |
338 | 344 | });', true); |
339 | 345 | |
340 | - if (empty($user_settings['tfa_secret'])) |
|
341 | - addInlineJavaScript(''); |
|
346 | + if (empty($user_settings['tfa_secret'])) { |
|
347 | + addInlineJavaScript(''); |
|
348 | + } |
|
342 | 349 | |
343 | 350 | call_integration_hook('integrate_cookie_settings', array(&$config_vars)); |
344 | 351 | |
345 | - if ($return_config) |
|
346 | - return $config_vars; |
|
352 | + if ($return_config) { |
|
353 | + return $config_vars; |
|
354 | + } |
|
347 | 355 | |
348 | 356 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save'; |
349 | 357 | $context['settings_title'] = $txt['cookies_sessions_settings']; |
@@ -354,11 +362,13 @@ discard block |
||
354 | 362 | call_integration_hook('integrate_save_cookie_settings'); |
355 | 363 | |
356 | 364 | // Local and global do not play nicely together. |
357 | - if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) |
|
358 | - unset ($_POST['globalCookies']); |
|
365 | + if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) { |
|
366 | + unset ($_POST['globalCookies']); |
|
367 | + } |
|
359 | 368 | |
360 | - if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) |
|
361 | - fatal_lang_error('invalid_cookie_domain', false); |
|
369 | + if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) { |
|
370 | + fatal_lang_error('invalid_cookie_domain', false); |
|
371 | + } |
|
362 | 372 | |
363 | 373 | saveSettings($config_vars); |
364 | 374 | |
@@ -441,8 +451,9 @@ discard block |
||
441 | 451 | |
442 | 452 | call_integration_hook('integrate_general_security_settings', array(&$config_vars)); |
443 | 453 | |
444 | - if ($return_config) |
|
445 | - return $config_vars; |
|
454 | + if ($return_config) { |
|
455 | + return $config_vars; |
|
456 | + } |
|
446 | 457 | |
447 | 458 | // Saving? |
448 | 459 | if (isset($_GET['save'])) |
@@ -481,8 +492,7 @@ discard block |
||
481 | 492 | $txt['cache_settings_message'] = $txt['detected_no_caching']; |
482 | 493 | $cache_level = array($txt['cache_off']); |
483 | 494 | $detected['none'] = $txt['cache_off']; |
484 | - } |
|
485 | - else |
|
495 | + } else |
|
486 | 496 | { |
487 | 497 | $txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected)); |
488 | 498 | $cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']); |
@@ -519,8 +529,9 @@ discard block |
||
519 | 529 | } |
520 | 530 | } |
521 | 531 | } |
522 | - if ($return_config) |
|
523 | - return $config_vars; |
|
532 | + if ($return_config) { |
|
533 | + return $config_vars; |
|
534 | + } |
|
524 | 535 | |
525 | 536 | // Saving again? |
526 | 537 | if (isset($_GET['save'])) |
@@ -548,8 +559,9 @@ discard block |
||
548 | 559 | $context['save_disabled'] = $context['settings_not_writable']; |
549 | 560 | |
550 | 561 | // Decide what message to show. |
551 | - if (!$context['save_disabled']) |
|
552 | - $context['settings_message'] = $txt['caching_information']; |
|
562 | + if (!$context['save_disabled']) { |
|
563 | + $context['settings_message'] = $txt['caching_information']; |
|
564 | + } |
|
553 | 565 | |
554 | 566 | // Prepare the template. |
555 | 567 | prepareServerSettingsContext($config_vars); |
@@ -572,24 +584,25 @@ discard block |
||
572 | 584 | if (stripos(PHP_OS, 'win') === 0) |
573 | 585 | { |
574 | 586 | $context['settings_message'] = $txt['loadavg_disabled_windows']; |
575 | - if (isset($_GET['save'])) |
|
576 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
577 | - } |
|
578 | - elseif (stripos(PHP_OS, 'darwin') === 0) |
|
587 | + if (isset($_GET['save'])) { |
|
588 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
589 | + } |
|
590 | + } elseif (stripos(PHP_OS, 'darwin') === 0) |
|
579 | 591 | { |
580 | 592 | $context['settings_message'] = $txt['loadavg_disabled_osx']; |
581 | - if (isset($_GET['save'])) |
|
582 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
583 | - } |
|
584 | - else |
|
593 | + if (isset($_GET['save'])) { |
|
594 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
595 | + } |
|
596 | + } else |
|
585 | 597 | { |
586 | 598 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
587 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) |
|
588 | - $modSettings['load_average'] = (float) $matches[1]; |
|
589 | - elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) |
|
590 | - $modSettings['load_average'] = (float) $matches[1]; |
|
591 | - else |
|
592 | - unset($modSettings['load_average']); |
|
599 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) { |
|
600 | + $modSettings['load_average'] = (float) $matches[1]; |
|
601 | + } elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) { |
|
602 | + $modSettings['load_average'] = (float) $matches[1]; |
|
603 | + } else { |
|
604 | + unset($modSettings['load_average']); |
|
605 | + } |
|
593 | 606 | |
594 | 607 | if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
595 | 608 | { |
@@ -625,8 +638,9 @@ discard block |
||
625 | 638 | |
626 | 639 | call_integration_hook('integrate_loadavg_settings', array(&$config_vars)); |
627 | 640 | |
628 | - if ($return_config) |
|
629 | - return $config_vars; |
|
641 | + if ($return_config) { |
|
642 | + return $config_vars; |
|
643 | + } |
|
630 | 644 | |
631 | 645 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save'; |
632 | 646 | $context['settings_title'] = $txt['load_balancing_settings']; |
@@ -637,24 +651,27 @@ discard block |
||
637 | 651 | // Stupidity is not allowed. |
638 | 652 | foreach ($_POST as $key => $value) |
639 | 653 | { |
640 | - if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) |
|
641 | - continue; |
|
642 | - else |
|
643 | - $_POST[$key] = (float) $value; |
|
644 | - |
|
645 | - if ($key == 'loadavg_auto_opt' && $value <= 1) |
|
646 | - $_POST['loadavg_auto_opt'] = 1.0; |
|
647 | - elseif ($key == 'loadavg_forum' && $value < 10) |
|
648 | - $_POST['loadavg_forum'] = 10.0; |
|
649 | - elseif ($value < 2) |
|
650 | - $_POST[$key] = 2.0; |
|
654 | + if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) { |
|
655 | + continue; |
|
656 | + } else { |
|
657 | + $_POST[$key] = (float) $value; |
|
658 | + } |
|
659 | + |
|
660 | + if ($key == 'loadavg_auto_opt' && $value <= 1) { |
|
661 | + $_POST['loadavg_auto_opt'] = 1.0; |
|
662 | + } elseif ($key == 'loadavg_forum' && $value < 10) { |
|
663 | + $_POST['loadavg_forum'] = 10.0; |
|
664 | + } elseif ($value < 2) { |
|
665 | + $_POST[$key] = 2.0; |
|
666 | + } |
|
651 | 667 | } |
652 | 668 | |
653 | 669 | call_integration_hook('integrate_save_loadavg_settings'); |
654 | 670 | |
655 | 671 | saveDBSettings($config_vars); |
656 | - if (!isset($_SESSION['adm-save'])) |
|
657 | - $_SESSION['adm-save'] = true; |
|
672 | + if (!isset($_SESSION['adm-save'])) { |
|
673 | + $_SESSION['adm-save'] = true; |
|
674 | + } |
|
658 | 675 | redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
659 | 676 | } |
660 | 677 | |
@@ -690,10 +707,11 @@ discard block |
||
690 | 707 | |
691 | 708 | if (isset($_SESSION['adm-save'])) |
692 | 709 | { |
693 | - if ($_SESSION['adm-save'] === true) |
|
694 | - $context['saved_successful'] = true; |
|
695 | - else |
|
696 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
710 | + if ($_SESSION['adm-save'] === true) { |
|
711 | + $context['saved_successful'] = true; |
|
712 | + } else { |
|
713 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
714 | + } |
|
697 | 715 | |
698 | 716 | unset($_SESSION['adm-save']); |
699 | 717 | } |
@@ -701,9 +719,9 @@ discard block |
||
701 | 719 | $context['config_vars'] = array(); |
702 | 720 | foreach ($config_vars as $identifier => $config_var) |
703 | 721 | { |
704 | - if (!is_array($config_var) || !isset($config_var[1])) |
|
705 | - $context['config_vars'][] = $config_var; |
|
706 | - else |
|
722 | + if (!is_array($config_var) || !isset($config_var[1])) { |
|
723 | + $context['config_vars'][] = $config_var; |
|
724 | + } else |
|
707 | 725 | { |
708 | 726 | $varname = $config_var[0]; |
709 | 727 | global $$varname; |
@@ -738,16 +756,19 @@ discard block |
||
738 | 756 | if ($config_var[3] == 'int' || $config_var[3] == 'float') |
739 | 757 | { |
740 | 758 | // Default to a min of 0 if one isn't set |
741 | - if (isset($config_var['min'])) |
|
742 | - $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
743 | - else |
|
744 | - $context['config_vars'][$config_var[0]]['min'] = 0; |
|
759 | + if (isset($config_var['min'])) { |
|
760 | + $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
761 | + } else { |
|
762 | + $context['config_vars'][$config_var[0]]['min'] = 0; |
|
763 | + } |
|
745 | 764 | |
746 | - if (isset($config_var['max'])) |
|
747 | - $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
765 | + if (isset($config_var['max'])) { |
|
766 | + $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
767 | + } |
|
748 | 768 | |
749 | - if (isset($config_var['step'])) |
|
750 | - $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
769 | + if (isset($config_var['step'])) { |
|
770 | + $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
771 | + } |
|
751 | 772 | } |
752 | 773 | |
753 | 774 | // If this is a select box handle any data. |
@@ -755,12 +776,13 @@ discard block |
||
755 | 776 | { |
756 | 777 | // If it's associative |
757 | 778 | $config_values = array_values($config_var[4]); |
758 | - if (isset($config_values[0]) && is_array($config_values[0])) |
|
759 | - $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
760 | - else |
|
779 | + if (isset($config_values[0]) && is_array($config_values[0])) { |
|
780 | + $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
781 | + } else |
|
761 | 782 | { |
762 | - foreach ($config_var[4] as $key => $item) |
|
763 | - $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
783 | + foreach ($config_var[4] as $key => $item) { |
|
784 | + $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
785 | + } |
|
764 | 786 | } |
765 | 787 | } |
766 | 788 | } |
@@ -785,10 +807,11 @@ discard block |
||
785 | 807 | |
786 | 808 | if (isset($_SESSION['adm-save'])) |
787 | 809 | { |
788 | - if ($_SESSION['adm-save'] === true) |
|
789 | - $context['saved_successful'] = true; |
|
790 | - else |
|
791 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
810 | + if ($_SESSION['adm-save'] === true) { |
|
811 | + $context['saved_successful'] = true; |
|
812 | + } else { |
|
813 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
814 | + } |
|
792 | 815 | |
793 | 816 | unset($_SESSION['adm-save']); |
794 | 817 | } |
@@ -800,26 +823,30 @@ discard block |
||
800 | 823 | foreach ($config_vars as $config_var) |
801 | 824 | { |
802 | 825 | // HR? |
803 | - if (!is_array($config_var)) |
|
804 | - $context['config_vars'][] = $config_var; |
|
805 | - else |
|
826 | + if (!is_array($config_var)) { |
|
827 | + $context['config_vars'][] = $config_var; |
|
828 | + } else |
|
806 | 829 | { |
807 | 830 | // If it has no name it doesn't have any purpose! |
808 | - if (empty($config_var[1])) |
|
809 | - continue; |
|
831 | + if (empty($config_var[1])) { |
|
832 | + continue; |
|
833 | + } |
|
810 | 834 | |
811 | 835 | // Special case for inline permissions |
812 | - if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) |
|
813 | - $inlinePermissions[] = $config_var[1]; |
|
814 | - elseif ($config_var[0] == 'permissions') |
|
815 | - continue; |
|
836 | + if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) { |
|
837 | + $inlinePermissions[] = $config_var[1]; |
|
838 | + } elseif ($config_var[0] == 'permissions') { |
|
839 | + continue; |
|
840 | + } |
|
816 | 841 | |
817 | - if ($config_var[0] == 'boards') |
|
818 | - $board_list = true; |
|
842 | + if ($config_var[0] == 'boards') { |
|
843 | + $board_list = true; |
|
844 | + } |
|
819 | 845 | |
820 | 846 | // Are we showing the BBC selection box? |
821 | - if ($config_var[0] == 'bbc') |
|
822 | - $bbcChoice[] = $config_var[1]; |
|
847 | + if ($config_var[0] == 'bbc') { |
|
848 | + $bbcChoice[] = $config_var[1]; |
|
849 | + } |
|
823 | 850 | |
824 | 851 | // We need to do some parsing of the value before we pass it in. |
825 | 852 | if (isset($modSettings[$config_var[1]])) |
@@ -838,8 +865,7 @@ discard block |
||
838 | 865 | default: |
839 | 866 | $value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]); |
840 | 867 | } |
841 | - } |
|
842 | - else |
|
868 | + } else |
|
843 | 869 | { |
844 | 870 | // Darn, it's empty. What type is expected? |
845 | 871 | switch ($config_var[0]) |
@@ -879,16 +905,19 @@ discard block |
||
879 | 905 | if ($config_var[0] == 'int' || $config_var[0] == 'float') |
880 | 906 | { |
881 | 907 | // Default to a min of 0 if one isn't set |
882 | - if (isset($config_var['min'])) |
|
883 | - $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
884 | - else |
|
885 | - $context['config_vars'][$config_var[1]]['min'] = 0; |
|
908 | + if (isset($config_var['min'])) { |
|
909 | + $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
910 | + } else { |
|
911 | + $context['config_vars'][$config_var[1]]['min'] = 0; |
|
912 | + } |
|
886 | 913 | |
887 | - if (isset($config_var['max'])) |
|
888 | - $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
914 | + if (isset($config_var['max'])) { |
|
915 | + $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
916 | + } |
|
889 | 917 | |
890 | - if (isset($config_var['step'])) |
|
891 | - $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
918 | + if (isset($config_var['step'])) { |
|
919 | + $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
920 | + } |
|
892 | 921 | } |
893 | 922 | |
894 | 923 | // If this is a select box handle any data. |
@@ -902,12 +931,13 @@ discard block |
||
902 | 931 | } |
903 | 932 | |
904 | 933 | // If it's associative |
905 | - if (isset($config_var[2][0]) && is_array($config_var[2][0])) |
|
906 | - $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
907 | - else |
|
934 | + if (isset($config_var[2][0]) && is_array($config_var[2][0])) { |
|
935 | + $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
936 | + } else |
|
908 | 937 | { |
909 | - foreach ($config_var[2] as $key => $item) |
|
910 | - $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
938 | + foreach ($config_var[2] as $key => $item) { |
|
939 | + $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
940 | + } |
|
911 | 941 | } |
912 | 942 | } |
913 | 943 | |
@@ -916,17 +946,19 @@ discard block |
||
916 | 946 | { |
917 | 947 | if (!is_numeric($k)) |
918 | 948 | { |
919 | - if (substr($k, 0, 2) == 'on') |
|
920 | - $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
921 | - else |
|
922 | - $context['config_vars'][$config_var[1]][$k] = $v; |
|
949 | + if (substr($k, 0, 2) == 'on') { |
|
950 | + $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
951 | + } else { |
|
952 | + $context['config_vars'][$config_var[1]][$k] = $v; |
|
953 | + } |
|
923 | 954 | } |
924 | 955 | |
925 | 956 | // See if there are any other labels that might fit? |
926 | - if (isset($txt['setting_' . $config_var[1]])) |
|
927 | - $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
928 | - elseif (isset($txt['groups_' . $config_var[1]])) |
|
929 | - $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
957 | + if (isset($txt['setting_' . $config_var[1]])) { |
|
958 | + $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
959 | + } elseif (isset($txt['groups_' . $config_var[1]])) { |
|
960 | + $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
961 | + } |
|
930 | 962 | } |
931 | 963 | |
932 | 964 | // Set the subtext in case it's part of the label. |
@@ -959,8 +991,9 @@ discard block |
||
959 | 991 | // What are the options, eh? |
960 | 992 | $temp = parse_bbc(false); |
961 | 993 | $bbcTags = array(); |
962 | - foreach ($temp as $tag) |
|
963 | - $bbcTags[] = $tag['tag']; |
|
994 | + foreach ($temp as $tag) { |
|
995 | + $bbcTags[] = $tag['tag']; |
|
996 | + } |
|
964 | 997 | |
965 | 998 | $bbcTags = array_unique($bbcTags); |
966 | 999 | $totalTags = count($bbcTags); |
@@ -975,8 +1008,9 @@ discard block |
||
975 | 1008 | $col = 0; $i = 0; |
976 | 1009 | foreach ($bbcTags as $tag) |
977 | 1010 | { |
978 | - if ($i % $tagsPerColumn == 0 && $i != 0) |
|
979 | - $col++; |
|
1011 | + if ($i % $tagsPerColumn == 0 && $i != 0) { |
|
1012 | + $col++; |
|
1013 | + } |
|
980 | 1014 | |
981 | 1015 | $context['bbc_columns'][$col][] = array( |
982 | 1016 | 'tag' => $tag, |
@@ -1019,18 +1053,21 @@ discard block |
||
1019 | 1053 | validateToken('admin-ssc'); |
1020 | 1054 | |
1021 | 1055 | // Fix the darn stupid cookiename! (more may not be allowed, but these for sure!) |
1022 | - if (isset($_POST['cookiename'])) |
|
1023 | - $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1056 | + if (isset($_POST['cookiename'])) { |
|
1057 | + $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1058 | + } |
|
1024 | 1059 | |
1025 | 1060 | // Fix the forum's URL if necessary. |
1026 | 1061 | if (isset($_POST['boardurl'])) |
1027 | 1062 | { |
1028 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
1029 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1030 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
1031 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1032 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
1033 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1063 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1064 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1065 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1066 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1067 | + } |
|
1068 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1069 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1070 | + } |
|
1034 | 1071 | } |
1035 | 1072 | |
1036 | 1073 | // Any passwords? |
@@ -1065,21 +1102,21 @@ discard block |
||
1065 | 1102 | // Figure out which config vars we're saving here... |
1066 | 1103 | foreach ($config_vars as $var) |
1067 | 1104 | { |
1068 | - if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) |
|
1069 | - continue; |
|
1105 | + if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) { |
|
1106 | + continue; |
|
1107 | + } |
|
1070 | 1108 | |
1071 | 1109 | $config_var = $var[0]; |
1072 | 1110 | |
1073 | 1111 | if (in_array($config_var, $config_passwords)) |
1074 | 1112 | { |
1075 | - if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) |
|
1076 | - $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1077 | - } |
|
1078 | - elseif (in_array($config_var, $config_strs)) |
|
1113 | + if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) { |
|
1114 | + $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1115 | + } |
|
1116 | + } elseif (in_array($config_var, $config_strs)) |
|
1079 | 1117 | { |
1080 | 1118 | $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\''; |
1081 | - } |
|
1082 | - elseif (in_array($config_var, $config_ints)) |
|
1119 | + } elseif (in_array($config_var, $config_ints)) |
|
1083 | 1120 | { |
1084 | 1121 | $new_settings[$config_var] = (int) $_POST[$config_var]; |
1085 | 1122 | |
@@ -1088,17 +1125,17 @@ discard block |
||
1088 | 1125 | $new_settings[$config_var] = max($min, $new_settings[$config_var]); |
1089 | 1126 | |
1090 | 1127 | // Is there a max value for this as well? |
1091 | - if (isset($var['max'])) |
|
1092 | - $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1093 | - } |
|
1094 | - elseif (in_array($config_var, $config_bools)) |
|
1128 | + if (isset($var['max'])) { |
|
1129 | + $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1130 | + } |
|
1131 | + } elseif (in_array($config_var, $config_bools)) |
|
1095 | 1132 | { |
1096 | - if (!empty($_POST[$config_var])) |
|
1097 | - $new_settings[$config_var] = '1'; |
|
1098 | - else |
|
1099 | - $new_settings[$config_var] = '0'; |
|
1100 | - } |
|
1101 | - else |
|
1133 | + if (!empty($_POST[$config_var])) { |
|
1134 | + $new_settings[$config_var] = '1'; |
|
1135 | + } else { |
|
1136 | + $new_settings[$config_var] = '0'; |
|
1137 | + } |
|
1138 | + } else |
|
1102 | 1139 | { |
1103 | 1140 | // This shouldn't happen, but it might... |
1104 | 1141 | fatal_error('Unknown config_var \'' . $config_var . '\''); |
@@ -1114,30 +1151,35 @@ discard block |
||
1114 | 1151 | foreach ($config_vars as $config_var) |
1115 | 1152 | { |
1116 | 1153 | // We just saved the file-based settings, so skip their definitions. |
1117 | - if (!is_array($config_var) || $config_var[2] == 'file') |
|
1118 | - continue; |
|
1154 | + if (!is_array($config_var) || $config_var[2] == 'file') { |
|
1155 | + continue; |
|
1156 | + } |
|
1119 | 1157 | |
1120 | 1158 | $new_setting = array($config_var[3], $config_var[0]); |
1121 | 1159 | |
1122 | 1160 | // Select options need carried over, too. |
1123 | - if (isset($config_var[4])) |
|
1124 | - $new_setting[] = $config_var[4]; |
|
1161 | + if (isset($config_var[4])) { |
|
1162 | + $new_setting[] = $config_var[4]; |
|
1163 | + } |
|
1125 | 1164 | |
1126 | 1165 | // Include min and max if necessary |
1127 | - if (isset($config_var['min'])) |
|
1128 | - $new_setting['min'] = $config_var['min']; |
|
1166 | + if (isset($config_var['min'])) { |
|
1167 | + $new_setting['min'] = $config_var['min']; |
|
1168 | + } |
|
1129 | 1169 | |
1130 | - if (isset($config_var['max'])) |
|
1131 | - $new_setting['max'] = $config_var['max']; |
|
1170 | + if (isset($config_var['max'])) { |
|
1171 | + $new_setting['max'] = $config_var['max']; |
|
1172 | + } |
|
1132 | 1173 | |
1133 | 1174 | // Rewrite the definition a bit. |
1134 | 1175 | $new_settings[] = $new_setting; |
1135 | 1176 | } |
1136 | 1177 | |
1137 | 1178 | // Save the new database-based settings, if any. |
1138 | - if (!empty($new_settings)) |
|
1139 | - saveDBSettings($new_settings); |
|
1140 | -} |
|
1179 | + if (!empty($new_settings)) { |
|
1180 | + saveDBSettings($new_settings); |
|
1181 | + } |
|
1182 | + } |
|
1141 | 1183 | |
1142 | 1184 | /** |
1143 | 1185 | * Helper function for saving database settings. |
@@ -1155,22 +1197,25 @@ discard block |
||
1155 | 1197 | $inlinePermissions = array(); |
1156 | 1198 | foreach ($config_vars as $var) |
1157 | 1199 | { |
1158 | - if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) |
|
1159 | - continue; |
|
1200 | + if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) { |
|
1201 | + continue; |
|
1202 | + } |
|
1160 | 1203 | |
1161 | 1204 | // Checkboxes! |
1162 | - elseif ($var[0] == 'check') |
|
1163 | - $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1205 | + elseif ($var[0] == 'check') { |
|
1206 | + $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1207 | + } |
|
1164 | 1208 | // Select boxes! |
1165 | - elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) |
|
1166 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1167 | - elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1209 | + elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { |
|
1210 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1211 | + } elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1168 | 1212 | { |
1169 | 1213 | // For security purposes we validate this line by line. |
1170 | 1214 | $lOptions = array(); |
1171 | - foreach ($_POST[$var[1]] as $invar) |
|
1172 | - if (in_array($invar, array_keys($var[2]))) |
|
1215 | + foreach ($_POST[$var[1]] as $invar) { |
|
1216 | + if (in_array($invar, array_keys($var[2]))) |
|
1173 | 1217 | $lOptions[] = $invar; |
1218 | + } |
|
1174 | 1219 | |
1175 | 1220 | $setArray[$var[1]] = json_encode($lOptions); |
1176 | 1221 | } |
@@ -1184,18 +1229,20 @@ discard block |
||
1184 | 1229 | $request = $smcFunc['db_query']('', ' |
1185 | 1230 | SELECT id_board |
1186 | 1231 | FROM {db_prefix}boards'); |
1187 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1188 | - $board_list[$row[0]] = true; |
|
1232 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1233 | + $board_list[$row[0]] = true; |
|
1234 | + } |
|
1189 | 1235 | |
1190 | 1236 | $smcFunc['db_free_result']($request); |
1191 | 1237 | } |
1192 | 1238 | |
1193 | 1239 | $lOptions = array(); |
1194 | 1240 | |
1195 | - if (!empty($_POST[$var[1]])) |
|
1196 | - foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1241 | + if (!empty($_POST[$var[1]])) { |
|
1242 | + foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1197 | 1243 | if (isset($board_list[$invar])) |
1198 | 1244 | $lOptions[] = $invar; |
1245 | + } |
|
1199 | 1246 | |
1200 | 1247 | $setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : ''; |
1201 | 1248 | } |
@@ -1209,8 +1256,9 @@ discard block |
||
1209 | 1256 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1210 | 1257 | |
1211 | 1258 | // Do we have a max value for this as well? |
1212 | - if (isset($var['max'])) |
|
1213 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1259 | + if (isset($var['max'])) { |
|
1260 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1261 | + } |
|
1214 | 1262 | } |
1215 | 1263 | // Floating point! |
1216 | 1264 | elseif ($var[0] == 'float') |
@@ -1222,40 +1270,47 @@ discard block |
||
1222 | 1270 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1223 | 1271 | |
1224 | 1272 | // Do we have a max value for this as well? |
1225 | - if (isset($var['max'])) |
|
1226 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1273 | + if (isset($var['max'])) { |
|
1274 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1275 | + } |
|
1227 | 1276 | } |
1228 | 1277 | // Text! |
1229 | - elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) |
|
1230 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1278 | + elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) { |
|
1279 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1280 | + } |
|
1231 | 1281 | // Passwords! |
1232 | 1282 | elseif ($var[0] == 'password') |
1233 | 1283 | { |
1234 | - if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) |
|
1235 | - $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1284 | + if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) { |
|
1285 | + $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1286 | + } |
|
1236 | 1287 | } |
1237 | 1288 | // BBC. |
1238 | 1289 | elseif ($var[0] == 'bbc') |
1239 | 1290 | { |
1240 | 1291 | |
1241 | 1292 | $bbcTags = array(); |
1242 | - foreach (parse_bbc(false) as $tag) |
|
1243 | - $bbcTags[] = $tag['tag']; |
|
1293 | + foreach (parse_bbc(false) as $tag) { |
|
1294 | + $bbcTags[] = $tag['tag']; |
|
1295 | + } |
|
1244 | 1296 | |
1245 | - if (!isset($_POST[$var[1] . '_enabledTags'])) |
|
1246 | - $_POST[$var[1] . '_enabledTags'] = array(); |
|
1247 | - elseif (!is_array($_POST[$var[1] . '_enabledTags'])) |
|
1248 | - $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1297 | + if (!isset($_POST[$var[1] . '_enabledTags'])) { |
|
1298 | + $_POST[$var[1] . '_enabledTags'] = array(); |
|
1299 | + } elseif (!is_array($_POST[$var[1] . '_enabledTags'])) { |
|
1300 | + $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1301 | + } |
|
1249 | 1302 | |
1250 | 1303 | $setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags'])); |
1251 | 1304 | } |
1252 | 1305 | // Permissions? |
1253 | - elseif ($var[0] == 'permissions') |
|
1254 | - $inlinePermissions[] = $var[1]; |
|
1306 | + elseif ($var[0] == 'permissions') { |
|
1307 | + $inlinePermissions[] = $var[1]; |
|
1308 | + } |
|
1255 | 1309 | } |
1256 | 1310 | |
1257 | - if (!empty($setArray)) |
|
1258 | - updateSettings($setArray); |
|
1311 | + if (!empty($setArray)) { |
|
1312 | + updateSettings($setArray); |
|
1313 | + } |
|
1259 | 1314 | |
1260 | 1315 | // If we have inline permissions we need to save them. |
1261 | 1316 | if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
@@ -1292,18 +1347,21 @@ discard block |
||
1292 | 1347 | // put all of it into an array |
1293 | 1348 | foreach ($info_lines as $line) |
1294 | 1349 | { |
1295 | - if (preg_match('~(' . $remove . ')~', $line)) |
|
1296 | - continue; |
|
1350 | + if (preg_match('~(' . $remove . ')~', $line)) { |
|
1351 | + continue; |
|
1352 | + } |
|
1297 | 1353 | |
1298 | 1354 | // new category? |
1299 | - if (strpos($line, '<h2>') !== false) |
|
1300 | - $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1355 | + if (strpos($line, '<h2>') !== false) { |
|
1356 | + $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1357 | + } |
|
1301 | 1358 | |
1302 | 1359 | // load it as setting => value or the old setting local master |
1303 | - if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1304 | - $pinfo[$category][$val[1]] = $val[2]; |
|
1305 | - elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1306 | - $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1360 | + if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1361 | + $pinfo[$category][$val[1]] = $val[2]; |
|
1362 | + } elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1363 | + $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1364 | + } |
|
1307 | 1365 | } |
1308 | 1366 | |
1309 | 1367 | // load it in to context and display it |
@@ -1338,8 +1396,9 @@ discard block |
||
1338 | 1396 | $testAPI = new $cache_class_name(); |
1339 | 1397 | |
1340 | 1398 | // No Support? NEXT! |
1341 | - if (!$testAPI->isSupported(true)) |
|
1342 | - continue; |
|
1399 | + if (!$testAPI->isSupported(true)) { |
|
1400 | + continue; |
|
1401 | + } |
|
1343 | 1402 | |
1344 | 1403 | $apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache; |
1345 | 1404 | } |
@@ -1364,8 +1423,9 @@ discard block |
||
1364 | 1423 | global $modSettings, $boardurl, $smcFunc; |
1365 | 1424 | |
1366 | 1425 | // Already have a key? Can't register again. |
1367 | - if (!empty($modSettings['sm_stats_key'])) |
|
1368 | - return true; |
|
1426 | + if (!empty($modSettings['sm_stats_key'])) { |
|
1427 | + return true; |
|
1428 | + } |
|
1369 | 1429 | |
1370 | 1430 | $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr); |
1371 | 1431 | if ($fp) |
@@ -1376,8 +1436,9 @@ discard block |
||
1376 | 1436 | fwrite($fp, $out); |
1377 | 1437 | |
1378 | 1438 | $return_data = ''; |
1379 | - while (!feof($fp)) |
|
1380 | - $return_data .= fgets($fp, 128); |
|
1439 | + while (!feof($fp)) { |
|
1440 | + $return_data .= fgets($fp, 128); |
|
1441 | + } |
|
1381 | 1442 | |
1382 | 1443 | fclose($fp); |
1383 | 1444 |