@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * View a summary. |
@@ -23,8 +24,9 @@ discard block |
||
23 | 24 | global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc; |
24 | 25 | |
25 | 26 | // Attempt to load the member's profile data. |
26 | - if (!loadMemberContext($memID) || !isset($memberContext[$memID])) |
|
27 | - fatal_lang_error('not_a_user', false, 404); |
|
27 | + if (!loadMemberContext($memID) || !isset($memberContext[$memID])) { |
|
28 | + fatal_lang_error('not_a_user', false, 404); |
|
29 | + } |
|
28 | 30 | |
29 | 31 | // Set up the stuff and load the user. |
30 | 32 | $context += array( |
@@ -49,19 +51,21 @@ discard block |
||
49 | 51 | |
50 | 52 | // See if they have broken any warning levels... |
51 | 53 | list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']); |
52 | - if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) |
|
53 | - $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
54 | - elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) |
|
55 | - $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
56 | - elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) |
|
57 | - $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
54 | + if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) { |
|
55 | + $context['warning_status'] = $txt['profile_warning_is_muted']; |
|
56 | + } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) { |
|
57 | + $context['warning_status'] = $txt['profile_warning_is_moderation']; |
|
58 | + } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) { |
|
59 | + $context['warning_status'] = $txt['profile_warning_is_watch']; |
|
60 | + } |
|
58 | 61 | |
59 | 62 | // They haven't even been registered for a full day!? |
60 | 63 | $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24)); |
61 | - if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) |
|
62 | - $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
63 | - else |
|
64 | - $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
64 | + if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) { |
|
65 | + $context['member']['posts_per_day'] = $txt['not_applicable']; |
|
66 | + } else { |
|
67 | + $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3); |
|
68 | + } |
|
65 | 69 | |
66 | 70 | // Set the age... |
67 | 71 | if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002) |
@@ -70,8 +74,7 @@ discard block |
||
70 | 74 | 'age' => $txt['not_applicable'], |
71 | 75 | 'today_is_birthday' => false |
72 | 76 | ); |
73 | - } |
|
74 | - else |
|
77 | + } else |
|
75 | 78 | { |
76 | 79 | list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d'); |
77 | 80 | $datearray = getdate(forum_time()); |
@@ -84,15 +87,16 @@ discard block |
||
84 | 87 | if (allowedTo('moderate_forum')) |
85 | 88 | { |
86 | 89 | // Make sure it's a valid ip address; otherwise, don't bother... |
87 | - if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) |
|
88 | - $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
89 | - else |
|
90 | - $context['member']['hostname'] = ''; |
|
90 | + if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) { |
|
91 | + $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']); |
|
92 | + } else { |
|
93 | + $context['member']['hostname'] = ''; |
|
94 | + } |
|
91 | 95 | |
92 | 96 | $context['can_see_ip'] = true; |
97 | + } else { |
|
98 | + $context['can_see_ip'] = false; |
|
93 | 99 | } |
94 | - else |
|
95 | - $context['can_see_ip'] = false; |
|
96 | 100 | |
97 | 101 | // Are they hidden? |
98 | 102 | $context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']); |
@@ -103,8 +107,9 @@ discard block |
||
103 | 107 | include_once($sourcedir . '/Who.php'); |
104 | 108 | $action = determineActions($user_profile[$memID]['url']); |
105 | 109 | |
106 | - if ($action !== false) |
|
107 | - $context['member']['action'] = $action; |
|
110 | + if ($action !== false) { |
|
111 | + $context['member']['action'] = $action; |
|
112 | + } |
|
108 | 113 | } |
109 | 114 | |
110 | 115 | // If the user is awaiting activation, and the viewer has permission - setup some activation context messages. |
@@ -167,13 +172,15 @@ discard block |
||
167 | 172 | { |
168 | 173 | // Work out what restrictions we actually have. |
169 | 174 | $ban_restrictions = array(); |
170 | - foreach (array('access', 'login', 'post') as $type) |
|
171 | - if ($row['cannot_' . $type]) |
|
175 | + foreach (array('access', 'login', 'post') as $type) { |
|
176 | + if ($row['cannot_' . $type]) |
|
172 | 177 | $ban_restrictions[] = $txt['ban_type_' . $type]; |
178 | + } |
|
173 | 179 | |
174 | 180 | // No actual ban in place? |
175 | - if (empty($ban_restrictions)) |
|
176 | - continue; |
|
181 | + if (empty($ban_restrictions)) { |
|
182 | + continue; |
|
183 | + } |
|
177 | 184 | |
178 | 185 | // Prepare the link for context. |
179 | 186 | $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>'); |
@@ -195,9 +202,10 @@ discard block |
||
195 | 202 | $context['print_custom_fields'] = array(); |
196 | 203 | |
197 | 204 | // Any custom profile fields? |
198 | - if (!empty($context['custom_fields'])) |
|
199 | - foreach ($context['custom_fields'] as $custom) |
|
205 | + if (!empty($context['custom_fields'])) { |
|
206 | + foreach ($context['custom_fields'] as $custom) |
|
200 | 207 | $context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom; |
208 | + } |
|
201 | 209 | |
202 | 210 | } |
203 | 211 | |
@@ -242,16 +250,18 @@ discard block |
||
242 | 250 | $row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array(); |
243 | 251 | $alerts[$id_alert] = $row; |
244 | 252 | |
245 | - if (!empty($row['sender_id'])) |
|
246 | - $senders[] = $row['sender_id']; |
|
253 | + if (!empty($row['sender_id'])) { |
|
254 | + $senders[] = $row['sender_id']; |
|
255 | + } |
|
247 | 256 | } |
248 | 257 | $smcFunc['db_free_result']($request); |
249 | 258 | |
250 | 259 | if($withSender) |
251 | 260 | { |
252 | 261 | $senders = loadMemberData($senders); |
253 | - foreach ($senders as $member) |
|
254 | - loadMemberContext($member); |
|
262 | + foreach ($senders as $member) { |
|
263 | + loadMemberContext($member); |
|
264 | + } |
|
255 | 265 | } |
256 | 266 | |
257 | 267 | // Now go through and actually make with the text. |
@@ -266,12 +276,15 @@ discard block |
||
266 | 276 | $msgs = array(); |
267 | 277 | foreach ($alerts as $id_alert => $alert) |
268 | 278 | { |
269 | - if (isset($alert['extra']['board'])) |
|
270 | - $boards[$alert['extra']['board']] = $txt['board_na']; |
|
271 | - if (isset($alert['extra']['topic'])) |
|
272 | - $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
273 | - if ($alert['content_type'] == 'msg') |
|
274 | - $msgs[$alert['content_id']] = $txt['topic_na']; |
|
279 | + if (isset($alert['extra']['board'])) { |
|
280 | + $boards[$alert['extra']['board']] = $txt['board_na']; |
|
281 | + } |
|
282 | + if (isset($alert['extra']['topic'])) { |
|
283 | + $topics[$alert['extra']['topic']] = $txt['topic_na']; |
|
284 | + } |
|
285 | + if ($alert['content_type'] == 'msg') { |
|
286 | + $msgs[$alert['content_id']] = $txt['topic_na']; |
|
287 | + } |
|
275 | 288 | } |
276 | 289 | |
277 | 290 | // Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up. |
@@ -286,8 +299,9 @@ discard block |
||
286 | 299 | 'boards' => array_keys($boards), |
287 | 300 | ) |
288 | 301 | ); |
289 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
290 | - $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
302 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
303 | + $boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
304 | + } |
|
291 | 305 | } |
292 | 306 | if (!empty($topics)) |
293 | 307 | { |
@@ -302,8 +316,9 @@ discard block |
||
302 | 316 | 'topics' => array_keys($topics), |
303 | 317 | ) |
304 | 318 | ); |
305 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
306 | - $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
319 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
320 | + $topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>'; |
|
321 | + } |
|
307 | 322 | } |
308 | 323 | if (!empty($msgs)) |
309 | 324 | { |
@@ -318,44 +333,51 @@ discard block |
||
318 | 333 | 'msgs' => array_keys($msgs), |
319 | 334 | ) |
320 | 335 | ); |
321 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
322 | - $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
336 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
337 | + $msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
338 | + } |
|
323 | 339 | } |
324 | 340 | |
325 | 341 | // Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already) |
326 | 342 | foreach ($alerts as $id_alert => $alert) |
327 | 343 | { |
328 | - if (!empty($alert['text'])) |
|
329 | - continue; |
|
330 | - if (isset($alert['extra']['board'])) |
|
331 | - if ($boards[$alert['extra']['board']] == $txt['board_na']) |
|
344 | + if (!empty($alert['text'])) { |
|
345 | + continue; |
|
346 | + } |
|
347 | + if (isset($alert['extra']['board'])) { |
|
348 | + if ($boards[$alert['extra']['board']] == $txt['board_na']) |
|
332 | 349 | { |
333 | 350 | unset($alerts[$id_alert]); |
351 | + } |
|
334 | 352 | continue; |
353 | + } else { |
|
354 | + $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
335 | 355 | } |
336 | - else |
|
337 | - $alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']]; |
|
338 | - if (isset($alert['extra']['topic'])) |
|
339 | - if ($alert['extra']['topic'] == $txt['topic_na']) |
|
356 | + if (isset($alert['extra']['topic'])) { |
|
357 | + if ($alert['extra']['topic'] == $txt['topic_na']) |
|
340 | 358 | { |
341 | 359 | unset($alerts[$id_alert]); |
360 | + } |
|
342 | 361 | continue; |
362 | + } else { |
|
363 | + $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
343 | 364 | } |
344 | - else |
|
345 | - $alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']]; |
|
346 | - if ($alert['content_type'] == 'msg') |
|
347 | - if ($msgs[$alert['content_id']] == $txt['topic_na']) |
|
365 | + if ($alert['content_type'] == 'msg') { |
|
366 | + if ($msgs[$alert['content_id']] == $txt['topic_na']) |
|
348 | 367 | { |
349 | 368 | unset($alerts[$id_alert]); |
369 | + } |
|
350 | 370 | continue; |
351 | - } |
|
352 | - else |
|
353 | - $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
354 | - if ($alert['content_type'] == 'profile') |
|
355 | - $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
371 | + } else { |
|
372 | + $alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']]; |
|
373 | + } |
|
374 | + if ($alert['content_type'] == 'profile') { |
|
375 | + $alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>'; |
|
376 | + } |
|
356 | 377 | |
357 | - if (!empty($memberContext[$alert['sender_id']])) |
|
358 | - $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
378 | + if (!empty($memberContext[$alert['sender_id']])) { |
|
379 | + $alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']]; |
|
380 | + } |
|
359 | 381 | |
360 | 382 | $string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action']; |
361 | 383 | if (isset($txt[$string])) |
@@ -443,11 +465,11 @@ discard block |
||
443 | 465 | checkSession('request'); |
444 | 466 | |
445 | 467 | // Call it! |
446 | - if ($action == 'remove') |
|
447 | - alert_delete($toMark, $memID); |
|
448 | - |
|
449 | - else |
|
450 | - alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
468 | + if ($action == 'remove') { |
|
469 | + alert_delete($toMark, $memID); |
|
470 | + } else { |
|
471 | + alert_mark($memID, $toMark, $action == 'read' ? 1 : 0); |
|
472 | + } |
|
451 | 473 | |
452 | 474 | // Set a nice update message. |
453 | 475 | $_SESSION['update_message'] = true; |
@@ -497,23 +519,27 @@ discard block |
||
497 | 519 | ); |
498 | 520 | |
499 | 521 | // Set the page title |
500 | - if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) |
|
501 | - $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
502 | - else |
|
503 | - $context['page_title'] = $txt['showPosts']; |
|
522 | + if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) { |
|
523 | + $context['page_title'] = $txt['show' . $title[$_GET['sa']]]; |
|
524 | + } else { |
|
525 | + $context['page_title'] = $txt['showPosts']; |
|
526 | + } |
|
504 | 527 | |
505 | 528 | $context['page_title'] .= ' - ' . $user_profile[$memID]['real_name']; |
506 | 529 | |
507 | 530 | // Is the load average too high to allow searching just now? |
508 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) |
|
509 | - fatal_lang_error('loadavg_show_posts_disabled', false); |
|
531 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) { |
|
532 | + fatal_lang_error('loadavg_show_posts_disabled', false); |
|
533 | + } |
|
510 | 534 | |
511 | 535 | // If we're specifically dealing with attachments use that function! |
512 | - if (isset($_GET['sa']) && $_GET['sa'] == 'attach') |
|
513 | - return showAttachments($memID); |
|
536 | + if (isset($_GET['sa']) && $_GET['sa'] == 'attach') { |
|
537 | + return showAttachments($memID); |
|
538 | + } |
|
514 | 539 | // Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function. |
515 | - elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') |
|
516 | - return showUnwatched($memID); |
|
540 | + elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') { |
|
541 | + return showUnwatched($memID); |
|
542 | + } |
|
517 | 543 | |
518 | 544 | // Are we just viewing topics? |
519 | 545 | $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false; |
@@ -536,27 +562,30 @@ discard block |
||
536 | 562 | $smcFunc['db_free_result']($request); |
537 | 563 | |
538 | 564 | // Trying to remove a message that doesn't exist. |
539 | - if (empty($info)) |
|
540 | - redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
565 | + if (empty($info)) { |
|
566 | + redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
|
567 | + } |
|
541 | 568 | |
542 | 569 | // We can be lazy, since removeMessage() will check the permissions for us. |
543 | 570 | require_once($sourcedir . '/RemoveTopic.php'); |
544 | 571 | removeMessage((int) $_GET['delete']); |
545 | 572 | |
546 | 573 | // Add it to the mod log. |
547 | - if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) |
|
548 | - logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
574 | + if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) { |
|
575 | + logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3])); |
|
576 | + } |
|
549 | 577 | |
550 | 578 | // Back to... where we are now ;). |
551 | 579 | redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']); |
552 | 580 | } |
553 | 581 | |
554 | 582 | // Default to 10. |
555 | - if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) |
|
556 | - $_REQUEST['viewscount'] = '10'; |
|
583 | + if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) { |
|
584 | + $_REQUEST['viewscount'] = '10'; |
|
585 | + } |
|
557 | 586 | |
558 | - if ($context['is_topics']) |
|
559 | - $request = $smcFunc['db_query']('', ' |
|
587 | + if ($context['is_topics']) { |
|
588 | + $request = $smcFunc['db_query']('', ' |
|
560 | 589 | SELECT COUNT(*) |
561 | 590 | FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
562 | 591 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . ' |
@@ -569,8 +598,8 @@ discard block |
||
569 | 598 | 'board' => $board, |
570 | 599 | ) |
571 | 600 | ); |
572 | - else |
|
573 | - $request = $smcFunc['db_query']('', ' |
|
601 | + } else { |
|
602 | + $request = $smcFunc['db_query']('', ' |
|
574 | 603 | SELECT COUNT(*) |
575 | 604 | FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : ' |
576 | 605 | INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . ' |
@@ -583,6 +612,7 @@ discard block |
||
583 | 612 | 'board' => $board, |
584 | 613 | ) |
585 | 614 | ); |
615 | + } |
|
586 | 616 | list ($msgCount) = $smcFunc['db_fetch_row']($request); |
587 | 617 | $smcFunc['db_free_result']($request); |
588 | 618 | |
@@ -603,10 +633,11 @@ discard block |
||
603 | 633 | |
604 | 634 | $range_limit = ''; |
605 | 635 | |
606 | - if ($context['is_topics']) |
|
607 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
608 | - else |
|
609 | - $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
636 | + if ($context['is_topics']) { |
|
637 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics']; |
|
638 | + } else { |
|
639 | + $maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; |
|
640 | + } |
|
610 | 641 | |
611 | 642 | $maxIndex = $maxPerPage; |
612 | 643 | |
@@ -632,9 +663,9 @@ discard block |
||
632 | 663 | { |
633 | 664 | $margin *= 5; |
634 | 665 | $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin); |
666 | + } else { |
|
667 | + $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
635 | 668 | } |
636 | - else |
|
637 | - $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin); |
|
638 | 669 | } |
639 | 670 | |
640 | 671 | // Find this user's posts. The left join on categories somehow makes this faster, weird as it looks. |
@@ -666,8 +697,7 @@ discard block |
||
666 | 697 | 'max' => $maxIndex, |
667 | 698 | ) |
668 | 699 | ); |
669 | - } |
|
670 | - else |
|
700 | + } else |
|
671 | 701 | { |
672 | 702 | $request = $smcFunc['db_query']('', ' |
673 | 703 | SELECT |
@@ -696,8 +726,9 @@ discard block |
||
696 | 726 | } |
697 | 727 | |
698 | 728 | // Make sure we quit this loop. |
699 | - if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) |
|
700 | - break; |
|
729 | + if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) { |
|
730 | + break; |
|
731 | + } |
|
701 | 732 | $looped = true; |
702 | 733 | $range_limit = ''; |
703 | 734 | } |
@@ -741,19 +772,21 @@ discard block |
||
741 | 772 | 'css_class' => $row['approved'] ? 'windowbg' : 'approvebg', |
742 | 773 | ); |
743 | 774 | |
744 | - if ($user_info['id'] == $row['id_member_started']) |
|
745 | - $board_ids['own'][$row['id_board']][] = $counter; |
|
775 | + if ($user_info['id'] == $row['id_member_started']) { |
|
776 | + $board_ids['own'][$row['id_board']][] = $counter; |
|
777 | + } |
|
746 | 778 | $board_ids['any'][$row['id_board']][] = $counter; |
747 | 779 | } |
748 | 780 | $smcFunc['db_free_result']($request); |
749 | 781 | |
750 | 782 | // All posts were retrieved in reverse order, get them right again. |
751 | - if ($reverse) |
|
752 | - $context['posts'] = array_reverse($context['posts'], true); |
|
783 | + if ($reverse) { |
|
784 | + $context['posts'] = array_reverse($context['posts'], true); |
|
785 | + } |
|
753 | 786 | |
754 | 787 | // These are all the permissions that are different from board to board.. |
755 | - if ($context['is_topics']) |
|
756 | - $permissions = array( |
|
788 | + if ($context['is_topics']) { |
|
789 | + $permissions = array( |
|
757 | 790 | 'own' => array( |
758 | 791 | 'post_reply_own' => 'can_reply', |
759 | 792 | ), |
@@ -761,8 +794,8 @@ discard block |
||
761 | 794 | 'post_reply_any' => 'can_reply', |
762 | 795 | ) |
763 | 796 | ); |
764 | - else |
|
765 | - $permissions = array( |
|
797 | + } else { |
|
798 | + $permissions = array( |
|
766 | 799 | 'own' => array( |
767 | 800 | 'post_reply_own' => 'can_reply', |
768 | 801 | 'delete_own' => 'can_delete', |
@@ -772,6 +805,7 @@ discard block |
||
772 | 805 | 'delete_any' => 'can_delete', |
773 | 806 | ) |
774 | 807 | ); |
808 | + } |
|
775 | 809 | |
776 | 810 | // For every permission in the own/any lists... |
777 | 811 | foreach ($permissions as $type => $list) |
@@ -782,19 +816,22 @@ discard block |
||
782 | 816 | $boards = boardsAllowedTo($permission); |
783 | 817 | |
784 | 818 | // Hmm, they can do it on all boards, can they? |
785 | - if (!empty($boards) && $boards[0] == 0) |
|
786 | - $boards = array_keys($board_ids[$type]); |
|
819 | + if (!empty($boards) && $boards[0] == 0) { |
|
820 | + $boards = array_keys($board_ids[$type]); |
|
821 | + } |
|
787 | 822 | |
788 | 823 | // Now go through each board they can do the permission on. |
789 | 824 | foreach ($boards as $board_id) |
790 | 825 | { |
791 | 826 | // There aren't any posts displayed from this board. |
792 | - if (!isset($board_ids[$type][$board_id])) |
|
793 | - continue; |
|
827 | + if (!isset($board_ids[$type][$board_id])) { |
|
828 | + continue; |
|
829 | + } |
|
794 | 830 | |
795 | 831 | // Set the permission to true ;). |
796 | - foreach ($board_ids[$type][$board_id] as $counter) |
|
797 | - $context['posts'][$counter][$allowed] = true; |
|
832 | + foreach ($board_ids[$type][$board_id] as $counter) { |
|
833 | + $context['posts'][$counter][$allowed] = true; |
|
834 | + } |
|
798 | 835 | } |
799 | 836 | } |
800 | 837 | } |
@@ -825,8 +862,9 @@ discard block |
||
825 | 862 | $boardsAllowed = boardsAllowedTo('view_attachments'); |
826 | 863 | |
827 | 864 | // Make sure we can't actually see anything... |
828 | - if (empty($boardsAllowed)) |
|
829 | - $boardsAllowed = array(-1); |
|
865 | + if (empty($boardsAllowed)) { |
|
866 | + $boardsAllowed = array(-1); |
|
867 | + } |
|
830 | 868 | |
831 | 869 | require_once($sourcedir . '/Subs-List.php'); |
832 | 870 | |
@@ -977,8 +1015,8 @@ discard block |
||
977 | 1015 | ) |
978 | 1016 | ); |
979 | 1017 | $attachments = array(); |
980 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
981 | - $attachments[] = array( |
|
1018 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1019 | + $attachments[] = array( |
|
982 | 1020 | 'id' => $row['id_attach'], |
983 | 1021 | 'filename' => $row['filename'], |
984 | 1022 | 'downloads' => $row['downloads'], |
@@ -990,6 +1028,7 @@ discard block |
||
990 | 1028 | 'board_name' => $row['name'], |
991 | 1029 | 'approved' => $row['approved'], |
992 | 1030 | ); |
1031 | + } |
|
993 | 1032 | |
994 | 1033 | $smcFunc['db_free_result']($request); |
995 | 1034 | |
@@ -1044,8 +1083,9 @@ discard block |
||
1044 | 1083 | global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir; |
1045 | 1084 | |
1046 | 1085 | // Only the owner can see the list (if the function is enabled of course) |
1047 | - if ($user_info['id'] != $memID) |
|
1048 | - return; |
|
1086 | + if ($user_info['id'] != $memID) { |
|
1087 | + return; |
|
1088 | + } |
|
1049 | 1089 | |
1050 | 1090 | require_once($sourcedir . '/Subs-List.php'); |
1051 | 1091 | |
@@ -1191,8 +1231,9 @@ discard block |
||
1191 | 1231 | ); |
1192 | 1232 | |
1193 | 1233 | $topics = array(); |
1194 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1195 | - $topics[] = $row['id_topic']; |
|
1234 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1235 | + $topics[] = $row['id_topic']; |
|
1236 | + } |
|
1196 | 1237 | |
1197 | 1238 | $smcFunc['db_free_result']($request); |
1198 | 1239 | |
@@ -1212,8 +1253,9 @@ discard block |
||
1212 | 1253 | 'topics' => $topics, |
1213 | 1254 | ) |
1214 | 1255 | ); |
1215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1216 | - $topicsInfo[] = $row; |
|
1256 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1257 | + $topicsInfo[] = $row; |
|
1258 | + } |
|
1217 | 1259 | $smcFunc['db_free_result']($request); |
1218 | 1260 | } |
1219 | 1261 | |
@@ -1261,8 +1303,9 @@ discard block |
||
1261 | 1303 | $context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name']; |
1262 | 1304 | |
1263 | 1305 | // Is the load average too high to allow searching just now? |
1264 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) |
|
1265 | - fatal_lang_error('loadavg_userstats_disabled', false); |
|
1306 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) { |
|
1307 | + fatal_lang_error('loadavg_userstats_disabled', false); |
|
1308 | + } |
|
1266 | 1309 | |
1267 | 1310 | // General user statistics. |
1268 | 1311 | $timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400); |
@@ -1405,11 +1448,13 @@ discard block |
||
1405 | 1448 | } |
1406 | 1449 | $smcFunc['db_free_result']($result); |
1407 | 1450 | |
1408 | - if ($maxPosts > 0) |
|
1409 | - for ($hour = 0; $hour < 24; $hour++) |
|
1451 | + if ($maxPosts > 0) { |
|
1452 | + for ($hour = 0; |
|
1453 | + } |
|
1454 | + $hour < 24; $hour++) |
|
1410 | 1455 | { |
1411 | - if (!isset($context['posts_by_time'][$hour])) |
|
1412 | - $context['posts_by_time'][$hour] = array( |
|
1456 | + if (!isset($context['posts_by_time'][$hour])) { |
|
1457 | + $context['posts_by_time'][$hour] = array( |
|
1413 | 1458 | 'hour' => $hour, |
1414 | 1459 | 'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)), |
1415 | 1460 | 'posts' => 0, |
@@ -1417,7 +1462,7 @@ discard block |
||
1417 | 1462 | 'relative_percent' => 0, |
1418 | 1463 | 'is_last' => $hour == 23, |
1419 | 1464 | ); |
1420 | - else |
|
1465 | + } else |
|
1421 | 1466 | { |
1422 | 1467 | $context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts); |
1423 | 1468 | $context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts); |
@@ -1450,8 +1495,9 @@ discard block |
||
1450 | 1495 | |
1451 | 1496 | foreach ($subActions as $sa => $action) |
1452 | 1497 | { |
1453 | - if (!allowedTo($action[2])) |
|
1454 | - unset($subActions[$sa]); |
|
1498 | + if (!allowedTo($action[2])) { |
|
1499 | + unset($subActions[$sa]); |
|
1500 | + } |
|
1455 | 1501 | } |
1456 | 1502 | |
1457 | 1503 | // Create the tabs for the template. |
@@ -1469,15 +1515,18 @@ discard block |
||
1469 | 1515 | ); |
1470 | 1516 | |
1471 | 1517 | // Moderation must be on to track edits. |
1472 | - if (empty($modSettings['userlog_enabled'])) |
|
1473 | - unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
1518 | + if (empty($modSettings['userlog_enabled'])) { |
|
1519 | + unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']); |
|
1520 | + } |
|
1474 | 1521 | |
1475 | 1522 | // Group requests must be active to show it... |
1476 | - if (empty($modSettings['show_group_membership'])) |
|
1477 | - unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
1523 | + if (empty($modSettings['show_group_membership'])) { |
|
1524 | + unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']); |
|
1525 | + } |
|
1478 | 1526 | |
1479 | - if (empty($subActions)) |
|
1480 | - fatal_lang_error('no_access', false); |
|
1527 | + if (empty($subActions)) { |
|
1528 | + fatal_lang_error('no_access', false); |
|
1529 | + } |
|
1481 | 1530 | |
1482 | 1531 | $keys = array_keys($subActions); |
1483 | 1532 | $default = array_shift($keys); |
@@ -1490,9 +1539,10 @@ discard block |
||
1490 | 1539 | $context['sub_template'] = $subActions[$context['tracking_area']][0]; |
1491 | 1540 | $call = call_helper($subActions[$context['tracking_area']][0], true); |
1492 | 1541 | |
1493 | - if (!empty($call)) |
|
1494 | - call_user_func($call, $memID); |
|
1495 | -} |
|
1542 | + if (!empty($call)) { |
|
1543 | + call_user_func($call, $memID); |
|
1544 | + } |
|
1545 | + } |
|
1496 | 1546 | |
1497 | 1547 | /** |
1498 | 1548 | * Handles tracking a user's activity |
@@ -1508,8 +1558,9 @@ discard block |
||
1508 | 1558 | isAllowedTo('moderate_forum'); |
1509 | 1559 | |
1510 | 1560 | $context['last_ip'] = $user_profile[$memID]['member_ip']; |
1511 | - if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) |
|
1512 | - $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
1561 | + if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) { |
|
1562 | + $context['last_ip2'] = $user_profile[$memID]['member_ip2']; |
|
1563 | + } |
|
1513 | 1564 | $context['member']['name'] = $user_profile[$memID]['real_name']; |
1514 | 1565 | |
1515 | 1566 | // Set the options for the list component. |
@@ -1675,8 +1726,9 @@ discard block |
||
1675 | 1726 | ) |
1676 | 1727 | ); |
1677 | 1728 | $message_members = array(); |
1678 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1679 | - $message_members[] = $row['id_member']; |
|
1729 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1730 | + $message_members[] = $row['id_member']; |
|
1731 | + } |
|
1680 | 1732 | $smcFunc['db_free_result']($request); |
1681 | 1733 | |
1682 | 1734 | // Fetch their names, cause of the GROUP BY doesn't like giving us that normally. |
@@ -1691,8 +1743,9 @@ discard block |
||
1691 | 1743 | 'ip_list' => $ips, |
1692 | 1744 | ) |
1693 | 1745 | ); |
1694 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1695 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
1746 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1747 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
1748 | + } |
|
1696 | 1749 | $smcFunc['db_free_result']($request); |
1697 | 1750 | } |
1698 | 1751 | |
@@ -1706,8 +1759,9 @@ discard block |
||
1706 | 1759 | 'ip_list' => $ips, |
1707 | 1760 | ) |
1708 | 1761 | ); |
1709 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1710 | - $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
1762 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1763 | + $context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
1764 | + } |
|
1711 | 1765 | $smcFunc['db_free_result']($request); |
1712 | 1766 | } |
1713 | 1767 | } |
@@ -1767,8 +1821,8 @@ discard block |
||
1767 | 1821 | )) |
1768 | 1822 | ); |
1769 | 1823 | $error_messages = array(); |
1770 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1771 | - $error_messages[] = array( |
|
1824 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1825 | + $error_messages[] = array( |
|
1772 | 1826 | 'ip' => inet_dtop($row['ip']), |
1773 | 1827 | 'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'], |
1774 | 1828 | 'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')), |
@@ -1776,6 +1830,7 @@ discard block |
||
1776 | 1830 | 'time' => timeformat($row['log_time']), |
1777 | 1831 | 'timestamp' => forum_time(true, $row['log_time']), |
1778 | 1832 | ); |
1833 | + } |
|
1779 | 1834 | $smcFunc['db_free_result']($request); |
1780 | 1835 | |
1781 | 1836 | return $error_messages; |
@@ -1838,8 +1893,8 @@ discard block |
||
1838 | 1893 | )) |
1839 | 1894 | ); |
1840 | 1895 | $messages = array(); |
1841 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1842 | - $messages[] = array( |
|
1896 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1897 | + $messages[] = array( |
|
1843 | 1898 | 'ip' => inet_dtop($row['poster_ip']), |
1844 | 1899 | 'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>', |
1845 | 1900 | 'board' => array( |
@@ -1852,6 +1907,7 @@ discard block |
||
1852 | 1907 | 'time' => timeformat($row['poster_time']), |
1853 | 1908 | 'timestamp' => forum_time(true, $row['poster_time']) |
1854 | 1909 | ); |
1910 | + } |
|
1855 | 1911 | $smcFunc['db_free_result']($request); |
1856 | 1912 | |
1857 | 1913 | return $messages; |
@@ -1878,19 +1934,20 @@ discard block |
||
1878 | 1934 | $context['sub_template'] = 'trackIP'; |
1879 | 1935 | $context['page_title'] = $txt['profile']; |
1880 | 1936 | $context['base_url'] = $scripturl . '?action=trackip'; |
1881 | - } |
|
1882 | - else |
|
1937 | + } else |
|
1883 | 1938 | { |
1884 | 1939 | $context['ip'] = $user_profile[$memID]['member_ip']; |
1885 | 1940 | $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
1886 | 1941 | } |
1887 | 1942 | |
1888 | 1943 | // Searching? |
1889 | - if (isset($_REQUEST['searchip'])) |
|
1890 | - $context['ip'] = trim($_REQUEST['searchip']); |
|
1944 | + if (isset($_REQUEST['searchip'])) { |
|
1945 | + $context['ip'] = trim($_REQUEST['searchip']); |
|
1946 | + } |
|
1891 | 1947 | |
1892 | - if (isValidIP($context['ip']) === false) |
|
1893 | - fatal_lang_error('invalid_tracking_ip', false); |
|
1948 | + if (isValidIP($context['ip']) === false) { |
|
1949 | + fatal_lang_error('invalid_tracking_ip', false); |
|
1950 | + } |
|
1894 | 1951 | |
1895 | 1952 | //mysql didn't support like search with varbinary |
1896 | 1953 | //$ip_var = str_replace('*', '%', $context['ip']); |
@@ -1898,8 +1955,9 @@ discard block |
||
1898 | 1955 | $ip_var = $context['ip']; |
1899 | 1956 | $ip_string = '= {inet:ip_address}'; |
1900 | 1957 | |
1901 | - if (empty($context['tracking_area'])) |
|
1902 | - $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
1958 | + if (empty($context['tracking_area'])) { |
|
1959 | + $context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip']; |
|
1960 | + } |
|
1903 | 1961 | |
1904 | 1962 | $request = $smcFunc['db_query']('', ' |
1905 | 1963 | SELECT id_member, real_name AS display_name, member_ip |
@@ -1910,8 +1968,9 @@ discard block |
||
1910 | 1968 | ) |
1911 | 1969 | ); |
1912 | 1970 | $context['ips'] = array(); |
1913 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1914 | - $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
1971 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1972 | + $context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>'; |
|
1973 | + } |
|
1915 | 1974 | $smcFunc['db_free_result']($request); |
1916 | 1975 | |
1917 | 1976 | ksort($context['ips']); |
@@ -2140,8 +2199,9 @@ discard block |
||
2140 | 2199 | foreach ($context['whois_servers'] as $whois) |
2141 | 2200 | { |
2142 | 2201 | // Strip off the "decimal point" and anything following... |
2143 | - if (in_array((int) $context['ip'], $whois['range'])) |
|
2144 | - $context['auto_whois_server'] = $whois; |
|
2202 | + if (in_array((int) $context['ip'], $whois['range'])) { |
|
2203 | + $context['auto_whois_server'] = $whois; |
|
2204 | + } |
|
2145 | 2205 | } |
2146 | 2206 | } |
2147 | 2207 | } |
@@ -2158,10 +2218,11 @@ discard block |
||
2158 | 2218 | // Gonna want this for the list. |
2159 | 2219 | require_once($sourcedir . '/Subs-List.php'); |
2160 | 2220 | |
2161 | - if ($memID == 0) |
|
2162 | - $context['base_url'] = $scripturl . '?action=trackip'; |
|
2163 | - else |
|
2164 | - $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
2221 | + if ($memID == 0) { |
|
2222 | + $context['base_url'] = $scripturl . '?action=trackip'; |
|
2223 | + } else { |
|
2224 | + $context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID; |
|
2225 | + } |
|
2165 | 2226 | |
2166 | 2227 | // Start with the user messages. |
2167 | 2228 | $listOptions = array( |
@@ -2271,12 +2332,13 @@ discard block |
||
2271 | 2332 | ) |
2272 | 2333 | ); |
2273 | 2334 | $logins = array(); |
2274 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2275 | - $logins[] = array( |
|
2335 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2336 | + $logins[] = array( |
|
2276 | 2337 | 'time' => timeformat($row['time']), |
2277 | 2338 | 'ip' => inet_dtop($row['ip']), |
2278 | 2339 | 'ip2' => inet_dtop($row['ip2']), |
2279 | 2340 | ); |
2341 | + } |
|
2280 | 2342 | $smcFunc['db_free_result']($request); |
2281 | 2343 | |
2282 | 2344 | return $logins; |
@@ -2301,11 +2363,12 @@ discard block |
||
2301 | 2363 | ) |
2302 | 2364 | ); |
2303 | 2365 | $context['custom_field_titles'] = array(); |
2304 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2305 | - $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
2366 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2367 | + $context['custom_field_titles']['customfield_' . $row['col_name']] = array( |
|
2306 | 2368 | 'title' => $row['field_name'], |
2307 | 2369 | 'parse_bbc' => $row['bbc'], |
2308 | 2370 | ); |
2371 | + } |
|
2309 | 2372 | $smcFunc['db_free_result']($request); |
2310 | 2373 | |
2311 | 2374 | // Set the options for the error lists. |
@@ -2444,19 +2507,22 @@ discard block |
||
2444 | 2507 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2445 | 2508 | { |
2446 | 2509 | $extra = $smcFunc['json_decode']($row['extra'], true); |
2447 | - if (!empty($extra['applicator'])) |
|
2448 | - $members[] = $extra['applicator']; |
|
2510 | + if (!empty($extra['applicator'])) { |
|
2511 | + $members[] = $extra['applicator']; |
|
2512 | + } |
|
2449 | 2513 | |
2450 | 2514 | // Work out what the name of the action is. |
2451 | - if (isset($txt['trackEdit_action_' . $row['action']])) |
|
2452 | - $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
2453 | - elseif (isset($txt[$row['action']])) |
|
2454 | - $action_text = $txt[$row['action']]; |
|
2515 | + if (isset($txt['trackEdit_action_' . $row['action']])) { |
|
2516 | + $action_text = $txt['trackEdit_action_' . $row['action']]; |
|
2517 | + } elseif (isset($txt[$row['action']])) { |
|
2518 | + $action_text = $txt[$row['action']]; |
|
2519 | + } |
|
2455 | 2520 | // Custom field? |
2456 | - elseif (isset($context['custom_field_titles'][$row['action']])) |
|
2457 | - $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
2458 | - else |
|
2459 | - $action_text = $row['action']; |
|
2521 | + elseif (isset($context['custom_field_titles'][$row['action']])) { |
|
2522 | + $action_text = $context['custom_field_titles'][$row['action']]['title']; |
|
2523 | + } else { |
|
2524 | + $action_text = $row['action']; |
|
2525 | + } |
|
2460 | 2526 | |
2461 | 2527 | // Parse BBC? |
2462 | 2528 | $parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false; |
@@ -2488,13 +2554,15 @@ discard block |
||
2488 | 2554 | ) |
2489 | 2555 | ); |
2490 | 2556 | $members = array(); |
2491 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2492 | - $members[$row['id_member']] = $row['real_name']; |
|
2557 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2558 | + $members[$row['id_member']] = $row['real_name']; |
|
2559 | + } |
|
2493 | 2560 | $smcFunc['db_free_result']($request); |
2494 | 2561 | |
2495 | - foreach ($edits as $key => $value) |
|
2496 | - if (isset($members[$value['id_member']])) |
|
2562 | + foreach ($edits as $key => $value) { |
|
2563 | + if (isset($members[$value['id_member']])) |
|
2497 | 2564 | $edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>'; |
2565 | + } |
|
2498 | 2566 | } |
2499 | 2567 | |
2500 | 2568 | return $edits; |
@@ -2695,10 +2763,11 @@ discard block |
||
2695 | 2763 | $context['board'] = $board; |
2696 | 2764 | |
2697 | 2765 | // Determine which groups this user is in. |
2698 | - if (empty($user_profile[$memID]['additional_groups'])) |
|
2699 | - $curGroups = array(); |
|
2700 | - else |
|
2701 | - $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
2766 | + if (empty($user_profile[$memID]['additional_groups'])) { |
|
2767 | + $curGroups = array(); |
|
2768 | + } else { |
|
2769 | + $curGroups = explode(',', $user_profile[$memID]['additional_groups']); |
|
2770 | + } |
|
2702 | 2771 | $curGroups[] = $user_profile[$memID]['id_group']; |
2703 | 2772 | $curGroups[] = $user_profile[$memID]['id_post_group']; |
2704 | 2773 | |
@@ -2718,28 +2787,30 @@ discard block |
||
2718 | 2787 | $context['no_access_boards'] = array(); |
2719 | 2788 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2720 | 2789 | { |
2721 | - if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) |
|
2722 | - $context['no_access_boards'][] = array( |
|
2790 | + if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) { |
|
2791 | + $context['no_access_boards'][] = array( |
|
2723 | 2792 | 'id' => $row['id_board'], |
2724 | 2793 | 'name' => $row['name'], |
2725 | 2794 | 'is_last' => false, |
2726 | 2795 | ); |
2727 | - elseif ($row['id_profile'] != 1 || $row['is_mod']) |
|
2728 | - $context['boards'][$row['id_board']] = array( |
|
2796 | + } elseif ($row['id_profile'] != 1 || $row['is_mod']) { |
|
2797 | + $context['boards'][$row['id_board']] = array( |
|
2729 | 2798 | 'id' => $row['id_board'], |
2730 | 2799 | 'name' => $row['name'], |
2731 | 2800 | 'selected' => $board == $row['id_board'], |
2732 | 2801 | 'profile' => $row['id_profile'], |
2733 | 2802 | 'profile_name' => $context['profiles'][$row['id_profile']]['name'], |
2734 | 2803 | ); |
2804 | + } |
|
2735 | 2805 | } |
2736 | 2806 | $smcFunc['db_free_result']($request); |
2737 | 2807 | |
2738 | 2808 | require_once($sourcedir . '/Subs-Boards.php'); |
2739 | 2809 | sortBoards($context['boards']); |
2740 | 2810 | |
2741 | - if (!empty($context['no_access_boards'])) |
|
2742 | - $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
2811 | + if (!empty($context['no_access_boards'])) { |
|
2812 | + $context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true; |
|
2813 | + } |
|
2743 | 2814 | |
2744 | 2815 | $context['member']['permissions'] = array( |
2745 | 2816 | 'general' => array(), |
@@ -2748,8 +2819,9 @@ discard block |
||
2748 | 2819 | |
2749 | 2820 | // If you're an admin we know you can do everything, we might as well leave. |
2750 | 2821 | $context['member']['has_all_permissions'] = in_array(1, $curGroups); |
2751 | - if ($context['member']['has_all_permissions']) |
|
2752 | - return; |
|
2822 | + if ($context['member']['has_all_permissions']) { |
|
2823 | + return; |
|
2824 | + } |
|
2753 | 2825 | |
2754 | 2826 | $denied = array(); |
2755 | 2827 | |
@@ -2768,21 +2840,24 @@ discard block |
||
2768 | 2840 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2769 | 2841 | { |
2770 | 2842 | // We don't know about this permission, it doesn't exist :P. |
2771 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
2772 | - continue; |
|
2843 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
2844 | + continue; |
|
2845 | + } |
|
2773 | 2846 | |
2774 | - if (empty($row['add_deny'])) |
|
2775 | - $denied[] = $row['permission']; |
|
2847 | + if (empty($row['add_deny'])) { |
|
2848 | + $denied[] = $row['permission']; |
|
2849 | + } |
|
2776 | 2850 | |
2777 | 2851 | // Permissions that end with _own or _any consist of two parts. |
2778 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
2779 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
2780 | - else |
|
2781 | - $name = $txt['permissionname_' . $row['permission']]; |
|
2852 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
2853 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
2854 | + } else { |
|
2855 | + $name = $txt['permissionname_' . $row['permission']]; |
|
2856 | + } |
|
2782 | 2857 | |
2783 | 2858 | // Add this permission if it doesn't exist yet. |
2784 | - if (!isset($context['member']['permissions']['general'][$row['permission']])) |
|
2785 | - $context['member']['permissions']['general'][$row['permission']] = array( |
|
2859 | + if (!isset($context['member']['permissions']['general'][$row['permission']])) { |
|
2860 | + $context['member']['permissions']['general'][$row['permission']] = array( |
|
2786 | 2861 | 'id' => $row['permission'], |
2787 | 2862 | 'groups' => array( |
2788 | 2863 | 'allowed' => array(), |
@@ -2792,6 +2867,7 @@ discard block |
||
2792 | 2867 | 'is_denied' => false, |
2793 | 2868 | 'is_global' => true, |
2794 | 2869 | ); |
2870 | + } |
|
2795 | 2871 | |
2796 | 2872 | // Add the membergroup to either the denied or the allowed groups. |
2797 | 2873 | $context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
@@ -2825,18 +2901,20 @@ discard block |
||
2825 | 2901 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2826 | 2902 | { |
2827 | 2903 | // We don't know about this permission, it doesn't exist :P. |
2828 | - if (!isset($txt['permissionname_' . $row['permission']])) |
|
2829 | - continue; |
|
2904 | + if (!isset($txt['permissionname_' . $row['permission']])) { |
|
2905 | + continue; |
|
2906 | + } |
|
2830 | 2907 | |
2831 | 2908 | // The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'. |
2832 | - if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) |
|
2833 | - $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
2834 | - else |
|
2835 | - $name = $txt['permissionname_' . $row['permission']]; |
|
2909 | + if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) { |
|
2910 | + $name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']]; |
|
2911 | + } else { |
|
2912 | + $name = $txt['permissionname_' . $row['permission']]; |
|
2913 | + } |
|
2836 | 2914 | |
2837 | 2915 | // Create the structure for this permission. |
2838 | - if (!isset($context['member']['permissions']['board'][$row['permission']])) |
|
2839 | - $context['member']['permissions']['board'][$row['permission']] = array( |
|
2916 | + if (!isset($context['member']['permissions']['board'][$row['permission']])) { |
|
2917 | + $context['member']['permissions']['board'][$row['permission']] = array( |
|
2840 | 2918 | 'id' => $row['permission'], |
2841 | 2919 | 'groups' => array( |
2842 | 2920 | 'allowed' => array(), |
@@ -2846,6 +2924,7 @@ discard block |
||
2846 | 2924 | 'is_denied' => false, |
2847 | 2925 | 'is_global' => empty($board), |
2848 | 2926 | ); |
2927 | + } |
|
2849 | 2928 | |
2850 | 2929 | $context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name']; |
2851 | 2930 | |
@@ -2864,8 +2943,9 @@ discard block |
||
2864 | 2943 | global $modSettings, $context, $sourcedir, $txt, $scripturl; |
2865 | 2944 | |
2866 | 2945 | // Firstly, can we actually even be here? |
2867 | - if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) |
|
2868 | - fatal_lang_error('no_access', false); |
|
2946 | + if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) { |
|
2947 | + fatal_lang_error('no_access', false); |
|
2948 | + } |
|
2869 | 2949 | |
2870 | 2950 | // Make sure things which are disabled stay disabled. |
2871 | 2951 | $modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110; |
@@ -2952,9 +3032,10 @@ discard block |
||
2952 | 3032 | $modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'], |
2953 | 3033 | ); |
2954 | 3034 | $context['current_level'] = 0; |
2955 | - foreach ($context['level_effects'] as $limit => $dummy) |
|
2956 | - if ($context['member']['warning'] >= $limit) |
|
3035 | + foreach ($context['level_effects'] as $limit => $dummy) { |
|
3036 | + if ($context['member']['warning'] >= $limit) |
|
2957 | 3037 | $context['current_level'] = $limit; |
2958 | -} |
|
3038 | + } |
|
3039 | + } |
|
2959 | 3040 | |
2960 | 3041 | ?> |
2961 | 3042 | \ No newline at end of file |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Interface cache_api_interface |
@@ -182,8 +183,9 @@ discard block |
||
182 | 183 | { |
183 | 184 | global $cache_enable; |
184 | 185 | |
185 | - if ($test) |
|
186 | - return true; |
|
186 | + if ($test) { |
|
187 | + return true; |
|
188 | + } |
|
187 | 189 | return !empty($cache_enable); |
188 | 190 | } |
189 | 191 | |
@@ -202,18 +204,20 @@ discard block |
||
202 | 204 | global $boardurl, $cachedir; |
203 | 205 | |
204 | 206 | // Find a valid good file to do mtime checks on. |
205 | - if (file_exists($cachedir . '/' . 'index.php')) |
|
206 | - $filemtime = $cachedir . '/' . 'index.php'; |
|
207 | - elseif (is_dir($cachedir . '/')) |
|
208 | - $filemtime = $cachedir . '/'; |
|
209 | - else |
|
210 | - $filemtime = $boardurl . '/index.php'; |
|
207 | + if (file_exists($cachedir . '/' . 'index.php')) { |
|
208 | + $filemtime = $cachedir . '/' . 'index.php'; |
|
209 | + } elseif (is_dir($cachedir . '/')) { |
|
210 | + $filemtime = $cachedir . '/'; |
|
211 | + } else { |
|
212 | + $filemtime = $boardurl . '/index.php'; |
|
213 | + } |
|
211 | 214 | |
212 | 215 | // Set the default if no prefix was specified. |
213 | - if (empty($prefix)) |
|
214 | - $this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-'; |
|
215 | - else |
|
216 | - $this->prefix = $prefix; |
|
216 | + if (empty($prefix)) { |
|
217 | + $this->prefix = md5($boardurl . filemtime($filemtime)) . '-SMF-'; |
|
218 | + } else { |
|
219 | + $this->prefix = $prefix; |
|
220 | + } |
|
217 | 221 | |
218 | 222 | return true; |
219 | 223 | } |
@@ -276,8 +280,9 @@ discard block |
||
276 | 280 | |
277 | 281 | // Invalidate cache, to be sure! |
278 | 282 | // ... as long as index.php can be modified, anyway. |
279 | - if (is_writable($cachedir . '/' . 'index.php')) |
|
280 | - @touch($cachedir . '/' . 'index.php'); |
|
283 | + if (is_writable($cachedir . '/' . 'index.php')) { |
|
284 | + @touch($cachedir . '/' . 'index.php'); |
|
285 | + } |
|
281 | 286 | |
282 | 287 | return true; |
283 | 288 | } |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * SQLite Cache API class |
@@ -68,8 +69,9 @@ discard block |
||
68 | 69 | { |
69 | 70 | $supported = class_exists("SQLite3") && is_writable($this->cachedir); |
70 | 71 | |
71 | - if ($test) |
|
72 | - return $supported; |
|
72 | + if ($test) { |
|
73 | + return $supported; |
|
74 | + } |
|
73 | 75 | |
74 | 76 | return parent::isSupported() && $supported; |
75 | 77 | } |
@@ -84,8 +86,9 @@ discard block |
||
84 | 86 | $result = $this->cacheDB->query($query); |
85 | 87 | |
86 | 88 | $value = null; |
87 | - while ($res = $result->fetchArray(SQLITE3_ASSOC)) |
|
88 | - $value = $res['value']; |
|
89 | + while ($res = $result->fetchArray(SQLITE3_ASSOC)) { |
|
90 | + $value = $res['value']; |
|
91 | + } |
|
89 | 92 | |
90 | 93 | return !empty($value) ? $value : null; |
91 | 94 | } |
@@ -125,8 +128,9 @@ discard block |
||
125 | 128 | $config_vars[] = $txt['cache_sqlite_settings']; |
126 | 129 | $config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir'); |
127 | 130 | |
128 | - if (!isset($context['settings_post_javascript'])) |
|
129 | - $context['settings_post_javascript'] = ''; |
|
131 | + if (!isset($context['settings_post_javascript'])) { |
|
132 | + $context['settings_post_javascript'] = ''; |
|
133 | + } |
|
130 | 134 | |
131 | 135 | $context['settings_post_javascript'] .= ' |
132 | 136 | $("#cache_accelerator").change(function (e) { |
@@ -149,10 +153,11 @@ discard block |
||
149 | 153 | global $cachedir_sqlite; |
150 | 154 | |
151 | 155 | // If its invalid, use SMF's. |
152 | - if (is_null($dir) || !is_writable($dir)) |
|
153 | - $this->cachedir = $cachedir_sqlite; |
|
154 | - else |
|
155 | - $this->cachedir = $dir; |
|
156 | + if (is_null($dir) || !is_writable($dir)) { |
|
157 | + $this->cachedir = $cachedir_sqlite; |
|
158 | + } else { |
|
159 | + $this->cachedir = $dir; |
|
160 | + } |
|
156 | 161 | } |
157 | 162 | |
158 | 163 | /** |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * PostgreSQL Cache API class |
@@ -49,8 +50,9 @@ discard block |
||
49 | 50 | |
50 | 51 | $result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache')); |
51 | 52 | |
52 | - if (pg_affected_rows($result) === 0) |
|
53 | - pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))'); |
|
53 | + if (pg_affected_rows($result) === 0) { |
|
54 | + pg_query($db_connection, 'CREATE UNLOGGED TABLE {db_prefix}cache (key text, value text, ttl bigint, PRIMARY KEY (key))'); |
|
55 | + } |
|
54 | 56 | } |
55 | 57 | |
56 | 58 | /** |
@@ -60,14 +62,16 @@ discard block |
||
60 | 62 | { |
61 | 63 | global $smcFunc, $db_connection; |
62 | 64 | |
63 | - if ($smcFunc['db_title'] !== 'PostgreSQL') |
|
64 | - return false; |
|
65 | + if ($smcFunc['db_title'] !== 'PostgreSQL') { |
|
66 | + return false; |
|
67 | + } |
|
65 | 68 | |
66 | 69 | $result = pg_query($db_connection, 'SHOW server_version_num'); |
67 | 70 | $res = pg_fetch_assoc($result); |
68 | 71 | |
69 | - if ($res['server_version_num'] < 90500) |
|
70 | - return false; |
|
72 | + if ($res['server_version_num'] < 90500) { |
|
73 | + return false; |
|
74 | + } |
|
71 | 75 | |
72 | 76 | return $test ? true : parent::isSupported(); |
73 | 77 | } |
@@ -81,13 +85,15 @@ discard block |
||
81 | 85 | |
82 | 86 | $ttl = time() - $ttl; |
83 | 87 | |
84 | - if (empty($this->pg_get_data_prep)) |
|
85 | - $this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1'); |
|
88 | + if (empty($this->pg_get_data_prep)) { |
|
89 | + $this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1'); |
|
90 | + } |
|
86 | 91 | |
87 | 92 | $result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl)); |
88 | 93 | |
89 | - if (pg_affected_rows($result) === 0) |
|
90 | - return null; |
|
94 | + if (pg_affected_rows($result) === 0) { |
|
95 | + return null; |
|
96 | + } |
|
91 | 97 | |
92 | 98 | $res = pg_fetch_assoc($result); |
93 | 99 | |
@@ -101,23 +107,26 @@ discard block |
||
101 | 107 | { |
102 | 108 | global $db_prefix, $db_connection; |
103 | 109 | |
104 | - if (!isset($value)) |
|
105 | - $value = ''; |
|
110 | + if (!isset($value)) { |
|
111 | + $value = ''; |
|
112 | + } |
|
106 | 113 | |
107 | 114 | $ttl = time() + $ttl; |
108 | 115 | |
109 | - if (empty($this->pg_put_data_prep)) |
|
110 | - $this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data', |
|
116 | + if (empty($this->pg_put_data_prep)) { |
|
117 | + $this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data', |
|
111 | 118 | 'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3) |
112 | 119 | ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl' |
113 | 120 | ); |
121 | + } |
|
114 | 122 | |
115 | 123 | $result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl)); |
116 | 124 | |
117 | - if (pg_affected_rows($result) > 0) |
|
118 | - return true; |
|
119 | - else |
|
120 | - return false; |
|
125 | + if (pg_affected_rows($result) > 0) { |
|
126 | + return true; |
|
127 | + } else { |
|
128 | + return false; |
|
129 | + } |
|
121 | 130 | } |
122 | 131 | |
123 | 132 | /** |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Prepares the information from the moderation log for viewing. |
@@ -32,14 +33,16 @@ discard block |
||
32 | 33 | |
33 | 34 | // Are we looking at the moderation log or the administration log. |
34 | 35 | $context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 3 : 1; |
35 | - if ($context['log_type'] == 3) |
|
36 | - isAllowedTo('admin_forum'); |
|
36 | + if ($context['log_type'] == 3) { |
|
37 | + isAllowedTo('admin_forum'); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | // These change dependant on whether we are viewing the moderation or admin log. |
39 | - if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') |
|
40 | - $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
41 | - else |
|
42 | - $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
41 | + if ($context['log_type'] == 3 || $_REQUEST['action'] == 'admin') { |
|
42 | + $context['url_start'] = '?action=admin;area=logs;sa=' . ($context['log_type'] == 3 ? 'adminlog' : 'modlog') . ';type=' . $context['log_type']; |
|
43 | + } else { |
|
44 | + $context['url_start'] = '?action=moderate;area=modlog;type=' . $context['log_type']; |
|
45 | + } |
|
43 | 46 | |
44 | 47 | $context['can_delete'] = allowedTo('admin_forum'); |
45 | 48 | |
@@ -67,8 +70,7 @@ discard block |
||
67 | 70 | $log_type = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'adminlog' ? 'admin' : 'moderate'; |
68 | 71 | logAction('clearlog_' . $log_type, array(), $log_type); |
69 | 72 | |
70 | - } |
|
71 | - elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
73 | + } elseif (!empty($_POST['remove']) && isset($_POST['delete']) && $context['can_delete']) |
|
72 | 74 | { |
73 | 75 | checkSession(); |
74 | 76 | validateToken('mod-ml'); |
@@ -114,15 +116,17 @@ discard block |
||
114 | 116 | 'ip' => array('sql' => 'lm.ip', 'label' => $txt['modlog_ip']) |
115 | 117 | ); |
116 | 118 | |
117 | - if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) |
|
118 | - $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
119 | - else |
|
120 | - $search_params_string = $search_params['string']; |
|
119 | + if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) { |
|
120 | + $search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search']; |
|
121 | + } else { |
|
122 | + $search_params_string = $search_params['string']; |
|
123 | + } |
|
121 | 124 | |
122 | - if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) |
|
123 | - $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
124 | - else |
|
125 | - $search_params_type = $search_params['type']; |
|
125 | + if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) { |
|
126 | + $search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member'); |
|
127 | + } else { |
|
128 | + $search_params_type = $search_params['type']; |
|
129 | + } |
|
126 | 130 | |
127 | 131 | $search_params_column = $searchTypes[$search_params_type]['sql']; |
128 | 132 | $search_params = array( |
@@ -301,15 +305,16 @@ discard block |
||
301 | 305 | $context['default_list'] = 'moderation_log_list'; |
302 | 306 | |
303 | 307 | // If a hook has changed this, respect it. |
304 | - if (!empty($moderation_menu_name)) |
|
305 | - $context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name; |
|
306 | - elseif (isset($context['moderation_menu_name'])) |
|
307 | - $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
308 | + if (!empty($moderation_menu_name)) { |
|
309 | + $context[$context['moderation_menu_name']]['tab_data'] = $moderation_menu_name; |
|
310 | + } elseif (isset($context['moderation_menu_name'])) { |
|
311 | + $context[$context['moderation_menu_name']]['tab_data'] = array( |
|
308 | 312 | 'title' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log'], |
309 | 313 | 'help' => $context['log_type'] == 3 ? 'adminlog' : 'modlog', |
310 | 314 | 'description' => $txt['modlog_' . ($context['log_type'] == 3 ? 'admin' : 'moderation') . '_log_desc'] |
311 | 315 | ); |
312 | -} |
|
316 | + } |
|
317 | + } |
|
313 | 318 | |
314 | 319 | /** |
315 | 320 | * Get the number of mod log entries. |
@@ -413,30 +418,35 @@ discard block |
||
413 | 418 | // Add on some of the column stuff info |
414 | 419 | if (!empty($row['id_board'])) |
415 | 420 | { |
416 | - if ($row['action'] == 'move') |
|
417 | - $row['extra']['board_to'] = $row['id_board']; |
|
418 | - else |
|
419 | - $row['extra']['board'] = $row['id_board']; |
|
421 | + if ($row['action'] == 'move') { |
|
422 | + $row['extra']['board_to'] = $row['id_board']; |
|
423 | + } else { |
|
424 | + $row['extra']['board'] = $row['id_board']; |
|
425 | + } |
|
420 | 426 | } |
421 | 427 | |
422 | - if (!empty($row['id_topic'])) |
|
423 | - $row['extra']['topic'] = $row['id_topic']; |
|
424 | - if (!empty($row['id_msg'])) |
|
425 | - $row['extra']['message'] = $row['id_msg']; |
|
428 | + if (!empty($row['id_topic'])) { |
|
429 | + $row['extra']['topic'] = $row['id_topic']; |
|
430 | + } |
|
431 | + if (!empty($row['id_msg'])) { |
|
432 | + $row['extra']['message'] = $row['id_msg']; |
|
433 | + } |
|
426 | 434 | |
427 | 435 | // Is this associated with a topic? |
428 | - if (isset($row['extra']['topic'])) |
|
429 | - $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
430 | - if (isset($row['extra']['new_topic'])) |
|
431 | - $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
436 | + if (isset($row['extra']['topic'])) { |
|
437 | + $topics[(int) $row['extra']['topic']][] = $row['id_action']; |
|
438 | + } |
|
439 | + if (isset($row['extra']['new_topic'])) { |
|
440 | + $topics[(int) $row['extra']['new_topic']][] = $row['id_action']; |
|
441 | + } |
|
432 | 442 | |
433 | 443 | // How about a member? |
434 | 444 | if (isset($row['extra']['member'])) |
435 | 445 | { |
436 | 446 | // Guests don't have names! |
437 | - if (empty($row['extra']['member'])) |
|
438 | - $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
439 | - else |
|
447 | + if (empty($row['extra']['member'])) { |
|
448 | + $row['extra']['member'] = $txt['modlog_parameter_guest']; |
|
449 | + } else |
|
440 | 450 | { |
441 | 451 | // Try to find it... |
442 | 452 | $members[(int) $row['extra']['member']][] = $row['id_action']; |
@@ -444,35 +454,42 @@ discard block |
||
444 | 454 | } |
445 | 455 | |
446 | 456 | // Associated with a board? |
447 | - if (isset($row['extra']['board_to'])) |
|
448 | - $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
449 | - if (isset($row['extra']['board_from'])) |
|
450 | - $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
451 | - if (isset($row['extra']['board'])) |
|
452 | - $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
457 | + if (isset($row['extra']['board_to'])) { |
|
458 | + $boards[(int) $row['extra']['board_to']][] = $row['id_action']; |
|
459 | + } |
|
460 | + if (isset($row['extra']['board_from'])) { |
|
461 | + $boards[(int) $row['extra']['board_from']][] = $row['id_action']; |
|
462 | + } |
|
463 | + if (isset($row['extra']['board'])) { |
|
464 | + $boards[(int) $row['extra']['board']][] = $row['id_action']; |
|
465 | + } |
|
453 | 466 | |
454 | 467 | // A message? |
455 | - if (isset($row['extra']['message'])) |
|
456 | - $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
468 | + if (isset($row['extra']['message'])) { |
|
469 | + $messages[(int) $row['extra']['message']][] = $row['id_action']; |
|
470 | + } |
|
457 | 471 | |
458 | 472 | // IP Info? |
459 | - if (isset($row['extra']['ip_range'])) |
|
460 | - if ($seeIP) |
|
473 | + if (isset($row['extra']['ip_range'])) { |
|
474 | + if ($seeIP) |
|
461 | 475 | $row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>'; |
462 | - else |
|
463 | - $row['extra']['ip_range'] = $txt['logged']; |
|
476 | + } else { |
|
477 | + $row['extra']['ip_range'] = $txt['logged']; |
|
478 | + } |
|
464 | 479 | |
465 | 480 | // Email? |
466 | - if (isset($row['extra']['email'])) |
|
467 | - $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
481 | + if (isset($row['extra']['email'])) { |
|
482 | + $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>'; |
|
483 | + } |
|
468 | 484 | |
469 | 485 | // Bans are complex. |
470 | 486 | if ($row['action'] == 'ban' || $row['action'] == 'banremove') |
471 | 487 | { |
472 | 488 | $row['action_text'] = $txt['modlog_ac_ban' . ($row['action'] == 'banremove' ? '_remove' : '')]; |
473 | - foreach (array('member', 'email', 'ip_range', 'hostname') as $type) |
|
474 | - if (isset($row['extra'][$type])) |
|
489 | + foreach (array('member', 'email', 'ip_range', 'hostname') as $type) { |
|
490 | + if (isset($row['extra'][$type])) |
|
475 | 491 | $row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type]; |
492 | + } |
|
476 | 493 | } |
477 | 494 | |
478 | 495 | // The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details. |
@@ -508,12 +525,13 @@ discard block |
||
508 | 525 | foreach ($boards[$row['id_board']] as $action) |
509 | 526 | { |
510 | 527 | // Make the board number into a link - dealing with moving too. |
511 | - if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) |
|
512 | - $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
513 | - elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) |
|
514 | - $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
515 | - elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) |
|
516 | - $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
528 | + if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) { |
|
529 | + $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
530 | + } elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) { |
|
531 | + $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
532 | + } elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) { |
|
533 | + $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'; |
|
534 | + } |
|
517 | 535 | } |
518 | 536 | } |
519 | 537 | $smcFunc['db_free_result']($request); |
@@ -547,10 +565,11 @@ discard block |
||
547 | 565 | ); |
548 | 566 | |
549 | 567 | // Make the topic number into a link - dealing with splitting too. |
550 | - if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) |
|
551 | - $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
552 | - elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) |
|
553 | - $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
568 | + if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) { |
|
569 | + $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
570 | + } elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) { |
|
571 | + $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>'; |
|
572 | + } |
|
554 | 573 | } |
555 | 574 | } |
556 | 575 | $smcFunc['db_free_result']($request); |
@@ -583,8 +602,9 @@ discard block |
||
583 | 602 | ); |
584 | 603 | |
585 | 604 | // Make the message number into a link. |
586 | - if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) |
|
587 | - $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
605 | + if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) { |
|
606 | + $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>'; |
|
607 | + } |
|
588 | 608 | } |
589 | 609 | } |
590 | 610 | $smcFunc['db_free_result']($request); |
@@ -624,25 +644,29 @@ discard block |
||
624 | 644 | foreach ($entries as $k => $entry) |
625 | 645 | { |
626 | 646 | // Make any message info links so its easier to go find that message. |
627 | - if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) |
|
628 | - $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
647 | + if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) { |
|
648 | + $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>'; |
|
649 | + } |
|
629 | 650 | |
630 | 651 | // Mark up any deleted members, topics and boards. |
631 | - foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) |
|
632 | - if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
652 | + foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) { |
|
653 | + if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) |
|
633 | 654 | $entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]); |
655 | + } |
|
634 | 656 | |
635 | 657 | if (isset($entry['extra']['report'])) |
636 | 658 | { |
637 | 659 | // Member profile reports go in a different area |
638 | - if (stristr($entry['action'], 'user_report')) |
|
639 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
640 | - else |
|
641 | - $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
660 | + if (stristr($entry['action'], 'user_report')) { |
|
661 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedmembers;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
662 | + } else { |
|
663 | + $entries[$k]['extra']['report'] = '<a href="' . $scripturl . '?action=moderate;area=reportedposts;sa=details;rid=' . $entry['extra']['report'] . '">' . $txt['modlog_report'] . '</a>'; |
|
664 | + } |
|
642 | 665 | } |
643 | 666 | |
644 | - if (empty($entries[$k]['action_text'])) |
|
645 | - $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
667 | + if (empty($entries[$k]['action_text'])) { |
|
668 | + $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action']; |
|
669 | + } |
|
646 | 670 | $entries[$k]['action_text'] = preg_replace_callback('~\{([A-Za-z\d_]+)\}~i', |
647 | 671 | function ($matches) use ($entries, $k) |
648 | 672 | { |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Retrieve a list and several other statistics of the users currently online. |
@@ -45,8 +46,9 @@ discard block |
||
45 | 46 | } |
46 | 47 | |
47 | 48 | // Not allowed sort method? Bang! Error! |
48 | - elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) |
|
49 | - trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
49 | + elseif (!in_array($membersOnlineOptions['sort'], $allowed_sort_options)) { |
|
50 | + trigger_error('Sort method for getMembersOnlineStats() function is not allowed', E_USER_NOTICE); |
|
51 | + } |
|
50 | 52 | |
51 | 53 | // Initialize the array that'll be returned later on. |
52 | 54 | $membersOnlineStats = array( |
@@ -63,8 +65,9 @@ discard block |
||
63 | 65 | // Get any spiders if enabled. |
64 | 66 | $spiders = array(); |
65 | 67 | $spider_finds = array(); |
66 | - if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) |
|
67 | - $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
68 | + if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] < 3 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) { |
|
69 | + $spiders = $smcFunc['json_decode']($modSettings['spider_name_cache'], true); |
|
70 | + } |
|
68 | 71 | |
69 | 72 | // Load the users online right now. |
70 | 73 | $request = $smcFunc['db_query']('', ' |
@@ -92,9 +95,7 @@ discard block |
||
92 | 95 | $membersOnlineStats['num_guests']++; |
93 | 96 | |
94 | 97 | continue; |
95 | - } |
|
96 | - |
|
97 | - elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
98 | + } elseif (empty($row['show_online']) && empty($membersOnlineOptions['show_hidden'])) |
|
98 | 99 | { |
99 | 100 | // Just increase the stats and don't add this hidden user to any list. |
100 | 101 | $membersOnlineStats['num_users_hidden']++; |
@@ -102,10 +103,11 @@ discard block |
||
102 | 103 | } |
103 | 104 | |
104 | 105 | // Some basic color coding... |
105 | - if (!empty($row['online_color'])) |
|
106 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
107 | - else |
|
108 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
106 | + if (!empty($row['online_color'])) { |
|
107 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
108 | + } else { |
|
109 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
110 | + } |
|
109 | 111 | |
110 | 112 | // Buddies get counted and highlighted. |
111 | 113 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
@@ -132,8 +134,8 @@ discard block |
||
132 | 134 | $membersOnlineStats['list_users_online'][$row[$membersOnlineOptions['sort']] . '_' . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
133 | 135 | |
134 | 136 | // Store all distinct (primary) membergroups that are shown. |
135 | - if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) |
|
136 | - $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
137 | + if (!isset($membersOnlineStats['online_groups'][$row['id_group']])) { |
|
138 | + $membersOnlineStats['online_groups'][$row['id_group']] = array( |
|
137 | 139 | 'id' => $row['id_group'], |
138 | 140 | 'name' => $row['group_name'], |
139 | 141 | 'color' => $row['online_color'], |
@@ -141,6 +143,7 @@ discard block |
||
141 | 143 | 'type' => $row['group_type'], |
142 | 144 | 'parent' => $row['id_parent'], |
143 | 145 | ); |
146 | + } |
|
144 | 147 | } |
145 | 148 | $smcFunc['db_free_result']($request); |
146 | 149 | |
@@ -201,11 +204,12 @@ discard block |
||
201 | 204 | $settingsToUpdate = array(); |
202 | 205 | |
203 | 206 | // More members on now than ever were? Update it! |
204 | - if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) |
|
205 | - $settingsToUpdate = array( |
|
207 | + if (!isset($modSettings['mostOnline']) || $total_users_online >= $modSettings['mostOnline']) { |
|
208 | + $settingsToUpdate = array( |
|
206 | 209 | 'mostOnline' => $total_users_online, |
207 | 210 | 'mostDate' => time() |
208 | 211 | ); |
212 | + } |
|
209 | 213 | |
210 | 214 | $date = strftime('%Y-%m-%d', forum_time(false)); |
211 | 215 | |
@@ -237,8 +241,9 @@ discard block |
||
237 | 241 | { |
238 | 242 | list ($modSettings['mostOnlineToday']) = $smcFunc['db_fetch_row']($request); |
239 | 243 | |
240 | - if ($total_users_online > $modSettings['mostOnlineToday']) |
|
241 | - trackStats(array('most_on' => $total_users_online)); |
|
244 | + if ($total_users_online > $modSettings['mostOnlineToday']) { |
|
245 | + trackStats(array('most_on' => $total_users_online)); |
|
246 | + } |
|
242 | 247 | |
243 | 248 | $total_users_online = max($total_users_online, $modSettings['mostOnlineToday']); |
244 | 249 | } |
@@ -255,8 +260,9 @@ discard block |
||
255 | 260 | $settingsToUpdate['mostOnlineToday'] = $total_users_online; |
256 | 261 | } |
257 | 262 | |
258 | - if (!empty($settingsToUpdate)) |
|
259 | - updateSettings($settingsToUpdate); |
|
260 | -} |
|
263 | + if (!empty($settingsToUpdate)) { |
|
264 | + updateSettings($settingsToUpdate); |
|
265 | + } |
|
266 | + } |
|
261 | 267 | |
262 | 268 | ?> |
263 | 269 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * Show the list of topics in this board, along with any child boards. |
@@ -56,8 +57,9 @@ discard block |
||
56 | 57 | |
57 | 58 | $context['name'] = $board_info['name']; |
58 | 59 | $context['description'] = $board_info['description']; |
59 | - if (!empty($board_info['description'])) |
|
60 | - $context['meta_description'] = strip_tags($board_info['description']); |
|
60 | + if (!empty($board_info['description'])) { |
|
61 | + $context['meta_description'] = strip_tags($board_info['description']); |
|
62 | + } |
|
61 | 63 | |
62 | 64 | // How many topics do we have in total? |
63 | 65 | $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics']; |
@@ -73,12 +75,14 @@ discard block |
||
73 | 75 | $session_name = session_name(); |
74 | 76 | foreach ($_GET as $k => $v) |
75 | 77 | { |
76 | - if (!in_array($k, array('board', 'start', $session_name))) |
|
77 | - $context['robot_no_index'] = true; |
|
78 | + if (!in_array($k, array('board', 'start', $session_name))) { |
|
79 | + $context['robot_no_index'] = true; |
|
80 | + } |
|
78 | 81 | } |
79 | 82 | } |
80 | - if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) |
|
81 | - $context['robot_no_index'] = true; |
|
83 | + if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) { |
|
84 | + $context['robot_no_index'] = true; |
|
85 | + } |
|
82 | 86 | |
83 | 87 | // If we can view unapproved messages and there are some build up a list. |
84 | 88 | if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) |
@@ -89,14 +93,16 @@ discard block |
||
89 | 93 | } |
90 | 94 | |
91 | 95 | // We only know these. |
92 | - if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) |
|
93 | - $_REQUEST['sort'] = 'last_post'; |
|
96 | + if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) { |
|
97 | + $_REQUEST['sort'] = 'last_post'; |
|
98 | + } |
|
94 | 99 | |
95 | 100 | // Make sure the starting place makes sense and construct the page index. |
96 | - if (isset($_REQUEST['sort'])) |
|
97 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
98 | - else |
|
99 | - $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
101 | + if (isset($_REQUEST['sort'])) { |
|
102 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
103 | + } else { |
|
104 | + $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true); |
|
105 | + } |
|
100 | 106 | $context['start'] = &$_REQUEST['start']; |
101 | 107 | |
102 | 108 | // Set a canonical URL for this page. |
@@ -132,14 +138,16 @@ discard block |
||
132 | 138 | $context['link_moderators'] = array(); |
133 | 139 | if (!empty($board_info['moderators'])) |
134 | 140 | { |
135 | - foreach ($board_info['moderators'] as $mod) |
|
136 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
141 | + foreach ($board_info['moderators'] as $mod) { |
|
142 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>'; |
|
143 | + } |
|
137 | 144 | } |
138 | 145 | if (!empty($board_info['moderator_groups'])) |
139 | 146 | { |
140 | 147 | // By default just tack the moderator groups onto the end of the members |
141 | - foreach ($board_info['moderator_groups'] as $mod_group) |
|
142 | - $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
148 | + foreach ($board_info['moderator_groups'] as $mod_group) { |
|
149 | + $context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>'; |
|
150 | + } |
|
143 | 151 | } |
144 | 152 | |
145 | 153 | // Now we tack the info onto the end of the linktree |
@@ -191,20 +199,24 @@ discard block |
||
191 | 199 | ); |
192 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
193 | 201 | { |
194 | - if (empty($row['id_member'])) |
|
195 | - continue; |
|
202 | + if (empty($row['id_member'])) { |
|
203 | + continue; |
|
204 | + } |
|
196 | 205 | |
197 | - if (!empty($row['online_color'])) |
|
198 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
199 | - else |
|
200 | - $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
206 | + if (!empty($row['online_color'])) { |
|
207 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>'; |
|
208 | + } else { |
|
209 | + $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; |
|
210 | + } |
|
201 | 211 | |
202 | 212 | $is_buddy = in_array($row['id_member'], $user_info['buddies']); |
203 | - if ($is_buddy) |
|
204 | - $link = '<strong>' . $link . '</strong>'; |
|
213 | + if ($is_buddy) { |
|
214 | + $link = '<strong>' . $link . '</strong>'; |
|
215 | + } |
|
205 | 216 | |
206 | - if (!empty($row['show_online']) || allowedTo('moderate_forum')) |
|
207 | - $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
217 | + if (!empty($row['show_online']) || allowedTo('moderate_forum')) { |
|
218 | + $context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link; |
|
219 | + } |
|
208 | 220 | // @todo why are we filling this array of data that are just counted (twice) and discarded? ??? |
209 | 221 | $context['view_members'][$row['log_time'] . $row['member_name']] = array( |
210 | 222 | 'id' => $row['id_member'], |
@@ -217,8 +229,9 @@ discard block |
||
217 | 229 | 'hidden' => empty($row['show_online']), |
218 | 230 | ); |
219 | 231 | |
220 | - if (empty($row['show_online'])) |
|
221 | - $context['view_num_hidden']++; |
|
232 | + if (empty($row['show_online'])) { |
|
233 | + $context['view_num_hidden']++; |
|
234 | + } |
|
222 | 235 | } |
223 | 236 | $context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']); |
224 | 237 | $smcFunc['db_free_result']($request); |
@@ -260,8 +273,9 @@ discard block |
||
260 | 273 | // Bring in any changes we want to make before the query. |
261 | 274 | call_integration_hook('integrate_pre_messageindex', array(&$sort_methods)); |
262 | 275 | |
263 | - foreach ($sort_methods as $key => $val) |
|
264 | - $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
276 | + foreach ($sort_methods as $key => $val) { |
|
277 | + $context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>'; |
|
278 | + } |
|
265 | 279 | |
266 | 280 | // Calculate the fastest way to get the topics. |
267 | 281 | $start = (int) $_REQUEST['start']; |
@@ -271,14 +285,15 @@ discard block |
||
271 | 285 | $fake_ascending = true; |
272 | 286 | $context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex']; |
273 | 287 | $start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex']; |
288 | + } else { |
|
289 | + $fake_ascending = false; |
|
274 | 290 | } |
275 | - else |
|
276 | - $fake_ascending = false; |
|
277 | 291 | |
278 | 292 | // Setup the default topic icons... |
279 | 293 | $context['icon_sources'] = array(); |
280 | - foreach ($context['stable_icons'] as $icon) |
|
281 | - $context['icon_sources'][$icon] = 'images_url'; |
|
294 | + foreach ($context['stable_icons'] as $icon) { |
|
295 | + $context['icon_sources'][$icon] = 'images_url'; |
|
296 | + } |
|
282 | 297 | |
283 | 298 | $topic_ids = array(); |
284 | 299 | $context['topics'] = array(); |
@@ -316,8 +331,9 @@ discard block |
||
316 | 331 | $message_pre_index_parameters |
317 | 332 | ); |
318 | 333 | $topic_ids = array(); |
319 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
320 | - $topic_ids[] = $row['id_topic']; |
|
334 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
335 | + $topic_ids[] = $row['id_topic']; |
|
336 | + } |
|
321 | 337 | } |
322 | 338 | |
323 | 339 | // Grab the appropriate topic information... |
@@ -375,11 +391,13 @@ discard block |
||
375 | 391 | // Begin 'printing' the message index for current board. |
376 | 392 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
377 | 393 | { |
378 | - if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') |
|
379 | - continue; |
|
394 | + if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') { |
|
395 | + continue; |
|
396 | + } |
|
380 | 397 | |
381 | - if (!$pre_query) |
|
382 | - $topic_ids[] = $row['id_topic']; |
|
398 | + if (!$pre_query) { |
|
399 | + $topic_ids[] = $row['id_topic']; |
|
400 | + } |
|
383 | 401 | |
384 | 402 | // Reference the main color class. |
385 | 403 | $colorClass = 'windowbg'; |
@@ -389,8 +407,9 @@ discard block |
||
389 | 407 | { |
390 | 408 | // Limit them to $modSettings['preview_characters'] characters |
391 | 409 | $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => ' '))); |
392 | - if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) |
|
393 | - $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
410 | + if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) { |
|
411 | + $row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...'; |
|
412 | + } |
|
394 | 413 | |
395 | 414 | // Censor the subject and message preview. |
396 | 415 | censorText($row['first_subject']); |
@@ -401,27 +420,27 @@ discard block |
||
401 | 420 | { |
402 | 421 | $row['last_subject'] = $row['first_subject']; |
403 | 422 | $row['last_body'] = $row['first_body']; |
404 | - } |
|
405 | - else |
|
423 | + } else |
|
406 | 424 | { |
407 | 425 | $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => ' '))); |
408 | - if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) |
|
409 | - $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
426 | + if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) { |
|
427 | + $row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...'; |
|
428 | + } |
|
410 | 429 | |
411 | 430 | censorText($row['last_subject']); |
412 | 431 | censorText($row['last_body']); |
413 | 432 | } |
414 | - } |
|
415 | - else |
|
433 | + } else |
|
416 | 434 | { |
417 | 435 | $row['first_body'] = ''; |
418 | 436 | $row['last_body'] = ''; |
419 | 437 | censorText($row['first_subject']); |
420 | 438 | |
421 | - if ($row['id_first_msg'] == $row['id_last_msg']) |
|
422 | - $row['last_subject'] = $row['first_subject']; |
|
423 | - else |
|
424 | - censorText($row['last_subject']); |
|
439 | + if ($row['id_first_msg'] == $row['id_last_msg']) { |
|
440 | + $row['last_subject'] = $row['first_subject']; |
|
441 | + } else { |
|
442 | + censorText($row['last_subject']); |
|
443 | + } |
|
425 | 444 | } |
426 | 445 | |
427 | 446 | // Decide how many pages the topic should have. |
@@ -432,42 +451,50 @@ discard block |
||
432 | 451 | $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false); |
433 | 452 | |
434 | 453 | // If we can use all, show all. |
435 | - if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) |
|
436 | - $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
454 | + if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) { |
|
455 | + $pages .= ' <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>'; |
|
456 | + } |
|
457 | + } else { |
|
458 | + $pages = ''; |
|
437 | 459 | } |
438 | - else |
|
439 | - $pages = ''; |
|
440 | 460 | |
441 | 461 | // We need to check the topic icons exist... |
442 | 462 | if (!empty($modSettings['messageIconChecks_enable'])) |
443 | 463 | { |
444 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
445 | - $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
446 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
447 | - $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
448 | - } |
|
449 | - else |
|
464 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
465 | + $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
466 | + } |
|
467 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
468 | + $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
469 | + } |
|
470 | + } else |
|
450 | 471 | { |
451 | - if (!isset($context['icon_sources'][$row['first_icon']])) |
|
452 | - $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
453 | - if (!isset($context['icon_sources'][$row['last_icon']])) |
|
454 | - $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
472 | + if (!isset($context['icon_sources'][$row['first_icon']])) { |
|
473 | + $context['icon_sources'][$row['first_icon']] = 'images_url'; |
|
474 | + } |
|
475 | + if (!isset($context['icon_sources'][$row['last_icon']])) { |
|
476 | + $context['icon_sources'][$row['last_icon']] = 'images_url'; |
|
477 | + } |
|
455 | 478 | } |
456 | 479 | |
457 | - if (!empty($board_info['recycle'])) |
|
458 | - $row['first_icon'] = 'recycled'; |
|
480 | + if (!empty($board_info['recycle'])) { |
|
481 | + $row['first_icon'] = 'recycled'; |
|
482 | + } |
|
459 | 483 | |
460 | 484 | // Is this topic pending approval, or does it have any posts pending approval? |
461 | - if ($context['can_approve_posts'] && $row['unapproved_posts']) |
|
462 | - $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
485 | + if ($context['can_approve_posts'] && $row['unapproved_posts']) { |
|
486 | + $colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost'); |
|
487 | + } |
|
463 | 488 | |
464 | 489 | // Sticky topics should get a different color, too. |
465 | - if ($row['is_sticky']) |
|
466 | - $colorClass .= ' sticky'; |
|
490 | + if ($row['is_sticky']) { |
|
491 | + $colorClass .= ' sticky'; |
|
492 | + } |
|
467 | 493 | |
468 | 494 | // Locked topics get special treatment as well. |
469 | - if ($row['locked']) |
|
470 | - $colorClass .= ' locked'; |
|
495 | + if ($row['locked']) { |
|
496 | + $colorClass .= ' locked'; |
|
497 | + } |
|
471 | 498 | |
472 | 499 | // 'Print' the topic info. |
473 | 500 | $context['topics'][$row['id_topic']] = array_merge($row, array( |
@@ -548,8 +575,9 @@ discard block |
||
548 | 575 | $smcFunc['db_free_result']($result); |
549 | 576 | |
550 | 577 | // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...) |
551 | - if ($fake_ascending) |
|
552 | - $context['topics'] = array_reverse($context['topics'], true); |
|
578 | + if ($fake_ascending) { |
|
579 | + $context['topics'] = array_reverse($context['topics'], true); |
|
580 | + } |
|
553 | 581 | |
554 | 582 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids)) |
555 | 583 | { |
@@ -566,8 +594,9 @@ discard block |
||
566 | 594 | 'limit' => count($topic_ids), |
567 | 595 | ) |
568 | 596 | ); |
569 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
570 | - $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
597 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
598 | + $context['topics'][$row['id_topic']]['is_posted_in'] = true; |
|
599 | + } |
|
571 | 600 | $smcFunc['db_free_result']($result); |
572 | 601 | } |
573 | 602 | } |
@@ -592,9 +621,9 @@ discard block |
||
592 | 621 | // Can we restore topics? |
593 | 622 | $context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']); |
594 | 623 | |
595 | - if ($user_info['is_admin'] || $modSettings['topic_move_any']) |
|
596 | - $context['can_move_any'] = true; |
|
597 | - else |
|
624 | + if ($user_info['is_admin'] || $modSettings['topic_move_any']) { |
|
625 | + $context['can_move_any'] = true; |
|
626 | + } else |
|
598 | 627 | { |
599 | 628 | // We'll use this in a minute |
600 | 629 | $boards_allowed = boardsAllowedTo('post_new'); |
@@ -621,11 +650,13 @@ discard block |
||
621 | 650 | } |
622 | 651 | |
623 | 652 | // Can we use quick moderation checkboxes? |
624 | - if ($options['display_quick_mod'] == 1) |
|
625 | - $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
653 | + if ($options['display_quick_mod'] == 1) { |
|
654 | + $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore']; |
|
655 | + } |
|
626 | 656 | // Or the icons? |
627 | - else |
|
628 | - $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
657 | + else { |
|
658 | + $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move']; |
|
659 | + } |
|
629 | 660 | } |
630 | 661 | |
631 | 662 | if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) |
@@ -659,13 +690,15 @@ discard block |
||
659 | 690 | ); |
660 | 691 | |
661 | 692 | // We've seen all these boards now! |
662 | - foreach ($board_info['parent_boards'] as $k => $dummy) |
|
663 | - if (isset($_SESSION['topicseen_cache'][$k])) |
|
693 | + foreach ($board_info['parent_boards'] as $k => $dummy) { |
|
694 | + if (isset($_SESSION['topicseen_cache'][$k])) |
|
664 | 695 | unset($_SESSION['topicseen_cache'][$k]); |
696 | + } |
|
665 | 697 | } |
666 | 698 | |
667 | - if (isset($_SESSION['topicseen_cache'][$board])) |
|
668 | - unset($_SESSION['topicseen_cache'][$board]); |
|
699 | + if (isset($_SESSION['topicseen_cache'][$board])) { |
|
700 | + unset($_SESSION['topicseen_cache'][$board]); |
|
701 | + } |
|
669 | 702 | |
670 | 703 | $request = $smcFunc['db_query']('', ' |
671 | 704 | SELECT id_topic, id_board, sent |
@@ -686,8 +719,9 @@ discard block |
||
686 | 719 | $context['is_marked_notify'] = true; |
687 | 720 | $board_sent = $row['sent']; |
688 | 721 | } |
689 | - if (!empty($row['id_topic'])) |
|
690 | - $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
722 | + if (!empty($row['id_topic'])) { |
|
723 | + $context['topics'][$row['id_topic']]['is_watched'] = true; |
|
724 | + } |
|
691 | 725 | } |
692 | 726 | $smcFunc['db_free_result']($request); |
693 | 727 | |
@@ -711,8 +745,7 @@ discard block |
||
711 | 745 | $pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array(); |
712 | 746 | $pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0); |
713 | 747 | $context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1)); |
714 | - } |
|
715 | - else |
|
748 | + } else |
|
716 | 749 | { |
717 | 750 | $context['is_marked_notify'] = false; |
718 | 751 | $context['board_notification_mode'] = 1; |
@@ -725,23 +758,27 @@ discard block |
||
725 | 758 | $context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false; |
726 | 759 | |
727 | 760 | // Don't want to show this forever... |
728 | - if ($context['becomesUnapproved']) |
|
729 | - unset($_SESSION['becomesUnapproved']); |
|
761 | + if ($context['becomesUnapproved']) { |
|
762 | + unset($_SESSION['becomesUnapproved']); |
|
763 | + } |
|
730 | 764 | |
731 | 765 | // Build the message index button array. |
732 | 766 | $context['normal_buttons'] = array(); |
733 | 767 | |
734 | - if ($context['can_post_new']) |
|
735 | - $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
768 | + if ($context['can_post_new']) { |
|
769 | + $context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true); |
|
770 | + } |
|
736 | 771 | |
737 | - if ($context['can_post_poll']) |
|
738 | - $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
772 | + if ($context['can_post_poll']) { |
|
773 | + $context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll'); |
|
774 | + } |
|
739 | 775 | |
740 | - if (!$context['user']['is_logged']) |
|
741 | - $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
776 | + if (!$context['user']['is_logged']) { |
|
777 | + $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']); |
|
778 | + } |
|
742 | 779 | |
743 | - if ($context['can_mark_notify']) |
|
744 | - $context['normal_buttons']['notify'] = array( |
|
780 | + if ($context['can_mark_notify']) { |
|
781 | + $context['normal_buttons']['notify'] = array( |
|
745 | 782 | 'lang' => true, |
746 | 783 | 'text' => 'notify_board_' . $context['board_notification_mode'], |
747 | 784 | 'sub_buttons' => array( |
@@ -759,6 +796,7 @@ discard block |
||
759 | 796 | ), |
760 | 797 | ), |
761 | 798 | ); |
799 | + } |
|
762 | 800 | |
763 | 801 | // Javascript for inline editing. |
764 | 802 | loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic'); |
@@ -780,18 +818,21 @@ discard block |
||
780 | 818 | checkSession('request'); |
781 | 819 | |
782 | 820 | // Lets go straight to the restore area. |
783 | - if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) |
|
784 | - redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
821 | + if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) { |
|
822 | + redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
823 | + } |
|
785 | 824 | |
786 | - if (isset($_SESSION['topicseen_cache'])) |
|
787 | - $_SESSION['topicseen_cache'] = array(); |
|
825 | + if (isset($_SESSION['topicseen_cache'])) { |
|
826 | + $_SESSION['topicseen_cache'] = array(); |
|
827 | + } |
|
788 | 828 | |
789 | 829 | // This is going to be needed to send off the notifications and for updateLastMessages(). |
790 | 830 | require_once($sourcedir . '/Subs-Post.php'); |
791 | 831 | |
792 | 832 | // Remember the last board they moved things to. |
793 | - if (isset($_REQUEST['move_to'])) |
|
794 | - $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
833 | + if (isset($_REQUEST['move_to'])) { |
|
834 | + $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
|
835 | + } |
|
795 | 836 | |
796 | 837 | // Only a few possible actions. |
797 | 838 | $possibleActions = array(); |
@@ -811,8 +852,7 @@ discard block |
||
811 | 852 | ); |
812 | 853 | |
813 | 854 | $redirect_url = 'board=' . $board . '.' . $_REQUEST['start']; |
814 | - } |
|
815 | - else |
|
855 | + } else |
|
816 | 856 | { |
817 | 857 | /** |
818 | 858 | * @todo Ugly. There's no getting around this, is there? |
@@ -830,8 +870,7 @@ discard block |
||
830 | 870 | if (!empty($board)) |
831 | 871 | { |
832 | 872 | $boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board)); |
833 | - } |
|
834 | - else |
|
873 | + } else |
|
835 | 874 | { |
836 | 875 | $boards_can['post_new'] = boardsAllowedTo('post_new'); |
837 | 876 | } |
@@ -842,55 +881,67 @@ discard block |
||
842 | 881 | } |
843 | 882 | } |
844 | 883 | |
845 | - if (!$user_info['is_guest']) |
|
846 | - $possibleActions[] = 'markread'; |
|
847 | - if (!empty($boards_can['make_sticky'])) |
|
848 | - $possibleActions[] = 'sticky'; |
|
849 | - if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) |
|
850 | - $possibleActions[] = 'move'; |
|
851 | - if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) |
|
852 | - $possibleActions[] = 'remove'; |
|
853 | - if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) |
|
854 | - $possibleActions[] = 'lock'; |
|
855 | - if (!empty($boards_can['merge_any'])) |
|
856 | - $possibleActions[] = 'merge'; |
|
857 | - if (!empty($boards_can['approve_posts'])) |
|
858 | - $possibleActions[] = 'approve'; |
|
884 | + if (!$user_info['is_guest']) { |
|
885 | + $possibleActions[] = 'markread'; |
|
886 | + } |
|
887 | + if (!empty($boards_can['make_sticky'])) { |
|
888 | + $possibleActions[] = 'sticky'; |
|
889 | + } |
|
890 | + if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) { |
|
891 | + $possibleActions[] = 'move'; |
|
892 | + } |
|
893 | + if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) { |
|
894 | + $possibleActions[] = 'remove'; |
|
895 | + } |
|
896 | + if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) { |
|
897 | + $possibleActions[] = 'lock'; |
|
898 | + } |
|
899 | + if (!empty($boards_can['merge_any'])) { |
|
900 | + $possibleActions[] = 'merge'; |
|
901 | + } |
|
902 | + if (!empty($boards_can['approve_posts'])) { |
|
903 | + $possibleActions[] = 'approve'; |
|
904 | + } |
|
859 | 905 | |
860 | 906 | // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction']. |
861 | 907 | // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.) |
862 | 908 | if (!empty($_REQUEST['topics'])) |
863 | 909 | { |
864 | 910 | // If the action isn't valid, just quit now. |
865 | - if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) |
|
866 | - redirectexit($redirect_url); |
|
911 | + if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) { |
|
912 | + redirectexit($redirect_url); |
|
913 | + } |
|
867 | 914 | |
868 | 915 | // Merge requires all topics as one parameter and can be done at once. |
869 | 916 | if ($_REQUEST['qaction'] == 'merge') |
870 | 917 | { |
871 | 918 | // Merge requires at least two topics. |
872 | - if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) |
|
873 | - redirectexit($redirect_url); |
|
919 | + if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) { |
|
920 | + redirectexit($redirect_url); |
|
921 | + } |
|
874 | 922 | |
875 | 923 | require_once($sourcedir . '/SplitTopics.php'); |
876 | 924 | return MergeExecute($_REQUEST['topics']); |
877 | 925 | } |
878 | 926 | |
879 | 927 | // Just convert to the other method, to make it easier. |
880 | - foreach ($_REQUEST['topics'] as $topic) |
|
881 | - $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
928 | + foreach ($_REQUEST['topics'] as $topic) { |
|
929 | + $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
|
930 | + } |
|
882 | 931 | } |
883 | 932 | |
884 | 933 | // Weird... how'd you get here? |
885 | - if (empty($_REQUEST['actions'])) |
|
886 | - redirectexit($redirect_url); |
|
934 | + if (empty($_REQUEST['actions'])) { |
|
935 | + redirectexit($redirect_url); |
|
936 | + } |
|
887 | 937 | |
888 | 938 | // Validate each action. |
889 | 939 | $temp = array(); |
890 | 940 | foreach ($_REQUEST['actions'] as $topic => $action) |
891 | 941 | { |
892 | - if (in_array($action, $possibleActions)) |
|
893 | - $temp[(int) $topic] = $action; |
|
942 | + if (in_array($action, $possibleActions)) { |
|
943 | + $temp[(int) $topic] = $action; |
|
944 | + } |
|
894 | 945 | } |
895 | 946 | $_REQUEST['actions'] = $temp; |
896 | 947 | |
@@ -911,27 +962,31 @@ discard block |
||
911 | 962 | { |
912 | 963 | if (!empty($board)) |
913 | 964 | { |
914 | - if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) |
|
915 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
916 | - } |
|
917 | - else |
|
965 | + if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) { |
|
966 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
967 | + } |
|
968 | + } else |
|
918 | 969 | { |
919 | 970 | // Don't allow them to act on unapproved posts they can't see... |
920 | - if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) |
|
921 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
971 | + if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) { |
|
972 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
973 | + } |
|
922 | 974 | // Goodness, this is fun. We need to validate the action. |
923 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) |
|
924 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
925 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) |
|
926 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
927 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) |
|
928 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
975 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) { |
|
976 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
977 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) { |
|
978 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
979 | + } elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) { |
|
980 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
981 | + } |
|
929 | 982 | // @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked']) |
930 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) |
|
931 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
983 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) { |
|
984 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
985 | + } |
|
932 | 986 | // If the topic is approved then you need permission to approve the posts within. |
933 | - elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) |
|
934 | - unset($_REQUEST['actions'][$row['id_topic']]); |
|
987 | + elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) { |
|
988 | + unset($_REQUEST['actions'][$row['id_topic']]); |
|
989 | + } |
|
935 | 990 | } |
936 | 991 | } |
937 | 992 | $smcFunc['db_free_result']($request); |
@@ -949,11 +1004,11 @@ discard block |
||
949 | 1004 | { |
950 | 1005 | $topic = (int) $topic; |
951 | 1006 | |
952 | - if ($action == 'markread') |
|
953 | - $markCache[] = $topic; |
|
954 | - elseif ($action == 'sticky') |
|
955 | - $stickyCache[] = $topic; |
|
956 | - elseif ($action == 'move') |
|
1007 | + if ($action == 'markread') { |
|
1008 | + $markCache[] = $topic; |
|
1009 | + } elseif ($action == 'sticky') { |
|
1010 | + $stickyCache[] = $topic; |
|
1011 | + } elseif ($action == 'move') |
|
957 | 1012 | { |
958 | 1013 | require_once($sourcedir . '/MoveTopic.php'); |
959 | 1014 | moveTopicConcurrence(); |
@@ -961,23 +1016,25 @@ discard block |
||
961 | 1016 | // $moveCache[0] is the topic, $moveCache[1] is the board to move to. |
962 | 1017 | $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']); |
963 | 1018 | |
964 | - if (empty($moveCache[1][$topic])) |
|
965 | - continue; |
|
1019 | + if (empty($moveCache[1][$topic])) { |
|
1020 | + continue; |
|
1021 | + } |
|
966 | 1022 | |
967 | 1023 | $moveCache[0][] = $topic; |
1024 | + } elseif ($action == 'remove') { |
|
1025 | + $removeCache[] = $topic; |
|
1026 | + } elseif ($action == 'lock') { |
|
1027 | + $lockCache[] = $topic; |
|
1028 | + } elseif ($action == 'approve') { |
|
1029 | + $approveCache[] = $topic; |
|
968 | 1030 | } |
969 | - elseif ($action == 'remove') |
|
970 | - $removeCache[] = $topic; |
|
971 | - elseif ($action == 'lock') |
|
972 | - $lockCache[] = $topic; |
|
973 | - elseif ($action == 'approve') |
|
974 | - $approveCache[] = $topic; |
|
975 | 1031 | } |
976 | 1032 | |
977 | - if (empty($board)) |
|
978 | - $affectedBoards = array(); |
|
979 | - else |
|
980 | - $affectedBoards = array($board => array(0, 0)); |
|
1033 | + if (empty($board)) { |
|
1034 | + $affectedBoards = array(); |
|
1035 | + } else { |
|
1036 | + $affectedBoards = array($board => array(0, 0)); |
|
1037 | + } |
|
981 | 1038 | |
982 | 1039 | // Do all the stickies... |
983 | 1040 | if (!empty($stickyCache)) |
@@ -1037,14 +1094,16 @@ discard block |
||
1037 | 1094 | { |
1038 | 1095 | $to = $moveCache[1][$row['id_topic']]; |
1039 | 1096 | |
1040 | - if (empty($to)) |
|
1041 | - continue; |
|
1097 | + if (empty($to)) { |
|
1098 | + continue; |
|
1099 | + } |
|
1042 | 1100 | |
1043 | 1101 | // Does this topic's board count the posts or not? |
1044 | 1102 | $countPosts[$row['id_topic']] = empty($row['count_posts']); |
1045 | 1103 | |
1046 | - if (!isset($moveTos[$to])) |
|
1047 | - $moveTos[$to] = array(); |
|
1104 | + if (!isset($moveTos[$to])) { |
|
1105 | + $moveTos[$to] = array(); |
|
1106 | + } |
|
1048 | 1107 | |
1049 | 1108 | $moveTos[$to][] = $row['id_topic']; |
1050 | 1109 | |
@@ -1058,8 +1117,9 @@ discard block |
||
1058 | 1117 | require_once($sourcedir . '/MoveTopic.php'); |
1059 | 1118 | |
1060 | 1119 | // Do the actual moves... |
1061 | - foreach ($moveTos as $to => $topics) |
|
1062 | - moveTopics($topics, $to); |
|
1120 | + foreach ($moveTos as $to => $topics) { |
|
1121 | + moveTopics($topics, $to); |
|
1122 | + } |
|
1063 | 1123 | |
1064 | 1124 | // Does the post counts need to be updated? |
1065 | 1125 | if (!empty($moveTos)) |
@@ -1108,20 +1168,23 @@ discard block |
||
1108 | 1168 | |
1109 | 1169 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1110 | 1170 | { |
1111 | - if (!isset($members[$row['id_member']])) |
|
1112 | - $members[$row['id_member']] = 0; |
|
1171 | + if (!isset($members[$row['id_member']])) { |
|
1172 | + $members[$row['id_member']] = 0; |
|
1173 | + } |
|
1113 | 1174 | |
1114 | - if ($topicRecounts[$row['id_topic']] === '+') |
|
1115 | - $members[$row['id_member']] += 1; |
|
1116 | - else |
|
1117 | - $members[$row['id_member']] -= 1; |
|
1175 | + if ($topicRecounts[$row['id_topic']] === '+') { |
|
1176 | + $members[$row['id_member']] += 1; |
|
1177 | + } else { |
|
1178 | + $members[$row['id_member']] -= 1; |
|
1179 | + } |
|
1118 | 1180 | } |
1119 | 1181 | |
1120 | 1182 | $smcFunc['db_free_result']($request); |
1121 | 1183 | |
1122 | 1184 | // And now update them member's post counts |
1123 | - foreach ($members as $id_member => $post_adj) |
|
1124 | - updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
1185 | + foreach ($members as $id_member => $post_adj) { |
|
1186 | + updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
|
1187 | + } |
|
1125 | 1188 | |
1126 | 1189 | } |
1127 | 1190 | } |
@@ -1201,8 +1264,9 @@ discard block |
||
1201 | 1264 | approveTopics($approveCache); |
1202 | 1265 | |
1203 | 1266 | // Time for some logging! |
1204 | - foreach ($approveCache as $topic) |
|
1205 | - logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
1267 | + foreach ($approveCache as $topic) { |
|
1268 | + logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
|
1269 | + } |
|
1206 | 1270 | } |
1207 | 1271 | } |
1208 | 1272 | |
@@ -1237,8 +1301,7 @@ discard block |
||
1237 | 1301 | $lockStatus[$row['id_topic']] = empty($row['locked']); |
1238 | 1302 | } |
1239 | 1303 | $smcFunc['db_free_result']($result); |
1240 | - } |
|
1241 | - else |
|
1304 | + } else |
|
1242 | 1305 | { |
1243 | 1306 | $result = $smcFunc['db_query']('', ' |
1244 | 1307 | SELECT id_topic, locked, id_board |
@@ -1288,13 +1351,15 @@ discard block |
||
1288 | 1351 | ) |
1289 | 1352 | ); |
1290 | 1353 | $logged_topics = array(); |
1291 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1292 | - $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
1354 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1355 | + $logged_topics[$row['id_topic']] = $row['unwatched']; |
|
1356 | + } |
|
1293 | 1357 | $smcFunc['db_free_result']($request); |
1294 | 1358 | |
1295 | 1359 | $markArray = array(); |
1296 | - foreach ($markCache as $topic) |
|
1297 | - $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
1360 | + foreach ($markCache as $topic) { |
|
1361 | + $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
|
1362 | + } |
|
1298 | 1363 | |
1299 | 1364 | $smcFunc['db_insert']('replace', |
1300 | 1365 | '{db_prefix}log_topics', |
@@ -1307,8 +1372,9 @@ discard block |
||
1307 | 1372 | foreach ($moveCache as $topic) |
1308 | 1373 | { |
1309 | 1374 | // Didn't actually move anything! |
1310 | - if (!isset($topic[0])) |
|
1311 | - break; |
|
1375 | + if (!isset($topic[0])) { |
|
1376 | + break; |
|
1377 | + } |
|
1312 | 1378 | |
1313 | 1379 | logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2])); |
1314 | 1380 | sendNotifications($topic[0], 'move'); |
@@ -1330,8 +1396,9 @@ discard block |
||
1330 | 1396 | 'calendar_updated' => time(), |
1331 | 1397 | )); |
1332 | 1398 | |
1333 | - if (!empty($affectedBoards)) |
|
1334 | - updateLastMessages(array_keys($affectedBoards)); |
|
1399 | + if (!empty($affectedBoards)) { |
|
1400 | + updateLastMessages(array_keys($affectedBoards)); |
|
1401 | + } |
|
1335 | 1402 | |
1336 | 1403 | redirectexit($redirect_url); |
1337 | 1404 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Main dispatcher. This function checks permissions and passes control through to the relevant section. |
@@ -245,8 +246,9 @@ discard block |
||
245 | 246 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
246 | 247 | { |
247 | 248 | // Private PM/email subjects and similar shouldn't be shown in the mailbox area. |
248 | - if (!empty($row['private'])) |
|
249 | - $row['subject'] = $txt['personal_message']; |
|
249 | + if (!empty($row['private'])) { |
|
250 | + $row['subject'] = $txt['personal_message']; |
|
251 | + } |
|
250 | 252 | |
251 | 253 | $mails[] = $row; |
252 | 254 | } |
@@ -300,8 +302,9 @@ discard block |
||
300 | 302 | $element = substr($key, strrpos($key, '_') + 1); |
301 | 303 | $processedBirthdayEmails[$index][$element] = $value; |
302 | 304 | } |
303 | - foreach ($processedBirthdayEmails as $index => $dummy) |
|
304 | - $emails[$index] = $index; |
|
305 | + foreach ($processedBirthdayEmails as $index => $dummy) { |
|
306 | + $emails[$index] = $index; |
|
307 | + } |
|
305 | 308 | |
306 | 309 | $config_vars = array( |
307 | 310 | // Mail queue stuff, this rocks ;) |
@@ -322,8 +325,9 @@ discard block |
||
322 | 325 | |
323 | 326 | call_integration_hook('integrate_modify_mail_settings', array(&$config_vars)); |
324 | 327 | |
325 | - if ($return_config) |
|
326 | - return $config_vars; |
|
328 | + if ($return_config) { |
|
329 | + return $config_vars; |
|
330 | + } |
|
327 | 331 | |
328 | 332 | // Saving? |
329 | 333 | if (isset($_GET['save'])) |
@@ -398,9 +402,9 @@ discard block |
||
398 | 402 | ); |
399 | 403 | list ($_GET['te']) = $smcFunc['db_fetch_row']($request); |
400 | 404 | $smcFunc['db_free_result']($request); |
405 | + } else { |
|
406 | + $_GET['te'] = (int) $_GET['te']; |
|
401 | 407 | } |
402 | - else |
|
403 | - $_GET['te'] = (int) $_GET['te']; |
|
404 | 408 | |
405 | 409 | $_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0; |
406 | 410 | |
@@ -424,12 +428,14 @@ discard block |
||
424 | 428 | |
425 | 429 | // Try get more time... |
426 | 430 | @set_time_limit(600); |
427 | - if (function_exists('apache_reset_timeout')) |
|
428 | - @apache_reset_timeout(); |
|
431 | + if (function_exists('apache_reset_timeout')) { |
|
432 | + @apache_reset_timeout(); |
|
433 | + } |
|
429 | 434 | |
430 | 435 | // Have we already used our maximum time? |
431 | - if ((time() - $time_start) < 5) |
|
432 | - return; |
|
436 | + if ((time() - $time_start) < 5) { |
|
437 | + return; |
|
438 | + } |
|
433 | 439 | |
434 | 440 | $context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
435 | 441 | $context['page_title'] = $txt['not_done_title']; |
@@ -459,8 +465,9 @@ discard block |
||
459 | 465 | { |
460 | 466 | global $txt; |
461 | 467 | |
462 | - if ($time_diff < 0) |
|
463 | - $time_diff = 0; |
|
468 | + if ($time_diff < 0) { |
|
469 | + $time_diff = 0; |
|
470 | + } |
|
464 | 471 | |
465 | 472 | // Just do a bit of an if fest... |
466 | 473 | if ($time_diff > 86400) |
@@ -481,8 +488,9 @@ discard block |
||
481 | 488 | return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes); |
482 | 489 | } |
483 | 490 | // Otherwise must be second |
484 | - else |
|
485 | - return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff); |
|
486 | -} |
|
491 | + else { |
|
492 | + return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff); |
|
493 | + } |
|
494 | + } |
|
487 | 495 | |
488 | 496 | ?> |
489 | 497 | \ No newline at end of file |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * The main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
64 | 65 | |
65 | 66 | // Pick the correct sub-action. |
66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
68 | - else |
|
69 | - $context['sub_action'] = 'browse'; |
|
67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
69 | + } else { |
|
70 | + $context['sub_action'] = 'browse'; |
|
71 | + } |
|
70 | 72 | |
71 | 73 | // Default page title is good. |
72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
95 | 97 | |
96 | 98 | // If not set, show a default path for the base directory |
97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
100 | - |
|
101 | - else |
|
102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
102 | + } else { |
|
103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
105 | 107 | |
106 | - if (!empty($modSettings['automanage_attachments'])) |
|
107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
108 | - |
|
109 | - else |
|
110 | - $context['valid_basedirectory'] = true; |
|
108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
110 | + } else { |
|
111 | + $context['valid_basedirectory'] = true; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
185 | 187 | |
186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
187 | 189 | |
188 | - if ($return_config) |
|
189 | - return $config_vars; |
|
190 | + if ($return_config) { |
|
191 | + return $config_vars; |
|
192 | + } |
|
190 | 193 | |
191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
197 | 200 | { |
198 | 201 | checkSession(); |
199 | 202 | |
200 | - if (isset($_POST['attachmentUploadDir'])) |
|
201 | - unset($_POST['attachmentUploadDir']); |
|
203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
204 | + unset($_POST['attachmentUploadDir']); |
|
205 | + } |
|
202 | 206 | |
203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
204 | 208 | { |
205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
211 | + } |
|
207 | 212 | |
208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
209 | 214 | { |
210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
211 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
216 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
217 | + } |
|
218 | + } else { |
|
219 | + $modSettings['attachment_basedirectories'] = array(); |
|
212 | 220 | } |
213 | - else |
|
214 | - $modSettings['attachment_basedirectories'] = array(); |
|
215 | 221 | |
216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
219 | 225 | |
220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
221 | 227 | { |
222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
230 | + } |
|
224 | 231 | } |
225 | 232 | |
226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
336 | 343 | |
337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
338 | 345 | |
339 | - if ($return_config) |
|
340 | - return $config_vars; |
|
346 | + if ($return_config) { |
|
347 | + return $config_vars; |
|
348 | + } |
|
341 | 349 | |
342 | 350 | // We need this file for the settings template. |
343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
348 | 356 | checkSession(); |
349 | 357 | |
350 | 358 | // These settings cannot be left empty! |
351 | - if (empty($_POST['custom_avatar_dir'])) |
|
352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
361 | + } |
|
353 | 362 | |
354 | - if (empty($_POST['custom_avatar_url'])) |
|
355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
363 | + if (empty($_POST['custom_avatar_url'])) { |
|
364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
365 | + } |
|
356 | 366 | |
357 | - if (empty($_POST['avatar_directory'])) |
|
358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
367 | + if (empty($_POST['avatar_directory'])) { |
|
368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
369 | + } |
|
359 | 370 | |
360 | - if (empty($_POST['avatar_url'])) |
|
361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
371 | + if (empty($_POST['avatar_url'])) { |
|
372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
373 | + } |
|
362 | 374 | |
363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
407 | 419 | foreach ($titles as $browse_type => $details) |
408 | 420 | { |
409 | - if ($browse_type != 'attachments') |
|
410 | - $list_title .= ' | '; |
|
421 | + if ($browse_type != 'attachments') { |
|
422 | + $list_title .= ' | '; |
|
423 | + } |
|
411 | 424 | |
412 | - if ($context['browse_type'] == $browse_type) |
|
413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
425 | + if ($context['browse_type'] == $browse_type) { |
|
426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
427 | + } |
|
414 | 428 | |
415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
446 | 460 | $link = '<a href="'; |
447 | 461 | |
448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
449 | - if ($rowData['attachment_type'] == 1) |
|
450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
463 | + if ($rowData['attachment_type'] == 1) { |
|
464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
465 | + } |
|
451 | 466 | |
452 | 467 | // By default avatars are downloaded almost as attachments. |
453 | - elseif ($context['browse_type'] == 'avatars') |
|
454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
468 | + elseif ($context['browse_type'] == 'avatars') { |
|
469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
470 | + } |
|
455 | 471 | |
456 | 472 | // Normal attachments are always linked to a topic ID. |
457 | - else |
|
458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
473 | + else { |
|
474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
475 | + } |
|
459 | 476 | |
460 | 477 | $link .= '"'; |
461 | 478 | |
462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
482 | + } |
|
465 | 483 | |
466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
467 | 485 | |
468 | 486 | // Show the dimensions. |
469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
489 | + } |
|
471 | 490 | |
472 | 491 | return $link; |
473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
501 | 520 | { |
502 | 521 | // In case of an attachment, return the poster of the attachment. |
503 | - if (empty($rowData['id_member'])) |
|
504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
522 | + if (empty($rowData['id_member'])) { |
|
523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
524 | + } |
|
505 | 525 | |
506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
507 | - else |
|
508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
527 | + else { |
|
528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
529 | + } |
|
509 | 530 | }, |
510 | 531 | ), |
511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
525 | 546 | |
526 | 547 | // Add a link to the topic in case of an attachment. |
527 | - if ($context['browse_type'] !== 'avatars') |
|
528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
548 | + if ($context['browse_type'] !== 'avatars') { |
|
549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
550 | + } |
|
529 | 551 | |
530 | 552 | return $date; |
531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
610 | 632 | global $smcFunc, $txt; |
611 | 633 | |
612 | 634 | // Choose a query depending on what we are viewing. |
613 | - if ($browse_type === 'avatars') |
|
614 | - $request = $smcFunc['db_query']('', ' |
|
635 | + if ($browse_type === 'avatars') { |
|
636 | + $request = $smcFunc['db_query']('', ' |
|
615 | 637 | SELECT |
616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
630 | 652 | 'per_page' => $items_per_page, |
631 | 653 | ) |
632 | 654 | ); |
633 | - else |
|
634 | - $request = $smcFunc['db_query']('', ' |
|
655 | + } else { |
|
656 | + $request = $smcFunc['db_query']('', ' |
|
635 | 657 | SELECT |
636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
650 | 672 | 'per_page' => $items_per_page, |
651 | 673 | ) |
652 | 674 | ); |
675 | + } |
|
653 | 676 | $files = array(); |
654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
655 | - $files[] = $row; |
|
677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
678 | + $files[] = $row; |
|
679 | + } |
|
656 | 680 | $smcFunc['db_free_result']($request); |
657 | 681 | |
658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
670 | 694 | global $smcFunc; |
671 | 695 | |
672 | 696 | // Depending on the type of file, different queries are used. |
673 | - if ($browse_type === 'avatars') |
|
674 | - $request = $smcFunc['db_query']('', ' |
|
697 | + if ($browse_type === 'avatars') { |
|
698 | + $request = $smcFunc['db_query']('', ' |
|
675 | 699 | SELECT COUNT(*) |
676 | 700 | FROM {db_prefix}attachments |
677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
679 | 703 | 'guest_id_member' => 0, |
680 | 704 | ) |
681 | 705 | ); |
682 | - else |
|
683 | - $request = $smcFunc['db_query']('', ' |
|
706 | + } else { |
|
707 | + $request = $smcFunc['db_query']('', ' |
|
684 | 708 | SELECT COUNT(*) AS num_attach |
685 | 709 | FROM {db_prefix}attachments AS a |
686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
693 | 717 | 'guest_id_member' => 0, |
694 | 718 | ) |
695 | 719 | ); |
720 | + } |
|
696 | 721 | |
697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
775 | 800 | $current_dir_size /= 1024; |
776 | 801 | |
777 | 802 | // If they specified a limit only.... |
778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
805 | + } |
|
780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
781 | 807 | |
782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
810 | + } |
|
784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
785 | 812 | |
786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
818 | 845 | |
819 | 846 | // Update the messages to reflect the change. |
820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
821 | - $smcFunc['db_query']('', ' |
|
847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
848 | + $smcFunc['db_query']('', ' |
|
822 | 849 | UPDATE {db_prefix}messages |
823 | 850 | SET body = CONCAT(body, {string:notice}) |
824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
828 | 855 | ) |
829 | 856 | ); |
830 | - } |
|
831 | - else |
|
857 | + } |
|
858 | + } else |
|
832 | 859 | { |
833 | 860 | // Remove all the old avatars. |
834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
854 | 881 | |
855 | 882 | // And make a note on the post. |
856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
857 | - $smcFunc['db_query']('', ' |
|
883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
884 | + $smcFunc['db_query']('', ' |
|
858 | 885 | UPDATE {db_prefix}messages |
859 | 886 | SET body = CONCAT(body, {string:notice}) |
860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
864 | 891 | ) |
865 | 892 | ); |
893 | + } |
|
866 | 894 | |
867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
882 | 910 | { |
883 | 911 | $attachments = array(); |
884 | 912 | // There must be a quicker way to pass this safety test?? |
885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
886 | - $attachments[] = (int) $removeID; |
|
913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
914 | + $attachments[] = (int) $removeID; |
|
915 | + } |
|
887 | 916 | |
888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
889 | 918 | $filesRemoved = false; |
890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
891 | 920 | |
892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
893 | - removeAttachments(array('id_attach' => $attachments)); |
|
894 | - else if (!empty($attachments)) |
|
921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
922 | + removeAttachments(array('id_attach' => $attachments)); |
|
923 | + } else if (!empty($attachments)) |
|
895 | 924 | { |
896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
930 | 959 | |
931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
932 | 961 | |
933 | - if (!isset($_POST['notice'])) |
|
934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
962 | + if (!isset($_POST['notice'])) { |
|
963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
964 | + } |
|
935 | 965 | |
936 | 966 | // Add the notice on the end of the changed messages. |
937 | - if (!empty($messages)) |
|
938 | - $smcFunc['db_query']('', ' |
|
967 | + if (!empty($messages)) { |
|
968 | + $smcFunc['db_query']('', ' |
|
939 | 969 | UPDATE {db_prefix}messages |
940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
945 | 975 | ) |
946 | 976 | ); |
977 | + } |
|
947 | 978 | |
948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
984 | 1015 | |
985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
987 | - elseif ($type == 'attachment_type') |
|
988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
989 | - elseif ($type == 'poster_time') |
|
990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
991 | - elseif ($type == 'last_login') |
|
992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
993 | - elseif ($type == 'size') |
|
994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
995 | - elseif ($type == 'id_topic') |
|
996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1018 | + } elseif ($type == 'attachment_type') { |
|
1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
1020 | + } elseif ($type == 'poster_time') { |
|
1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
1022 | + } elseif ($type == 'last_login') { |
|
1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
1024 | + } elseif ($type == 'size') { |
|
1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
1026 | + } elseif ($type == 'id_topic') { |
|
1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
1028 | + } |
|
997 | 1029 | |
998 | 1030 | // Add the parameter! |
999 | 1031 | $query_parameter[$real_type] = $restriction; |
1000 | 1032 | |
1001 | - if ($type == 'do_logging') |
|
1002 | - $do_logging = $condition['id_attach']; |
|
1033 | + if ($type == 'do_logging') { |
|
1034 | + $do_logging = $condition['id_attach']; |
|
1035 | + } |
|
1003 | 1036 | } |
1004 | 1037 | $condition = implode(' AND ', $new_condition); |
1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
1031 | 1064 | // wasn't it obvious? :P |
1032 | 1065 | // @todo look again at this. |
1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
1034 | - } |
|
1035 | - else |
|
1067 | + } else |
|
1036 | 1068 | { |
1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
1038 | 1070 | @unlink($filename); |
1039 | 1071 | |
1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
1041 | - if (!empty($row['id_parent'])) |
|
1042 | - $parents[] = $row['id_parent']; |
|
1073 | + if (!empty($row['id_parent'])) { |
|
1074 | + $parents[] = $row['id_parent']; |
|
1075 | + } |
|
1043 | 1076 | |
1044 | 1077 | // If this attachments has a thumb, remove it as well. |
1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
1051 | 1084 | } |
1052 | 1085 | |
1053 | 1086 | // Make a list. |
1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
1055 | - $msgs[] = $row['id_msg']; |
|
1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
1088 | + $msgs[] = $row['id_msg']; |
|
1089 | + } |
|
1056 | 1090 | |
1057 | 1091 | $attach[] = $row['id_attach']; |
1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
1060 | 1094 | |
1061 | 1095 | // Removed attachments don't have to be updated anymore. |
1062 | 1096 | $parents = array_diff($parents, $attach); |
1063 | - if (!empty($parents)) |
|
1064 | - $smcFunc['db_query']('', ' |
|
1097 | + if (!empty($parents)) { |
|
1098 | + $smcFunc['db_query']('', ' |
|
1065 | 1099 | UPDATE {db_prefix}attachments |
1066 | 1100 | SET id_thumb = {int:no_thumb} |
1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
1070 | 1104 | 'no_thumb' => 0, |
1071 | 1105 | ) |
1072 | 1106 | ); |
1107 | + } |
|
1073 | 1108 | |
1074 | 1109 | if (!empty($do_logging)) |
1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
1086 | 1121 | ) |
1087 | 1122 | ); |
1088 | 1123 | |
1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1090 | - logAction( |
|
1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1125 | + logAction( |
|
1091 | 1126 | 'remove_attach', |
1092 | 1127 | array( |
1093 | 1128 | 'message' => $row['id_msg'], |
1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1095 | 1130 | ) |
1096 | 1131 | ); |
1132 | + } |
|
1097 | 1133 | $smcFunc['db_free_result']($request); |
1098 | 1134 | } |
1099 | 1135 | |
1100 | - if (!empty($attach)) |
|
1101 | - $smcFunc['db_query']('', ' |
|
1136 | + if (!empty($attach)) { |
|
1137 | + $smcFunc['db_query']('', ' |
|
1102 | 1138 | DELETE FROM {db_prefix}attachments |
1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
1104 | 1140 | array( |
1105 | 1141 | 'attachment_list' => $attach, |
1106 | 1142 | ) |
1107 | 1143 | ); |
1144 | + } |
|
1108 | 1145 | |
1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
1110 | 1147 | |
1111 | - if ($return_affected_messages) |
|
1112 | - return array_unique($msgs); |
|
1113 | -} |
|
1148 | + if ($return_affected_messages) { |
|
1149 | + return array_unique($msgs); |
|
1150 | + } |
|
1151 | + } |
|
1114 | 1152 | |
1115 | 1153 | /** |
1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
1122 | 1160 | checkSession('get'); |
1123 | 1161 | |
1124 | 1162 | // If we choose cancel, redirect right back. |
1125 | - if (isset($_POST['cancel'])) |
|
1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1163 | + if (isset($_POST['cancel'])) { |
|
1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1165 | + } |
|
1127 | 1166 | |
1128 | 1167 | // Try give us a while to sort this out... |
1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
1140 | 1179 | if (isset($_GET['fixErrors'])) |
1141 | 1180 | { |
1142 | 1181 | // Nothing? |
1143 | - if (empty($_POST['to_fix'])) |
|
1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1182 | + if (empty($_POST['to_fix'])) { |
|
1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
1184 | + } |
|
1145 | 1185 | |
1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
1147 | 1187 | // @todo No need to do this I think. |
1148 | - foreach ($_POST['to_fix'] as $value) |
|
1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
1188 | + foreach ($_POST['to_fix'] as $value) { |
|
1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
1190 | + } |
|
1150 | 1191 | } |
1151 | 1192 | } |
1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
1213 | 1254 | } |
1214 | 1255 | } |
1215 | 1256 | } |
1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
1259 | + } |
|
1218 | 1260 | $smcFunc['db_free_result']($result); |
1219 | 1261 | |
1220 | 1262 | // Do we need to delete what we have? |
1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
1222 | - $smcFunc['db_query']('', ' |
|
1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
1264 | + $smcFunc['db_query']('', ' |
|
1223 | 1265 | DELETE FROM {db_prefix}attachments |
1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
1228 | 1270 | 'attachment_type' => 3, |
1229 | 1271 | ) |
1230 | 1272 | ); |
1273 | + } |
|
1231 | 1274 | |
1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
1272 | 1315 | $to_update[] = $row['id_attach']; |
1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
1274 | 1317 | } |
1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
1320 | + } |
|
1277 | 1321 | $smcFunc['db_free_result']($result); |
1278 | 1322 | |
1279 | 1323 | // Do we need to delete what we have? |
1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
1281 | - $smcFunc['db_query']('', ' |
|
1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
1325 | + $smcFunc['db_query']('', ' |
|
1282 | 1326 | UPDATE {db_prefix}attachments |
1283 | 1327 | SET id_thumb = {int:no_thumb} |
1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
1287 | 1331 | 'no_thumb' => 0, |
1288 | 1332 | ) |
1289 | 1333 | ); |
1334 | + } |
|
1290 | 1335 | |
1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1325 | 1370 | { |
1326 | 1371 | // Get the filename. |
1327 | - if ($row['attachment_type'] == 1) |
|
1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1329 | - else |
|
1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1372 | + if ($row['attachment_type'] == 1) { |
|
1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1374 | + } else { |
|
1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1376 | + } |
|
1331 | 1377 | |
1332 | 1378 | // File doesn't exist? |
1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
1340 | 1386 | |
1341 | 1387 | // Loop through the other folders. |
1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
1344 | 1390 | { |
1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
1392 | + } |
|
1346 | 1393 | $errors_found[] = 'wrong_folder'; |
1347 | 1394 | |
1348 | 1395 | // Are we going to fix this now? |
1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
1350 | - $smcFunc['db_query']('', ' |
|
1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
1397 | + $smcFunc['db_query']('', ' |
|
1351 | 1398 | UPDATE {db_prefix}attachments |
1352 | 1399 | SET id_folder = {int:new_folder} |
1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
1356 | 1403 | 'id_attach' => $row['id_attach'], |
1357 | 1404 | ) |
1358 | 1405 | ); |
1406 | + } |
|
1359 | 1407 | |
1360 | 1408 | continue 2; |
1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
1364 | 1412 | $to_remove[] = $row['id_attach']; |
1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
1367 | - } |
|
1368 | - elseif (filesize($filename) == 0) |
|
1415 | + } elseif (filesize($filename) == 0) |
|
1369 | 1416 | { |
1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
1376 | 1423 | $to_remove[] = $row['id_attach']; |
1377 | 1424 | @unlink($filename); |
1378 | 1425 | } |
1379 | - } |
|
1380 | - elseif (filesize($filename) != $row['size']) |
|
1426 | + } elseif (filesize($filename) != $row['size']) |
|
1381 | 1427 | { |
1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
1398 | 1444 | } |
1399 | 1445 | } |
1400 | 1446 | |
1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
1404 | - $to_fix[] = 'file_size_of_zero'; |
|
1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
1406 | - $to_fix[] = 'file_wrong_size'; |
|
1407 | - if (in_array('wrong_folder', $errors_found)) |
|
1408 | - $to_fix[] = 'wrong_folder'; |
|
1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
1449 | + } |
|
1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
1451 | + $to_fix[] = 'file_size_of_zero'; |
|
1452 | + } |
|
1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
1454 | + $to_fix[] = 'file_wrong_size'; |
|
1455 | + } |
|
1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
1457 | + $to_fix[] = 'wrong_folder'; |
|
1458 | + } |
|
1409 | 1459 | $smcFunc['db_free_result']($result); |
1410 | 1460 | |
1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
1475 | 1525 | // If we are repairing remove the file from disk now. |
1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
1477 | 1527 | { |
1478 | - if ($row['attachment_type'] == 1) |
|
1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1480 | - else |
|
1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1528 | + if ($row['attachment_type'] == 1) { |
|
1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
1530 | + } else { |
|
1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
1532 | + } |
|
1482 | 1533 | @unlink($filename); |
1483 | 1534 | } |
1484 | 1535 | } |
1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1486 | - $to_fix[] = 'avatar_no_member'; |
|
1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1537 | + $to_fix[] = 'avatar_no_member'; |
|
1538 | + } |
|
1487 | 1539 | $smcFunc['db_free_result']($result); |
1488 | 1540 | |
1489 | 1541 | // Do we need to delete what we have? |
1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
1491 | - $smcFunc['db_query']('', ' |
|
1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
1543 | + $smcFunc['db_query']('', ' |
|
1492 | 1544 | DELETE FROM {db_prefix}attachments |
1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
1499 | 1551 | 'no_msg' => 0, |
1500 | 1552 | ) |
1501 | 1553 | ); |
1554 | + } |
|
1502 | 1555 | |
1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1504 | 1557 | } |
@@ -1558,13 +1611,14 @@ discard block |
||
1558 | 1611 | @unlink($filename); |
1559 | 1612 | } |
1560 | 1613 | } |
1561 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1562 | - $to_fix[] = 'attachment_no_msg'; |
|
1614 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1615 | + $to_fix[] = 'attachment_no_msg'; |
|
1616 | + } |
|
1563 | 1617 | $smcFunc['db_free_result']($result); |
1564 | 1618 | |
1565 | 1619 | // Do we need to delete what we have? |
1566 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
1567 | - $smcFunc['db_query']('', ' |
|
1620 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
1621 | + $smcFunc['db_query']('', ' |
|
1568 | 1622 | DELETE FROM {db_prefix}attachments |
1569 | 1623 | WHERE id_attach IN ({array_int:to_remove}) |
1570 | 1624 | AND id_member = {int:no_member} |
@@ -1575,6 +1629,7 @@ discard block |
||
1575 | 1629 | 'attach_thumb' => array(0,3), |
1576 | 1630 | ) |
1577 | 1631 | ); |
1632 | + } |
|
1578 | 1633 | |
1579 | 1634 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
1580 | 1635 | } |
@@ -1598,8 +1653,9 @@ discard block |
||
1598 | 1653 | { |
1599 | 1654 | while ($file = readdir($dir)) |
1600 | 1655 | { |
1601 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
1602 | - continue; |
|
1656 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
1657 | + continue; |
|
1658 | + } |
|
1603 | 1659 | |
1604 | 1660 | if ($files_checked <= $current_check) |
1605 | 1661 | { |
@@ -1607,8 +1663,9 @@ discard block |
||
1607 | 1663 | if (strpos($file, 'post_tmp_') !== false) |
1608 | 1664 | { |
1609 | 1665 | // Temp file is more than 5 hours old! |
1610 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
1611 | - @unlink($attach_dir . '/' . $file); |
|
1666 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
1667 | + @unlink($attach_dir . '/' . $file); |
|
1668 | + } |
|
1612 | 1669 | } |
1613 | 1670 | // That should be an attachment, let's check if we have it in the database |
1614 | 1671 | elseif (strpos($file, '_') !== false) |
@@ -1630,8 +1687,7 @@ discard block |
||
1630 | 1687 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1631 | 1688 | { |
1632 | 1689 | @unlink($attach_dir . '/' . $file); |
1633 | - } |
|
1634 | - else |
|
1690 | + } else |
|
1635 | 1691 | { |
1636 | 1692 | $context['repair_errors']['files_without_attachment']++; |
1637 | 1693 | $to_fix[] = 'files_without_attachment'; |
@@ -1639,14 +1695,12 @@ discard block |
||
1639 | 1695 | } |
1640 | 1696 | $smcFunc['db_free_result']($request); |
1641 | 1697 | } |
1642 | - } |
|
1643 | - else |
|
1698 | + } else |
|
1644 | 1699 | { |
1645 | 1700 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
1646 | 1701 | { |
1647 | 1702 | @unlink($attach_dir . '/' . $file); |
1648 | - } |
|
1649 | - else |
|
1703 | + } else |
|
1650 | 1704 | { |
1651 | 1705 | $context['repair_errors']['files_without_attachment']++; |
1652 | 1706 | $to_fix[] = 'files_without_attachment'; |
@@ -1655,8 +1709,9 @@ discard block |
||
1655 | 1709 | } |
1656 | 1710 | $current_check++; |
1657 | 1711 | $_GET['substep'] = $current_check; |
1658 | - if ($current_check - $files_checked >= $max_checks) |
|
1659 | - pauseAttachmentMaintenance($to_fix); |
|
1712 | + if ($current_check - $files_checked >= $max_checks) { |
|
1713 | + pauseAttachmentMaintenance($to_fix); |
|
1714 | + } |
|
1660 | 1715 | } |
1661 | 1716 | closedir($dir); |
1662 | 1717 | } |
@@ -1692,12 +1747,14 @@ discard block |
||
1692 | 1747 | |
1693 | 1748 | // Try get more time... |
1694 | 1749 | @set_time_limit(600); |
1695 | - if (function_exists('apache_reset_timeout')) |
|
1696 | - @apache_reset_timeout(); |
|
1750 | + if (function_exists('apache_reset_timeout')) { |
|
1751 | + @apache_reset_timeout(); |
|
1752 | + } |
|
1697 | 1753 | |
1698 | 1754 | // Have we already used our maximum time? |
1699 | - if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
1700 | - return; |
|
1755 | + if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
1756 | + return; |
|
1757 | + } |
|
1701 | 1758 | |
1702 | 1759 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
1703 | 1760 | $context['page_title'] = $txt['not_done_title']; |
@@ -1709,10 +1766,11 @@ discard block |
||
1709 | 1766 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
1710 | 1767 | |
1711 | 1768 | // Change these two if more steps are added! |
1712 | - if (empty($max_substep)) |
|
1713 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1714 | - else |
|
1715 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1769 | + if (empty($max_substep)) { |
|
1770 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
1771 | + } else { |
|
1772 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
1773 | + } |
|
1716 | 1774 | |
1717 | 1775 | // Never more than 100%! |
1718 | 1776 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1754,15 +1812,17 @@ discard block |
||
1754 | 1812 | 'attachment_type' => 0, |
1755 | 1813 | ) |
1756 | 1814 | ); |
1757 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1758 | - $attachments[] = $row['id_attach']; |
|
1815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1816 | + $attachments[] = $row['id_attach']; |
|
1817 | + } |
|
1759 | 1818 | $smcFunc['db_free_result']($request); |
1819 | + } elseif (!empty($_GET['aid'])) { |
|
1820 | + $attachments[] = (int) $_GET['aid']; |
|
1760 | 1821 | } |
1761 | - elseif (!empty($_GET['aid'])) |
|
1762 | - $attachments[] = (int) $_GET['aid']; |
|
1763 | 1822 | |
1764 | - if (empty($attachments)) |
|
1765 | - fatal_lang_error('no_access', false); |
|
1823 | + if (empty($attachments)) { |
|
1824 | + fatal_lang_error('no_access', false); |
|
1825 | + } |
|
1766 | 1826 | |
1767 | 1827 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
1768 | 1828 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1795,17 +1855,18 @@ discard block |
||
1795 | 1855 | } |
1796 | 1856 | $smcFunc['db_free_result']($request); |
1797 | 1857 | |
1798 | - if (empty($attachments)) |
|
1799 | - fatal_lang_error('no_access', false); |
|
1858 | + if (empty($attachments)) { |
|
1859 | + fatal_lang_error('no_access', false); |
|
1860 | + } |
|
1800 | 1861 | |
1801 | 1862 | // Finally, we are there. Follow through! |
1802 | 1863 | if ($is_approve) |
1803 | 1864 | { |
1804 | 1865 | // Checked and deemed worthy. |
1805 | 1866 | ApproveAttachments($attachments); |
1867 | + } else { |
|
1868 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1806 | 1869 | } |
1807 | - else |
|
1808 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
1809 | 1870 | |
1810 | 1871 | // Return to the topic.... |
1811 | 1872 | redirectexit($redirect); |
@@ -1821,8 +1882,9 @@ discard block |
||
1821 | 1882 | { |
1822 | 1883 | global $smcFunc; |
1823 | 1884 | |
1824 | - if (empty($attachments)) |
|
1825 | - return 0; |
|
1885 | + if (empty($attachments)) { |
|
1886 | + return 0; |
|
1887 | + } |
|
1826 | 1888 | |
1827 | 1889 | // For safety, check for thumbnails... |
1828 | 1890 | $request = $smcFunc['db_query']('', ' |
@@ -1841,15 +1903,17 @@ discard block |
||
1841 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1842 | 1904 | { |
1843 | 1905 | // Update the thumbnail too... |
1844 | - if (!empty($row['id_thumb'])) |
|
1845 | - $attachments[] = $row['id_thumb']; |
|
1906 | + if (!empty($row['id_thumb'])) { |
|
1907 | + $attachments[] = $row['id_thumb']; |
|
1908 | + } |
|
1846 | 1909 | |
1847 | 1910 | $attachments[] = $row['id_attach']; |
1848 | 1911 | } |
1849 | 1912 | $smcFunc['db_free_result']($request); |
1850 | 1913 | |
1851 | - if (empty($attachments)) |
|
1852 | - return 0; |
|
1914 | + if (empty($attachments)) { |
|
1915 | + return 0; |
|
1916 | + } |
|
1853 | 1917 | |
1854 | 1918 | // Approving an attachment is not hard - it's easy. |
1855 | 1919 | $smcFunc['db_query']('', ' |
@@ -1875,14 +1939,15 @@ discard block |
||
1875 | 1939 | ) |
1876 | 1940 | ); |
1877 | 1941 | |
1878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1879 | - logAction( |
|
1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1943 | + logAction( |
|
1880 | 1944 | 'approve_attach', |
1881 | 1945 | array( |
1882 | 1946 | 'message' => $row['id_msg'], |
1883 | 1947 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
1884 | 1948 | ) |
1885 | 1949 | ); |
1950 | + } |
|
1886 | 1951 | $smcFunc['db_free_result']($request); |
1887 | 1952 | |
1888 | 1953 | // Remove from the approval queue. |
@@ -1905,11 +1970,11 @@ discard block |
||
1905 | 1970 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
1906 | 1971 | |
1907 | 1972 | // Since this needs to be done eventually. |
1908 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
1909 | - $modSettings['attachment_basedirectories'] = array(); |
|
1910 | - |
|
1911 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
1912 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
1973 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
1974 | + $modSettings['attachment_basedirectories'] = array(); |
|
1975 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
1976 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
1977 | + } |
|
1913 | 1978 | |
1914 | 1979 | $errors = array(); |
1915 | 1980 | |
@@ -1924,8 +1989,9 @@ discard block |
||
1924 | 1989 | { |
1925 | 1990 | $error = ''; |
1926 | 1991 | $id = (int) $id; |
1927 | - if ($id < 1) |
|
1928 | - continue; |
|
1992 | + if ($id < 1) { |
|
1993 | + continue; |
|
1994 | + } |
|
1929 | 1995 | |
1930 | 1996 | // Sorry, these dirs are NOT valid |
1931 | 1997 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1944,8 +2010,7 @@ discard block |
||
1944 | 2010 | { |
1945 | 2011 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
1946 | 2012 | continue; |
1947 | - } |
|
1948 | - elseif (empty($path)) |
|
2013 | + } elseif (empty($path)) |
|
1949 | 2014 | { |
1950 | 2015 | // Ignore this and set $id to one less |
1951 | 2016 | continue; |
@@ -1953,10 +2018,11 @@ discard block |
||
1953 | 2018 | |
1954 | 2019 | // OK, so let's try to create it then. |
1955 | 2020 | require_once($sourcedir . '/Subs-Attachments.php'); |
1956 | - if (automanage_attachments_create_directory($path)) |
|
1957 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
1958 | - else |
|
1959 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2021 | + if (automanage_attachments_create_directory($path)) { |
|
2022 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2023 | + } else { |
|
2024 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
2025 | + } |
|
1960 | 2026 | } |
1961 | 2027 | |
1962 | 2028 | // Changing a directory name? |
@@ -1969,8 +2035,7 @@ discard block |
||
1969 | 2035 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
1970 | 2036 | $path = $modSettings['attachmentUploadDir'][$id]; |
1971 | 2037 | } |
1972 | - } |
|
1973 | - else |
|
2038 | + } else |
|
1974 | 2039 | { |
1975 | 2040 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
1976 | 2041 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1995,12 +2060,13 @@ discard block |
||
1995 | 2060 | $path = $modSettings['attachmentUploadDir'][$id]; |
1996 | 2061 | |
1997 | 2062 | // It's not a good idea to delete the current directory. |
1998 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
1999 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2063 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
2065 | + } |
|
2000 | 2066 | // Or the current base directory |
2001 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
2002 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
2003 | - else |
|
2067 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
2068 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
2069 | + } else |
|
2004 | 2070 | { |
2005 | 2071 | // Let's not try to delete a path with files in it. |
2006 | 2072 | $request = $smcFunc['db_query']('', ' |
@@ -2019,17 +2085,18 @@ discard block |
||
2019 | 2085 | if (!empty($modSettings['attachment_basedirectories'])) |
2020 | 2086 | { |
2021 | 2087 | // Count any sub-folders. |
2022 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
2023 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2088 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
2089 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
2024 | 2090 | $num_attach++; |
2091 | + } |
|
2025 | 2092 | } |
2026 | 2093 | |
2027 | 2094 | // It's safe to delete. So try to delete the folder also |
2028 | 2095 | if ($num_attach == 0) |
2029 | 2096 | { |
2030 | - if (is_dir($path)) |
|
2031 | - $doit = true; |
|
2032 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2097 | + if (is_dir($path)) { |
|
2098 | + $doit = true; |
|
2099 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
2033 | 2100 | { |
2034 | 2101 | $doit = true; |
2035 | 2102 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2039,8 +2106,9 @@ discard block |
||
2039 | 2106 | { |
2040 | 2107 | unlink($path . '/.htaccess'); |
2041 | 2108 | unlink($path . '/index.php'); |
2042 | - if (!@rmdir($path)) |
|
2043 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2109 | + if (!@rmdir($path)) { |
|
2110 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
2111 | + } |
|
2044 | 2112 | } |
2045 | 2113 | |
2046 | 2114 | // Remove it from the base directory list. |
@@ -2050,14 +2118,15 @@ discard block |
||
2050 | 2118 | updateSettings(array('attachment_basedirectories' => $smcFunc['json_encode']($modSettings['attachment_basedirectories']))); |
2051 | 2119 | $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
2052 | 2120 | } |
2121 | + } else { |
|
2122 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2053 | 2123 | } |
2054 | - else |
|
2055 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
2056 | 2124 | |
2057 | - if (empty($error)) |
|
2058 | - continue; |
|
2059 | - else |
|
2060 | - $errors[] = $error; |
|
2125 | + if (empty($error)) { |
|
2126 | + continue; |
|
2127 | + } else { |
|
2128 | + $errors[] = $error; |
|
2129 | + } |
|
2061 | 2130 | } |
2062 | 2131 | } |
2063 | 2132 | |
@@ -2065,23 +2134,26 @@ discard block |
||
2065 | 2134 | } |
2066 | 2135 | |
2067 | 2136 | // We need to make sure the current directory is right. |
2068 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
2069 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2137 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
2138 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2139 | + } |
|
2070 | 2140 | |
2071 | 2141 | // Find the current directory if there's no value carried, |
2072 | 2142 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
2073 | 2143 | { |
2074 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
2075 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2076 | - else |
|
2077 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2144 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
2145 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
2146 | + } else { |
|
2147 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
2148 | + } |
|
2078 | 2149 | } |
2079 | 2150 | |
2080 | 2151 | // If the user wishes to go back, update the last_dir array |
2081 | 2152 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
2082 | 2153 | { |
2083 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
2084 | - $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
2154 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
2155 | + $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
2156 | + } |
|
2085 | 2157 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
2086 | 2158 | |
2087 | 2159 | if (is_numeric($num)) |
@@ -2089,16 +2161,18 @@ discard block |
||
2089 | 2161 | // Need to find the base folder. |
2090 | 2162 | $bid = -1; |
2091 | 2163 | $use_subdirectories_for_attachments = 0; |
2092 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2093 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2164 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2165 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
2094 | 2166 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
2095 | 2167 | { |
2096 | 2168 | $use_subdirectories_for_attachments = 1; |
2169 | + } |
|
2097 | 2170 | break; |
2098 | 2171 | } |
2099 | 2172 | |
2100 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
2101 | - $bid = 0; |
|
2173 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
2174 | + $bid = 0; |
|
2175 | + } |
|
2102 | 2176 | |
2103 | 2177 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
2104 | 2178 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2117,8 +2191,8 @@ discard block |
||
2117 | 2191 | // We might need to reset the paths. This loop will just loop through once. |
2118 | 2192 | foreach ($new_dirs as $id => $dir) |
2119 | 2193 | { |
2120 | - if ($id != 1) |
|
2121 | - $smcFunc['db_query']('', ' |
|
2194 | + if ($id != 1) { |
|
2195 | + $smcFunc['db_query']('', ' |
|
2122 | 2196 | UPDATE {db_prefix}attachments |
2123 | 2197 | SET id_folder = {int:default_folder} |
2124 | 2198 | WHERE id_folder = {int:current_folder}', |
@@ -2127,14 +2201,14 @@ discard block |
||
2127 | 2201 | 'current_folder' => $id, |
2128 | 2202 | ) |
2129 | 2203 | ); |
2204 | + } |
|
2130 | 2205 | |
2131 | 2206 | $update = array( |
2132 | 2207 | 'currentAttachmentUploadDir' => 1, |
2133 | 2208 | 'attachmentUploadDir' => $smcFunc['json_encode'](array(1 => $dir)), |
2134 | 2209 | ); |
2135 | 2210 | } |
2136 | - } |
|
2137 | - else |
|
2211 | + } else |
|
2138 | 2212 | { |
2139 | 2213 | // Save it to the database. |
2140 | 2214 | $update = array( |
@@ -2143,11 +2217,13 @@ discard block |
||
2143 | 2217 | ); |
2144 | 2218 | } |
2145 | 2219 | |
2146 | - if (!empty($update)) |
|
2147 | - updateSettings($update); |
|
2220 | + if (!empty($update)) { |
|
2221 | + updateSettings($update); |
|
2222 | + } |
|
2148 | 2223 | |
2149 | - if (!empty($errors)) |
|
2150 | - $_SESSION['errors']['dir'] = $errors; |
|
2224 | + if (!empty($errors)) { |
|
2225 | + $_SESSION['errors']['dir'] = $errors; |
|
2226 | + } |
|
2151 | 2227 | |
2152 | 2228 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2153 | 2229 | } |
@@ -2161,10 +2237,11 @@ discard block |
||
2161 | 2237 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
2162 | 2238 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
2163 | 2239 | { |
2164 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
2165 | - $update = (array( |
|
2240 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
2241 | + $update = (array( |
|
2166 | 2242 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
2167 | 2243 | )); |
2244 | + } |
|
2168 | 2245 | } |
2169 | 2246 | |
2170 | 2247 | if (isset($_POST['base_dir'])) |
@@ -2212,13 +2289,15 @@ discard block |
||
2212 | 2289 | |
2213 | 2290 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
2214 | 2291 | { |
2215 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
2216 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2292 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
2293 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
2294 | + } |
|
2217 | 2295 | } |
2218 | 2296 | |
2219 | 2297 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
2220 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
2221 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2298 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
2299 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
2300 | + } |
|
2222 | 2301 | ksort($modSettings['attachment_basedirectories']); |
2223 | 2302 | |
2224 | 2303 | $update = (array( |
@@ -2228,11 +2307,13 @@ discard block |
||
2228 | 2307 | )); |
2229 | 2308 | } |
2230 | 2309 | |
2231 | - if (!empty($errors)) |
|
2232 | - $_SESSION['errors']['base'] = $errors; |
|
2310 | + if (!empty($errors)) { |
|
2311 | + $_SESSION['errors']['base'] = $errors; |
|
2312 | + } |
|
2233 | 2313 | |
2234 | - if (!empty($update)) |
|
2235 | - updateSettings($update); |
|
2314 | + if (!empty($update)) { |
|
2315 | + updateSettings($update); |
|
2316 | + } |
|
2236 | 2317 | |
2237 | 2318 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
2238 | 2319 | } |
@@ -2242,13 +2323,15 @@ discard block |
||
2242 | 2323 | if (is_array($_SESSION['errors'])) |
2243 | 2324 | { |
2244 | 2325 | $errors = array(); |
2245 | - if (!empty($_SESSION['errors']['dir'])) |
|
2246 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
2326 | + if (!empty($_SESSION['errors']['dir'])) { |
|
2327 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
2247 | 2328 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2329 | + } |
|
2248 | 2330 | |
2249 | - if (!empty($_SESSION['errors']['base'])) |
|
2250 | - foreach ($_SESSION['errors']['base'] as $error) |
|
2331 | + if (!empty($_SESSION['errors']['base'])) { |
|
2332 | + foreach ($_SESSION['errors']['base'] as $error) |
|
2251 | 2333 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
2334 | + } |
|
2252 | 2335 | } |
2253 | 2336 | unset($_SESSION['errors']); |
2254 | 2337 | } |
@@ -2458,8 +2541,9 @@ discard block |
||
2458 | 2541 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
2459 | 2542 | { |
2460 | 2543 | // If there aren't any attachments in this directory this won't exist. |
2461 | - if (!isset($expected_files[$id])) |
|
2462 | - $expected_files[$id] = 0; |
|
2544 | + if (!isset($expected_files[$id])) { |
|
2545 | + $expected_files[$id] = 0; |
|
2546 | + } |
|
2463 | 2547 | |
2464 | 2548 | // Check if the directory is doing okay. |
2465 | 2549 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2472,10 +2556,11 @@ discard block |
||
2472 | 2556 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
2473 | 2557 | |
2474 | 2558 | // Count any sub-folders. |
2475 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2476 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2559 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2560 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2477 | 2561 | { |
2478 | 2562 | $expected_files[$id]++; |
2563 | + } |
|
2479 | 2564 | $sub_dirs++; |
2480 | 2565 | } |
2481 | 2566 | } |
@@ -2493,8 +2578,8 @@ discard block |
||
2493 | 2578 | } |
2494 | 2579 | |
2495 | 2580 | // Just stick a new directory on at the bottom. |
2496 | - if (isset($_REQUEST['new_path'])) |
|
2497 | - $attachdirs[] = array( |
|
2581 | + if (isset($_REQUEST['new_path'])) { |
|
2582 | + $attachdirs[] = array( |
|
2498 | 2583 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
2499 | 2584 | 'current' => false, |
2500 | 2585 | 'path' => '', |
@@ -2502,6 +2587,7 @@ discard block |
||
2502 | 2587 | 'num_files' => '', |
2503 | 2588 | 'status' => '', |
2504 | 2589 | ); |
2590 | + } |
|
2505 | 2591 | |
2506 | 2592 | return $attachdirs; |
2507 | 2593 | } |
@@ -2514,8 +2600,9 @@ discard block |
||
2514 | 2600 | { |
2515 | 2601 | global $modSettings, $txt; |
2516 | 2602 | |
2517 | - if (empty($modSettings['attachment_basedirectories'])) |
|
2518 | - return; |
|
2603 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
2604 | + return; |
|
2605 | + } |
|
2519 | 2606 | |
2520 | 2607 | $basedirs = array(); |
2521 | 2608 | // Get a list of the base directories. |
@@ -2523,16 +2610,18 @@ discard block |
||
2523 | 2610 | { |
2524 | 2611 | // Loop through the attach directory array to count any sub-directories |
2525 | 2612 | $expected_dirs = 0; |
2526 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
2527 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2613 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
2614 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
2528 | 2615 | $expected_dirs++; |
2616 | + } |
|
2529 | 2617 | |
2530 | - if (!is_dir($dir)) |
|
2531 | - $status = 'does_not_exist'; |
|
2532 | - elseif (!is_writeable($dir)) |
|
2533 | - $status = 'not_writable'; |
|
2534 | - else |
|
2535 | - $status = 'ok'; |
|
2618 | + if (!is_dir($dir)) { |
|
2619 | + $status = 'does_not_exist'; |
|
2620 | + } elseif (!is_writeable($dir)) { |
|
2621 | + $status = 'not_writable'; |
|
2622 | + } else { |
|
2623 | + $status = 'ok'; |
|
2624 | + } |
|
2536 | 2625 | |
2537 | 2626 | $basedirs[] = array( |
2538 | 2627 | 'id' => $id, |
@@ -2543,14 +2632,15 @@ discard block |
||
2543 | 2632 | ); |
2544 | 2633 | } |
2545 | 2634 | |
2546 | - if (isset($_REQUEST['new_base_path'])) |
|
2547 | - $basedirs[] = array( |
|
2635 | + if (isset($_REQUEST['new_base_path'])) { |
|
2636 | + $basedirs[] = array( |
|
2548 | 2637 | 'id' => '', |
2549 | 2638 | 'current' => false, |
2550 | 2639 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
2551 | 2640 | 'num_dirs' => '', |
2552 | 2641 | 'status' => '', |
2553 | 2642 | ); |
2643 | + } |
|
2554 | 2644 | |
2555 | 2645 | return $basedirs; |
2556 | 2646 | } |
@@ -2566,10 +2656,11 @@ discard block |
||
2566 | 2656 | */ |
2567 | 2657 | function attachDirStatus($dir, $expected_files) |
2568 | 2658 | { |
2569 | - if (!is_dir($dir)) |
|
2570 | - return array('does_not_exist', true, ''); |
|
2571 | - elseif (!is_writable($dir)) |
|
2572 | - return array('not_writable', true, ''); |
|
2659 | + if (!is_dir($dir)) { |
|
2660 | + return array('does_not_exist', true, ''); |
|
2661 | + } elseif (!is_writable($dir)) { |
|
2662 | + return array('not_writable', true, ''); |
|
2663 | + } |
|
2573 | 2664 | |
2574 | 2665 | // Everything is okay so far, start to scan through the directory. |
2575 | 2666 | $num_files = 0; |
@@ -2577,22 +2668,26 @@ discard block |
||
2577 | 2668 | while ($file = $dir_handle->read()) |
2578 | 2669 | { |
2579 | 2670 | // Now do we have a real file here? |
2580 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
2581 | - continue; |
|
2671 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
2672 | + continue; |
|
2673 | + } |
|
2582 | 2674 | |
2583 | 2675 | $num_files++; |
2584 | 2676 | } |
2585 | 2677 | $dir_handle->close(); |
2586 | 2678 | |
2587 | - if ($num_files < $expected_files) |
|
2588 | - return array('files_missing', true, $num_files); |
|
2679 | + if ($num_files < $expected_files) { |
|
2680 | + return array('files_missing', true, $num_files); |
|
2681 | + } |
|
2589 | 2682 | // Empty? |
2590 | - elseif ($expected_files == 0) |
|
2591 | - return array('unused', false, $num_files); |
|
2683 | + elseif ($expected_files == 0) { |
|
2684 | + return array('unused', false, $num_files); |
|
2685 | + } |
|
2592 | 2686 | // All good! |
2593 | - else |
|
2594 | - return array('ok', false, $num_files); |
|
2595 | -} |
|
2687 | + else { |
|
2688 | + return array('ok', false, $num_files); |
|
2689 | + } |
|
2690 | + } |
|
2596 | 2691 | |
2597 | 2692 | /** |
2598 | 2693 | * Maintance function to move attachments from one directory to another |
@@ -2604,10 +2699,11 @@ discard block |
||
2604 | 2699 | checkSession(); |
2605 | 2700 | |
2606 | 2701 | $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
2607 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
2608 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
2609 | - else |
|
2610 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
2702 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
2703 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
2704 | + } else { |
|
2705 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
2706 | + } |
|
2611 | 2707 | |
2612 | 2708 | $_POST['from'] = (int) $_POST['from']; |
2613 | 2709 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2621,11 +2717,13 @@ discard block |
||
2621 | 2717 | $total_moved = 0; |
2622 | 2718 | $total_not_moved = 0; |
2623 | 2719 | |
2624 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
2625 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
2720 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
2721 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
2722 | + } |
|
2626 | 2723 | |
2627 | - if ($_POST['from'] == $_POST['to']) |
|
2628 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
2724 | + if ($_POST['from'] == $_POST['to']) { |
|
2725 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
2726 | + } |
|
2629 | 2727 | |
2630 | 2728 | if (empty($results)) |
2631 | 2729 | { |
@@ -2644,8 +2742,9 @@ discard block |
||
2644 | 2742 | $smcFunc['db_free_result']($request); |
2645 | 2743 | $total_progress -= $start; |
2646 | 2744 | |
2647 | - if ($total_progress < 1) |
|
2648 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2745 | + if ($total_progress < 1) { |
|
2746 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2747 | + } |
|
2649 | 2748 | } |
2650 | 2749 | |
2651 | 2750 | if (empty($results)) |
@@ -2661,9 +2760,9 @@ discard block |
||
2661 | 2760 | |
2662 | 2761 | automanage_attachments_check_directory(); |
2663 | 2762 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
2763 | + } else { |
|
2764 | + $new_dir = $_POST['to']; |
|
2664 | 2765 | } |
2665 | - else |
|
2666 | - $new_dir = $_POST['to']; |
|
2667 | 2766 | |
2668 | 2767 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
2669 | 2768 | |
@@ -2671,8 +2770,9 @@ discard block |
||
2671 | 2770 | while ($break == false) |
2672 | 2771 | { |
2673 | 2772 | @set_time_limit(300); |
2674 | - if (function_exists('apache_reset_timeout')) |
|
2675 | - @apache_reset_timeout(); |
|
2773 | + if (function_exists('apache_reset_timeout')) { |
|
2774 | + @apache_reset_timeout(); |
|
2775 | + } |
|
2676 | 2776 | |
2677 | 2777 | // If limits are set, get the file count and size for the destination folder |
2678 | 2778 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2708,13 +2808,15 @@ discard block |
||
2708 | 2808 | |
2709 | 2809 | if ($smcFunc['db_num_rows']($request) === 0) |
2710 | 2810 | { |
2711 | - if (empty($current_progress)) |
|
2712 | - $results[] = $txt['attachment_transfer_no_find']; |
|
2811 | + if (empty($current_progress)) { |
|
2812 | + $results[] = $txt['attachment_transfer_no_find']; |
|
2813 | + } |
|
2713 | 2814 | break; |
2714 | 2815 | } |
2715 | 2816 | |
2716 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
2717 | - $break = true; |
|
2817 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
2818 | + $break = true; |
|
2819 | + } |
|
2718 | 2820 | |
2719 | 2821 | // Move them |
2720 | 2822 | $moved = array(); |
@@ -2738,8 +2840,9 @@ discard block |
||
2738 | 2840 | automanage_attachments_by_space(); |
2739 | 2841 | |
2740 | 2842 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2741 | - if (!empty($total_not_moved)) |
|
2742 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2843 | + if (!empty($total_not_moved)) { |
|
2844 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2845 | + } |
|
2743 | 2846 | |
2744 | 2847 | $dir_files = 0; |
2745 | 2848 | $total_moved = 0; |
@@ -2747,8 +2850,7 @@ discard block |
||
2747 | 2850 | |
2748 | 2851 | $break = false; |
2749 | 2852 | break; |
2750 | - } |
|
2751 | - else |
|
2853 | + } else |
|
2752 | 2854 | { |
2753 | 2855 | // Hmm, not in auto. Time to bail out then... |
2754 | 2856 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2763,9 +2865,9 @@ discard block |
||
2763 | 2865 | $total_moved++; |
2764 | 2866 | $current_progress++; |
2765 | 2867 | $moved[] = $row['id_attach']; |
2868 | + } else { |
|
2869 | + $total_not_moved++; |
|
2766 | 2870 | } |
2767 | - else |
|
2768 | - $total_not_moved++; |
|
2769 | 2871 | } |
2770 | 2872 | $smcFunc['db_free_result']($request); |
2771 | 2873 | |
@@ -2803,13 +2905,15 @@ discard block |
||
2803 | 2905 | } |
2804 | 2906 | |
2805 | 2907 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
2806 | - if (!empty($total_not_moved)) |
|
2807 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2908 | + if (!empty($total_not_moved)) { |
|
2909 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
2910 | + } |
|
2808 | 2911 | } |
2809 | 2912 | |
2810 | 2913 | $_SESSION['results'] = $results; |
2811 | - if (file_exists($boarddir . '/progress.php')) |
|
2812 | - unlink($boarddir . '/progress.php'); |
|
2914 | + if (file_exists($boarddir . '/progress.php')) { |
|
2915 | + unlink($boarddir . '/progress.php'); |
|
2916 | + } |
|
2813 | 2917 | |
2814 | 2918 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
2815 | 2919 | } |