@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * The main entrance point for the Manage Members screen. |
@@ -62,16 +63,18 @@ discard block |
||
62 | 63 | $context['activation_numbers'] = array(); |
63 | 64 | $context['awaiting_activation'] = 0; |
64 | 65 | $context['awaiting_approval'] = 0; |
65 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
66 | - $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
66 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
67 | + $context['activation_numbers'][$row['is_activated']] = $row['total_members']; |
|
68 | + } |
|
67 | 69 | $smcFunc['db_free_result']($request); |
68 | 70 | |
69 | 71 | foreach ($context['activation_numbers'] as $activation_type => $total_members) |
70 | 72 | { |
71 | - if (in_array($activation_type, array(0, 2))) |
|
72 | - $context['awaiting_activation'] += $total_members; |
|
73 | - elseif (in_array($activation_type, array(3, 4, 5))) |
|
74 | - $context['awaiting_approval'] += $total_members; |
|
73 | + if (in_array($activation_type, array(0, 2))) { |
|
74 | + $context['awaiting_activation'] += $total_members; |
|
75 | + } elseif (in_array($activation_type, array(3, 4, 5))) { |
|
76 | + $context['awaiting_approval'] += $total_members; |
|
77 | + } |
|
75 | 78 | } |
76 | 79 | |
77 | 80 | // For the page header... do we show activation? |
@@ -124,8 +127,9 @@ discard block |
||
124 | 127 | } |
125 | 128 | if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve')) |
126 | 129 | { |
127 | - if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) |
|
128 | - $context['tabs']['search']['is_last'] = true; |
|
130 | + if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) { |
|
131 | + $context['tabs']['search']['is_last'] = true; |
|
132 | + } |
|
129 | 133 | unset($context['tabs']['approve']); |
130 | 134 | } |
131 | 135 | |
@@ -157,8 +161,9 @@ discard block |
||
157 | 161 | foreach ($_POST['delete'] as $key => $value) |
158 | 162 | { |
159 | 163 | // Don't delete yourself, idiot. |
160 | - if ($value != $user_info['id']) |
|
161 | - $delete[$key] = (int) $value; |
|
164 | + if ($value != $user_info['id']) { |
|
165 | + $delete[$key] = (int) $value; |
|
166 | + } |
|
162 | 167 | } |
163 | 168 | |
164 | 169 | if (!empty($delete)) |
@@ -194,17 +199,18 @@ discard block |
||
194 | 199 | ); |
195 | 200 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
196 | 201 | { |
197 | - if ($row['min_posts'] == -1) |
|
198 | - $context['membergroups'][] = array( |
|
202 | + if ($row['min_posts'] == -1) { |
|
203 | + $context['membergroups'][] = array( |
|
199 | 204 | 'id' => $row['id_group'], |
200 | 205 | 'name' => $row['group_name'], |
201 | 206 | 'can_be_additional' => true |
202 | 207 | ); |
203 | - else |
|
204 | - $context['postgroups'][] = array( |
|
208 | + } else { |
|
209 | + $context['postgroups'][] = array( |
|
205 | 210 | 'id' => $row['id_group'], |
206 | 211 | 'name' => $row['group_name'] |
207 | 212 | ); |
213 | + } |
|
208 | 214 | } |
209 | 215 | $smcFunc['db_free_result']($request); |
210 | 216 | |
@@ -268,14 +274,15 @@ discard block |
||
268 | 274 | call_integration_hook('integrate_view_members_params', array(&$params)); |
269 | 275 | |
270 | 276 | $search_params = array(); |
271 | - if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) |
|
272 | - $search_params = smf_json_decode(base64_decode($_REQUEST['params']), true); |
|
273 | - elseif (!empty($_POST)) |
|
277 | + if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) { |
|
278 | + $search_params = smf_json_decode(base64_decode($_REQUEST['params']), true); |
|
279 | + } elseif (!empty($_POST)) |
|
274 | 280 | { |
275 | 281 | $search_params['types'] = $_POST['types']; |
276 | - foreach ($params as $param_name => $param_info) |
|
277 | - if (isset($_POST[$param_name])) |
|
282 | + foreach ($params as $param_name => $param_info) { |
|
283 | + if (isset($_POST[$param_name])) |
|
278 | 284 | $search_params[$param_name] = $_POST[$param_name]; |
285 | + } |
|
279 | 286 | } |
280 | 287 | |
281 | 288 | $search_url_params = isset($search_params) ? base64_encode(json_encode($search_params)) : null; |
@@ -288,18 +295,21 @@ discard block |
||
288 | 295 | foreach ($params as $param_name => $param_info) |
289 | 296 | { |
290 | 297 | // Not filled in? |
291 | - if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') |
|
292 | - continue; |
|
298 | + if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') { |
|
299 | + continue; |
|
300 | + } |
|
293 | 301 | |
294 | 302 | // Make sure numeric values are really numeric. |
295 | - if (in_array($param_info['type'], array('int', 'age'))) |
|
296 | - $search_params[$param_name] = (int) $search_params[$param_name]; |
|
303 | + if (in_array($param_info['type'], array('int', 'age'))) { |
|
304 | + $search_params[$param_name] = (int) $search_params[$param_name]; |
|
305 | + } |
|
297 | 306 | // Date values have to match the specified format. |
298 | 307 | elseif ($param_info['type'] == 'date') |
299 | 308 | { |
300 | 309 | // Check if this date format is valid. |
301 | - if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) |
|
302 | - continue; |
|
310 | + if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) { |
|
311 | + continue; |
|
312 | + } |
|
303 | 313 | |
304 | 314 | $search_params[$param_name] = strtotime($search_params[$param_name]); |
305 | 315 | } |
@@ -308,8 +318,9 @@ discard block |
||
308 | 318 | if (!empty($param_info['range'])) |
309 | 319 | { |
310 | 320 | // Default to '=', just in case... |
311 | - if (empty($range_trans[$search_params['types'][$param_name]])) |
|
312 | - $search_params['types'][$param_name] = '='; |
|
321 | + if (empty($range_trans[$search_params['types'][$param_name]])) { |
|
322 | + $search_params['types'][$param_name] = '='; |
|
323 | + } |
|
313 | 324 | |
314 | 325 | // Handle special case 'age'. |
315 | 326 | if ($param_info['type'] == 'age') |
@@ -337,29 +348,30 @@ discard block |
||
337 | 348 | elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=') |
338 | 349 | { |
339 | 350 | $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400); |
351 | + } else { |
|
352 | + $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
340 | 353 | } |
341 | - else |
|
342 | - $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name]; |
|
343 | 354 | } |
344 | 355 | // Checkboxes. |
345 | 356 | elseif ($param_info['type'] == 'checkbox') |
346 | 357 | { |
347 | 358 | // Each checkbox or no checkbox at all is checked -> ignore. |
348 | - if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) |
|
349 | - continue; |
|
359 | + if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) { |
|
360 | + continue; |
|
361 | + } |
|
350 | 362 | |
351 | 363 | $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})'; |
352 | 364 | $where_params[$param_name . '_check'] = $search_params[$param_name]; |
353 | - } |
|
354 | - else |
|
365 | + } else |
|
355 | 366 | { |
356 | 367 | // Replace the wildcard characters ('*' and '?') into MySQL ones. |
357 | 368 | $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'))); |
358 | 369 | |
359 | - if ($smcFunc['db_case_sensitive']) |
|
360 | - $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
361 | - else |
|
362 | - $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
370 | + if ($smcFunc['db_case_sensitive']) { |
|
371 | + $query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})'; |
|
372 | + } else { |
|
373 | + $query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})'; |
|
374 | + } |
|
363 | 375 | $where_params[$param_name . '_normal'] = '%' . $parameter . '%'; |
364 | 376 | } |
365 | 377 | } |
@@ -375,16 +387,18 @@ discard block |
||
375 | 387 | } |
376 | 388 | |
377 | 389 | // Additional membergroups (these are only relevant if not all primary groups where selected!). |
378 | - if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) |
|
379 | - foreach ($search_params['membergroups'][2] as $mg) |
|
390 | + if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) { |
|
391 | + foreach ($search_params['membergroups'][2] as $mg) |
|
380 | 392 | { |
381 | 393 | $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0'; |
394 | + } |
|
382 | 395 | $where_params['add_group_' . $mg] = $mg; |
383 | 396 | } |
384 | 397 | |
385 | 398 | // Combine the one or two membergroup parts into one query part linked with an OR. |
386 | - if (!empty($mg_query_parts)) |
|
387 | - $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
399 | + if (!empty($mg_query_parts)) { |
|
400 | + $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')'; |
|
401 | + } |
|
388 | 402 | |
389 | 403 | // Get all selected post count related membergroups. |
390 | 404 | if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups'])) |
@@ -396,9 +410,9 @@ discard block |
||
396 | 410 | // Construct the where part of the query. |
397 | 411 | $where = empty($query_parts) ? '1=1' : implode(' |
398 | 412 | AND ', $query_parts); |
413 | + } else { |
|
414 | + $search_url_params = null; |
|
399 | 415 | } |
400 | - else |
|
401 | - $search_url_params = null; |
|
402 | 416 | |
403 | 417 | // Construct the additional URL part with the query info in it. |
404 | 418 | $context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : ''; |
@@ -521,28 +535,32 @@ discard block |
||
521 | 535 | 'function' => function($rowData) use ($txt) |
522 | 536 | { |
523 | 537 | // Calculate number of days since last online. |
524 | - if (empty($rowData['last_login'])) |
|
525 | - $difference = $txt['never']; |
|
526 | - else |
|
538 | + if (empty($rowData['last_login'])) { |
|
539 | + $difference = $txt['never']; |
|
540 | + } else |
|
527 | 541 | { |
528 | 542 | $num_days_difference = jeffsdatediff($rowData['last_login']); |
529 | 543 | |
530 | 544 | // Today. |
531 | - if (empty($num_days_difference)) |
|
532 | - $difference = $txt['viewmembers_today']; |
|
545 | + if (empty($num_days_difference)) { |
|
546 | + $difference = $txt['viewmembers_today']; |
|
547 | + } |
|
533 | 548 | |
534 | 549 | // Yesterday. |
535 | - elseif ($num_days_difference == 1) |
|
536 | - $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
550 | + elseif ($num_days_difference == 1) { |
|
551 | + $difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']); |
|
552 | + } |
|
537 | 553 | |
538 | 554 | // X days ago. |
539 | - else |
|
540 | - $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
555 | + else { |
|
556 | + $difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']); |
|
557 | + } |
|
541 | 558 | } |
542 | 559 | |
543 | 560 | // Show it in italics if they're not activated... |
544 | - if ($rowData['is_activated'] % 10 != 1) |
|
545 | - $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
561 | + if ($rowData['is_activated'] % 10 != 1) { |
|
562 | + $difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference); |
|
563 | + } |
|
546 | 564 | |
547 | 565 | return $difference; |
548 | 566 | }, |
@@ -594,8 +612,9 @@ discard block |
||
594 | 612 | ); |
595 | 613 | |
596 | 614 | // Without enough permissions, don't show 'delete members' checkboxes. |
597 | - if (!allowedTo('profile_remove_any')) |
|
598 | - unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
615 | + if (!allowedTo('profile_remove_any')) { |
|
616 | + unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']); |
|
617 | + } |
|
599 | 618 | |
600 | 619 | require_once($sourcedir . '/Subs-List.php'); |
601 | 620 | createList($listOptions); |
@@ -638,17 +657,18 @@ discard block |
||
638 | 657 | ); |
639 | 658 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
640 | 659 | { |
641 | - if ($row['min_posts'] == -1) |
|
642 | - $context['membergroups'][] = array( |
|
660 | + if ($row['min_posts'] == -1) { |
|
661 | + $context['membergroups'][] = array( |
|
643 | 662 | 'id' => $row['id_group'], |
644 | 663 | 'name' => $row['group_name'], |
645 | 664 | 'can_be_additional' => true |
646 | 665 | ); |
647 | - else |
|
648 | - $context['postgroups'][] = array( |
|
666 | + } else { |
|
667 | + $context['postgroups'][] = array( |
|
649 | 668 | 'id' => $row['id_group'], |
650 | 669 | 'name' => $row['group_name'] |
651 | 670 | ); |
671 | + } |
|
652 | 672 | } |
653 | 673 | $smcFunc['db_free_result']($request); |
654 | 674 | |
@@ -675,8 +695,9 @@ discard block |
||
675 | 695 | $context['page_title'] = $txt['admin_members']; |
676 | 696 | $context['sub_template'] = 'admin_browse'; |
677 | 697 | $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve'); |
678 | - if (isset($context['tabs'][$context['browse_type']])) |
|
679 | - $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
698 | + if (isset($context['tabs'][$context['browse_type']])) { |
|
699 | + $context['tabs'][$context['browse_type']]['is_selected'] = true; |
|
700 | + } |
|
680 | 701 | |
681 | 702 | // Allowed filters are those we can have, in theory. |
682 | 703 | $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2); |
@@ -687,18 +708,20 @@ discard block |
||
687 | 708 | foreach ($context['activation_numbers'] as $type => $amount) |
688 | 709 | { |
689 | 710 | // We have some of these... |
690 | - if (in_array($type, $context['allowed_filters']) && $amount > 0) |
|
691 | - $context['available_filters'][] = array( |
|
711 | + if (in_array($type, $context['allowed_filters']) && $amount > 0) { |
|
712 | + $context['available_filters'][] = array( |
|
692 | 713 | 'type' => $type, |
693 | 714 | 'amount' => $amount, |
694 | 715 | 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?', |
695 | 716 | 'selected' => $type == $context['current_filter'] |
696 | 717 | ); |
718 | + } |
|
697 | 719 | } |
698 | 720 | |
699 | 721 | // If the filter was not sent, set it to whatever has people in it! |
700 | - if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) |
|
701 | - $context['current_filter'] = $context['available_filters'][0]['type']; |
|
722 | + if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) { |
|
723 | + $context['current_filter'] = $context['available_filters'][0]['type']; |
|
724 | + } |
|
702 | 725 | |
703 | 726 | // This little variable is used to determine if we should flag where we are looking. |
704 | 727 | $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1; |
@@ -713,44 +736,47 @@ discard block |
||
713 | 736 | ); |
714 | 737 | |
715 | 738 | // Are we showing duplicate information? |
716 | - if (isset($_GET['showdupes'])) |
|
717 | - $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
739 | + if (isset($_GET['showdupes'])) { |
|
740 | + $_SESSION['showdupes'] = (int) $_GET['showdupes']; |
|
741 | + } |
|
718 | 742 | $context['show_duplicates'] = !empty($_SESSION['showdupes']); |
719 | 743 | |
720 | 744 | // Determine which actions we should allow on this page. |
721 | 745 | if ($context['browse_type'] == 'approve') |
722 | 746 | { |
723 | 747 | // If we are approving deleted accounts we have a slightly different list... actually a mirror ;) |
724 | - if ($context['current_filter'] == 4) |
|
725 | - $context['allowed_actions'] = array( |
|
748 | + if ($context['current_filter'] == 4) { |
|
749 | + $context['allowed_actions'] = array( |
|
726 | 750 | 'reject' => $txt['admin_browse_w_approve_deletion'], |
727 | 751 | 'ok' => $txt['admin_browse_w_reject'], |
728 | 752 | ); |
729 | - else |
|
730 | - $context['allowed_actions'] = array( |
|
753 | + } else { |
|
754 | + $context['allowed_actions'] = array( |
|
731 | 755 | 'ok' => $txt['admin_browse_w_approve'], |
732 | 756 | 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'], |
733 | 757 | 'require_activation' => $txt['admin_browse_w_approve_require_activate'], |
734 | 758 | 'reject' => $txt['admin_browse_w_reject'], |
735 | 759 | 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'], |
736 | 760 | ); |
737 | - } |
|
738 | - elseif ($context['browse_type'] == 'activate') |
|
739 | - $context['allowed_actions'] = array( |
|
761 | + } |
|
762 | + } elseif ($context['browse_type'] == 'activate') { |
|
763 | + $context['allowed_actions'] = array( |
|
740 | 764 | 'ok' => $txt['admin_browse_w_activate'], |
741 | 765 | 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'], |
742 | 766 | 'delete' => $txt['admin_browse_w_delete'], |
743 | 767 | 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'], |
744 | 768 | 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'], |
745 | 769 | ); |
770 | + } |
|
746 | 771 | |
747 | 772 | // Create an option list for actions allowed to be done with selected members. |
748 | 773 | $allowed_actions = ' |
749 | 774 | <option selected value="">' . $txt['admin_browse_with_selected'] . ':</option> |
750 | 775 | <option value="" disabled>-----------------------------</option>'; |
751 | - foreach ($context['allowed_actions'] as $key => $desc) |
|
752 | - $allowed_actions .= ' |
|
776 | + foreach ($context['allowed_actions'] as $key => $desc) { |
|
777 | + $allowed_actions .= ' |
|
753 | 778 | <option value="' . $key . '">' . $desc . '</option>'; |
779 | + } |
|
754 | 780 | |
755 | 781 | // Setup the Javascript function for selecting an action for the list. |
756 | 782 | $javascript = ' |
@@ -762,15 +788,16 @@ discard block |
||
762 | 788 | var message = "";'; |
763 | 789 | |
764 | 790 | // We have special messages for approving deletion of accounts - it's surprisingly logical - honest. |
765 | - if ($context['current_filter'] == 4) |
|
766 | - $javascript .= ' |
|
791 | + if ($context['current_filter'] == 4) { |
|
792 | + $javascript .= ' |
|
767 | 793 | if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
768 | 794 | message = "' . $txt['admin_browse_w_delete'] . '"; |
769 | 795 | else |
770 | 796 | message = "' . $txt['admin_browse_w_reject'] . '";'; |
797 | + } |
|
771 | 798 | // Otherwise a nice standard message. |
772 | - else |
|
773 | - $javascript .= ' |
|
799 | + else { |
|
800 | + $javascript .= ' |
|
774 | 801 | if (document.forms.postForm.todo.value.indexOf("delete") != -1) |
775 | 802 | message = "' . $txt['admin_browse_w_delete'] . '"; |
776 | 803 | else if (document.forms.postForm.todo.value.indexOf("reject") != -1) |
@@ -779,6 +806,7 @@ discard block |
||
779 | 806 | message = "' . $txt['admin_browse_w_remind'] . '"; |
780 | 807 | else |
781 | 808 | message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";'; |
809 | + } |
|
782 | 810 | $javascript .= ' |
783 | 811 | if (confirm(message + " ' . $txt['admin_browse_warn'] . '")) |
784 | 812 | document.forms.postForm.submit(); |
@@ -911,10 +939,11 @@ discard block |
||
911 | 939 | $member_links = array(); |
912 | 940 | foreach ($rowData['duplicate_members'] as $member) |
913 | 941 | { |
914 | - if ($member['id']) |
|
915 | - $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
916 | - else |
|
917 | - $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
942 | + if ($member['id']) { |
|
943 | + $member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>'; |
|
944 | + } else { |
|
945 | + $member_links[] = $member['name'] . ' (' . $txt['guest'] . ')'; |
|
946 | + } |
|
918 | 947 | } |
919 | 948 | return implode(', ', $member_links); |
920 | 949 | }, |
@@ -963,14 +992,16 @@ discard block |
||
963 | 992 | ); |
964 | 993 | |
965 | 994 | // Pick what column to actually include if we're showing duplicates. |
966 | - if ($context['show_duplicates']) |
|
967 | - unset($listOptions['columns']['email']); |
|
968 | - else |
|
969 | - unset($listOptions['columns']['duplicates']); |
|
995 | + if ($context['show_duplicates']) { |
|
996 | + unset($listOptions['columns']['email']); |
|
997 | + } else { |
|
998 | + unset($listOptions['columns']['duplicates']); |
|
999 | + } |
|
970 | 1000 | |
971 | 1001 | // Only show hostname on duplicates as it takes a lot of time. |
972 | - if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) |
|
973 | - unset($listOptions['columns']['hostname']); |
|
1002 | + if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) { |
|
1003 | + unset($listOptions['columns']['hostname']); |
|
1004 | + } |
|
974 | 1005 | |
975 | 1006 | // Is there any need to show filters? |
976 | 1007 | if (isset($context['available_filters']) && count($context['available_filters']) > 1) |
@@ -978,9 +1009,10 @@ discard block |
||
978 | 1009 | $filterOptions = ' |
979 | 1010 | <strong>' . $txt['admin_browse_filter_by'] . ':</strong> |
980 | 1011 | <select name="filter" onchange="this.form.submit();">'; |
981 | - foreach ($context['available_filters'] as $filter) |
|
982 | - $filterOptions .= ' |
|
1012 | + foreach ($context['available_filters'] as $filter) { |
|
1013 | + $filterOptions .= ' |
|
983 | 1014 | <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>'; |
1015 | + } |
|
984 | 1016 | $filterOptions .= ' |
985 | 1017 | </select> |
986 | 1018 | <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit"></noscript>'; |
@@ -992,12 +1024,13 @@ discard block |
||
992 | 1024 | } |
993 | 1025 | |
994 | 1026 | // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at. |
995 | - if (!empty($context['show_filter']) && !empty($context['available_filters'])) |
|
996 | - $listOptions['additional_rows'][] = array( |
|
1027 | + if (!empty($context['show_filter']) && !empty($context['available_filters'])) { |
|
1028 | + $listOptions['additional_rows'][] = array( |
|
997 | 1029 | 'position' => 'above_column_headers', |
998 | 1030 | 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'], |
999 | 1031 | 'class' => 'smalltext floatright', |
1000 | 1032 | ); |
1033 | + } |
|
1001 | 1034 | |
1002 | 1035 | // Now that we have all the options, create the list. |
1003 | 1036 | require_once($sourcedir . '/Subs-List.php'); |
@@ -1027,12 +1060,14 @@ discard block |
||
1027 | 1060 | $current_filter = (int) $_REQUEST['orig_filter']; |
1028 | 1061 | |
1029 | 1062 | // If we are applying a filter do just that - then redirect. |
1030 | - if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) |
|
1031 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1063 | + if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) { |
|
1064 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']); |
|
1065 | + } |
|
1032 | 1066 | |
1033 | 1067 | // Nothing to do? |
1034 | - if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) |
|
1035 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1068 | + if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) { |
|
1069 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1070 | + } |
|
1036 | 1071 | |
1037 | 1072 | // Are we dealing with members who have been waiting for > set amount of time? |
1038 | 1073 | if (isset($_POST['time_passed'])) |
@@ -1045,8 +1080,9 @@ discard block |
||
1045 | 1080 | else |
1046 | 1081 | { |
1047 | 1082 | $members = array(); |
1048 | - foreach ($_POST['todoAction'] as $id) |
|
1049 | - $members[] = (int) $id; |
|
1083 | + foreach ($_POST['todoAction'] as $id) { |
|
1084 | + $members[] = (int) $id; |
|
1085 | + } |
|
1050 | 1086 | $condition = ' |
1051 | 1087 | AND id_member IN ({array_int:members})'; |
1052 | 1088 | } |
@@ -1067,8 +1103,9 @@ discard block |
||
1067 | 1103 | $member_count = $smcFunc['db_num_rows']($request); |
1068 | 1104 | |
1069 | 1105 | // If no results then just return! |
1070 | - if ($member_count == 0) |
|
1071 | - redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1106 | + if ($member_count == 0) { |
|
1107 | + redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
|
1108 | + } |
|
1072 | 1109 | |
1073 | 1110 | $member_info = array(); |
1074 | 1111 | $members = array(); |
@@ -1107,8 +1144,9 @@ discard block |
||
1107 | 1144 | // Do we have to let the integration code know about the activations? |
1108 | 1145 | if (!empty($modSettings['integrate_activate'])) |
1109 | 1146 | { |
1110 | - foreach ($member_info as $member) |
|
1111 | - call_integration_hook('integrate_activate', array($member['username'])); |
|
1147 | + foreach ($member_info as $member) { |
|
1148 | + call_integration_hook('integrate_activate', array($member['username'])); |
|
1149 | + } |
|
1112 | 1150 | } |
1113 | 1151 | |
1114 | 1152 | // Check for email. |
@@ -1238,20 +1276,23 @@ discard block |
||
1238 | 1276 | $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member'; |
1239 | 1277 | |
1240 | 1278 | require_once($sourcedir . '/Logging.php'); |
1241 | - foreach ($member_info as $member) |
|
1242 | - logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1279 | + foreach ($member_info as $member) { |
|
1280 | + logAction($log_action, array('member' => $member['id']), 'admin'); |
|
1281 | + } |
|
1243 | 1282 | } |
1244 | 1283 | |
1245 | 1284 | // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers). |
1246 | - if (in_array($current_filter, array(3, 4, 5))) |
|
1247 | - updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1285 | + if (in_array($current_filter, array(3, 4, 5))) { |
|
1286 | + updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0))); |
|
1287 | + } |
|
1248 | 1288 | |
1249 | 1289 | // Update the member's stats. (but, we know the member didn't change their name.) |
1250 | 1290 | updateStats('member', false); |
1251 | 1291 | |
1252 | 1292 | // If they haven't been deleted, update the post group statistics on them... |
1253 | - if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) |
|
1254 | - updateStats('postgroups', $members); |
|
1293 | + if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) { |
|
1294 | + updateStats('postgroups', $members); |
|
1295 | + } |
|
1255 | 1296 | |
1256 | 1297 | redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']); |
1257 | 1298 | } |
@@ -1276,10 +1317,11 @@ discard block |
||
1276 | 1317 | $dis = time() - $old; |
1277 | 1318 | |
1278 | 1319 | // Before midnight? |
1279 | - if ($dis < $sinceMidnight) |
|
1280 | - return 0; |
|
1281 | - else |
|
1282 | - $dis -= $sinceMidnight; |
|
1320 | + if ($dis < $sinceMidnight) { |
|
1321 | + return 0; |
|
1322 | + } else { |
|
1323 | + $dis -= $sinceMidnight; |
|
1324 | + } |
|
1283 | 1325 | |
1284 | 1326 | // Divide out the seconds in a day to get the number of days. |
1285 | 1327 | return ceil($dis / (24 * 60 * 60)); |
@@ -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 | * Check if the current directory is still valid or not. |
@@ -28,22 +29,24 @@ discard block |
||
28 | 29 | global $boarddir, $modSettings, $context; |
29 | 30 | |
30 | 31 | // Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found. |
31 | - if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') |
|
32 | - $doit = true; |
|
33 | - elseif (empty($modSettings['automanage_attachments'])) |
|
34 | - return; |
|
35 | - elseif (!isset($_FILES)) |
|
36 | - return; |
|
37 | - elseif (isset($_FILES['attachment'])) |
|
38 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
32 | + if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') { |
|
33 | + $doit = true; |
|
34 | + } elseif (empty($modSettings['automanage_attachments'])) { |
|
35 | + return; |
|
36 | + } elseif (!isset($_FILES)) { |
|
37 | + return; |
|
38 | + } elseif (isset($_FILES['attachment'])) { |
|
39 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
39 | 40 | if (!empty($dummy)) |
40 | 41 | { |
41 | 42 | $doit = true; |
43 | + } |
|
42 | 44 | break; |
43 | 45 | } |
44 | 46 | |
45 | - if (!isset($doit)) |
|
46 | - return; |
|
47 | + if (!isset($doit)) { |
|
48 | + return; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | $year = date('Y'); |
49 | 52 | $month = date('m'); |
@@ -54,21 +57,25 @@ discard block |
||
54 | 57 | |
55 | 58 | if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments'])) |
56 | 59 | { |
57 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
58 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
60 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
61 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
62 | + } |
|
59 | 63 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
64 | + } else { |
|
65 | + $base_dir = 0; |
|
60 | 66 | } |
61 | - else |
|
62 | - $base_dir = 0; |
|
63 | 67 | |
64 | 68 | if ($modSettings['automanage_attachments'] == 1) |
65 | 69 | { |
66 | - if (!isset($modSettings['last_attachments_directory'])) |
|
67 | - $modSettings['last_attachments_directory'] = array(); |
|
68 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
69 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
70 | - if (!isset($modSettings['last_attachments_directory'][$base_dir])) |
|
71 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
70 | + if (!isset($modSettings['last_attachments_directory'])) { |
|
71 | + $modSettings['last_attachments_directory'] = array(); |
|
72 | + } |
|
73 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
74 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
75 | + } |
|
76 | + if (!isset($modSettings['last_attachments_directory'][$base_dir])) { |
|
77 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
78 | + } |
|
72 | 79 | } |
73 | 80 | |
74 | 81 | $basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
@@ -97,12 +104,14 @@ discard block |
||
97 | 104 | $updir = ''; |
98 | 105 | } |
99 | 106 | |
100 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
101 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
102 | - if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) |
|
103 | - $outputCreation = automanage_attachments_create_directory($updir); |
|
104 | - elseif (in_array($updir, $modSettings['attachmentUploadDir'])) |
|
105 | - $outputCreation = true; |
|
107 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
108 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
109 | + } |
|
110 | + if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) { |
|
111 | + $outputCreation = automanage_attachments_create_directory($updir); |
|
112 | + } elseif (in_array($updir, $modSettings['attachmentUploadDir'])) { |
|
113 | + $outputCreation = true; |
|
114 | + } |
|
106 | 115 | |
107 | 116 | if ($outputCreation) |
108 | 117 | { |
@@ -139,8 +148,9 @@ discard block |
||
139 | 148 | $count = count($tree); |
140 | 149 | |
141 | 150 | $directory = attachments_init_dir($tree, $count); |
142 | - if ($directory === false) |
|
143 | - return false; |
|
151 | + if ($directory === false) { |
|
152 | + return false; |
|
153 | + } |
|
144 | 154 | } |
145 | 155 | |
146 | 156 | $directory .= DIRECTORY_SEPARATOR . array_shift($tree); |
@@ -168,8 +178,9 @@ discard block |
||
168 | 178 | } |
169 | 179 | |
170 | 180 | // Everything seems fine...let's create the .htaccess |
171 | - if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) |
|
172 | - secureDirectory($updir, true); |
|
181 | + if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) { |
|
182 | + secureDirectory($updir, true); |
|
183 | + } |
|
173 | 184 | |
174 | 185 | $sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR; |
175 | 186 | $updir = rtrim($updir, $sep); |
@@ -201,8 +212,9 @@ discard block |
||
201 | 212 | { |
202 | 213 | global $modSettings, $boarddir; |
203 | 214 | |
204 | - if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) |
|
205 | - return; |
|
215 | + if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) { |
|
216 | + return; |
|
217 | + } |
|
206 | 218 | |
207 | 219 | $basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir; |
208 | 220 | // Just to be sure: I don't want directory separators at the end |
@@ -214,13 +226,14 @@ discard block |
||
214 | 226 | { |
215 | 227 | $base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']); |
216 | 228 | $base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0; |
229 | + } else { |
|
230 | + $base_dir = 0; |
|
217 | 231 | } |
218 | - else |
|
219 | - $base_dir = 0; |
|
220 | 232 | |
221 | 233 | // Get the last attachment directory for that base directory |
222 | - if (empty($modSettings['last_attachments_directory'][$base_dir])) |
|
223 | - $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
234 | + if (empty($modSettings['last_attachments_directory'][$base_dir])) { |
|
235 | + $modSettings['last_attachments_directory'][$base_dir] = 0; |
|
236 | + } |
|
224 | 237 | // And increment it. |
225 | 238 | $modSettings['last_attachments_directory'][$base_dir]++; |
226 | 239 | |
@@ -235,10 +248,10 @@ discard block |
||
235 | 248 | $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
236 | 249 | |
237 | 250 | return true; |
251 | + } else { |
|
252 | + return false; |
|
253 | + } |
|
238 | 254 | } |
239 | - else |
|
240 | - return false; |
|
241 | -} |
|
242 | 255 | |
243 | 256 | /** |
244 | 257 | * Split a path into a list of all directories and subdirectories |
@@ -256,12 +269,13 @@ discard block |
||
256 | 269 | * in Windows we need to explode for both \ and / |
257 | 270 | * while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR) |
258 | 271 | */ |
259 | - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') |
|
260 | - $tree = preg_split('#[\\\/]#', $directory); |
|
261 | - else |
|
272 | + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
273 | + $tree = preg_split('#[\\\/]#', $directory); |
|
274 | + } else |
|
262 | 275 | { |
263 | - if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) |
|
264 | - return false; |
|
276 | + if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) { |
|
277 | + return false; |
|
278 | + } |
|
265 | 279 | |
266 | 280 | $tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR)); |
267 | 281 | } |
@@ -285,10 +299,11 @@ discard block |
||
285 | 299 | //Better be sure that the first part of the path is actually a drive letter... |
286 | 300 | //...even if, I should check this in the admin page...isn't it? |
287 | 301 | //...NHAAA Let's leave space for users' complains! :P |
288 | - if (preg_match('/^[a-z]:$/i', $tree[0])) |
|
289 | - $directory = array_shift($tree); |
|
290 | - else |
|
291 | - return false; |
|
302 | + if (preg_match('/^[a-z]:$/i', $tree[0])) { |
|
303 | + $directory = array_shift($tree); |
|
304 | + } else { |
|
305 | + return false; |
|
306 | + } |
|
292 | 307 | |
293 | 308 | $count--; |
294 | 309 | } |
@@ -303,18 +318,20 @@ discard block |
||
303 | 318 | global $context, $modSettings, $smcFunc, $txt, $user_info; |
304 | 319 | |
305 | 320 | // Make sure we're uploading to the right place. |
306 | - if (!empty($modSettings['automanage_attachments'])) |
|
307 | - automanage_attachments_check_directory(); |
|
321 | + if (!empty($modSettings['automanage_attachments'])) { |
|
322 | + automanage_attachments_check_directory(); |
|
323 | + } |
|
308 | 324 | |
309 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
310 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
325 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
326 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
327 | + } |
|
311 | 328 | |
312 | 329 | $context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
313 | 330 | |
314 | 331 | // Is the attachments folder actualy there? |
315 | - if (!empty($context['dir_creation_error'])) |
|
316 | - $initial_error = $context['dir_creation_error']; |
|
317 | - elseif (!is_dir($context['attach_dir'])) |
|
332 | + if (!empty($context['dir_creation_error'])) { |
|
333 | + $initial_error = $context['dir_creation_error']; |
|
334 | + } elseif (!is_dir($context['attach_dir'])) |
|
318 | 335 | { |
319 | 336 | $initial_error = 'attach_folder_warning'; |
320 | 337 | log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical'); |
@@ -337,12 +354,12 @@ discard block |
||
337 | 354 | ); |
338 | 355 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
339 | 356 | $smcFunc['db_free_result']($request); |
340 | - } |
|
341 | - else |
|
342 | - $context['attachments'] = array( |
|
357 | + } else { |
|
358 | + $context['attachments'] = array( |
|
343 | 359 | 'quantity' => 0, |
344 | 360 | 'total_size' => 0, |
345 | 361 | ); |
362 | + } |
|
346 | 363 | } |
347 | 364 | |
348 | 365 | // Hmm. There are still files in session. |
@@ -352,39 +369,44 @@ discard block |
||
352 | 369 | // Let's try to keep them. But... |
353 | 370 | $ignore_temp = true; |
354 | 371 | // If new files are being added. We can't ignore those |
355 | - foreach ($_FILES['attachment']['tmp_name'] as $dummy) |
|
356 | - if (!empty($dummy)) |
|
372 | + foreach ($_FILES['attachment']['tmp_name'] as $dummy) { |
|
373 | + if (!empty($dummy)) |
|
357 | 374 | { |
358 | 375 | $ignore_temp = false; |
376 | + } |
|
359 | 377 | break; |
360 | 378 | } |
361 | 379 | |
362 | 380 | // Need to make space for the new files. So, bye bye. |
363 | 381 | if (!$ignore_temp) |
364 | 382 | { |
365 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
366 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
383 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
384 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
367 | 385 | unlink($attachment['tmp_name']); |
386 | + } |
|
368 | 387 | |
369 | 388 | $context['we_are_history'] = $txt['error_temp_attachments_flushed']; |
370 | 389 | $_SESSION['temp_attachments'] = array(); |
371 | 390 | } |
372 | 391 | } |
373 | 392 | |
374 | - if (!isset($_FILES['attachment']['name'])) |
|
375 | - $_FILES['attachment']['tmp_name'] = array(); |
|
393 | + if (!isset($_FILES['attachment']['name'])) { |
|
394 | + $_FILES['attachment']['tmp_name'] = array(); |
|
395 | + } |
|
376 | 396 | |
377 | - if (!isset($_SESSION['temp_attachments'])) |
|
378 | - $_SESSION['temp_attachments'] = array(); |
|
397 | + if (!isset($_SESSION['temp_attachments'])) { |
|
398 | + $_SESSION['temp_attachments'] = array(); |
|
399 | + } |
|
379 | 400 | |
380 | 401 | // Remember where we are at. If it's anywhere at all. |
381 | - if (!$ignore_temp) |
|
382 | - $_SESSION['temp_attachments']['post'] = array( |
|
402 | + if (!$ignore_temp) { |
|
403 | + $_SESSION['temp_attachments']['post'] = array( |
|
383 | 404 | 'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0, |
384 | 405 | 'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0, |
385 | 406 | 'topic' => !empty($topic) ? $topic : 0, |
386 | 407 | 'board' => !empty($board) ? $board : 0, |
387 | 408 | ); |
409 | + } |
|
388 | 410 | |
389 | 411 | // If we have an initial error, lets just display it. |
390 | 412 | if (!empty($initial_error)) |
@@ -392,9 +414,10 @@ discard block |
||
392 | 414 | $_SESSION['temp_attachments']['initial_error'] = $initial_error; |
393 | 415 | |
394 | 416 | // And delete the files 'cos they ain't going nowhere. |
395 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
396 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
417 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
418 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
397 | 419 | unlink($_FILES['attachment']['tmp_name'][$n]); |
420 | + } |
|
398 | 421 | |
399 | 422 | $_FILES['attachment']['tmp_name'] = array(); |
400 | 423 | } |
@@ -402,21 +425,24 @@ discard block |
||
402 | 425 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
403 | 426 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
404 | 427 | { |
405 | - if ($_FILES['attachment']['name'][$n] == '') |
|
406 | - continue; |
|
428 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
429 | + continue; |
|
430 | + } |
|
407 | 431 | |
408 | 432 | // First, let's first check for PHP upload errors. |
409 | 433 | $errors = array(); |
410 | 434 | if (!empty($_FILES['attachment']['error'][$n])) |
411 | 435 | { |
412 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
413 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
414 | - elseif ($_FILES['attachment']['error'][$n] == 6) |
|
415 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
416 | - else |
|
417 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
418 | - if (empty($errors)) |
|
419 | - $errors[] = 'attach_php_error'; |
|
436 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
437 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
438 | + } elseif ($_FILES['attachment']['error'][$n] == 6) { |
|
439 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
440 | + } else { |
|
441 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
442 | + } |
|
443 | + if (empty($errors)) { |
|
444 | + $errors[] = 'attach_php_error'; |
|
445 | + } |
|
420 | 446 | } |
421 | 447 | |
422 | 448 | // Try to move and rename the file before doing any more checks on it. |
@@ -426,8 +452,9 @@ discard block |
||
426 | 452 | { |
427 | 453 | // The reported MIME type of the attachment might not be reliable. |
428 | 454 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
429 | - if (function_exists('mime_content_type')) |
|
430 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
455 | + if (function_exists('mime_content_type')) { |
|
456 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
457 | + } |
|
431 | 458 | |
432 | 459 | $_SESSION['temp_attachments'][$attachID] = array( |
433 | 460 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -439,16 +466,16 @@ discard block |
||
439 | 466 | ); |
440 | 467 | |
441 | 468 | // Move the file to the attachments folder with a temp name for now. |
442 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
443 | - smf_chmod($destName, 0644); |
|
444 | - else |
|
469 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
470 | + smf_chmod($destName, 0644); |
|
471 | + } else |
|
445 | 472 | { |
446 | 473 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
447 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
448 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
474 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
475 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
476 | + } |
|
449 | 477 | } |
450 | - } |
|
451 | - else |
|
478 | + } else |
|
452 | 479 | { |
453 | 480 | $_SESSION['temp_attachments'][$attachID] = array( |
454 | 481 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -456,12 +483,14 @@ discard block |
||
456 | 483 | 'errors' => $errors, |
457 | 484 | ); |
458 | 485 | |
459 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
460 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
486 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
487 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
488 | + } |
|
461 | 489 | } |
462 | 490 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
463 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
464 | - attachmentChecks($attachID); |
|
491 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
492 | + attachmentChecks($attachID); |
|
493 | + } |
|
465 | 494 | } |
466 | 495 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
467 | 496 | // Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand()) |
@@ -488,21 +517,20 @@ discard block |
||
488 | 517 | global $modSettings, $context, $sourcedir, $smcFunc; |
489 | 518 | |
490 | 519 | // No data or missing data .... Not necessarily needed, but in case a mod author missed something. |
491 | - if (empty($_SESSION['temp_attachments'][$attachID])) |
|
492 | - $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
493 | - |
|
494 | - elseif (empty($attachID)) |
|
495 | - $error = '$attachID'; |
|
496 | - |
|
497 | - elseif (empty($context['attachments'])) |
|
498 | - $error = '$context[\'attachments\']'; |
|
499 | - |
|
500 | - elseif (empty($context['attach_dir'])) |
|
501 | - $error = '$context[\'attach_dir\']'; |
|
520 | + if (empty($_SESSION['temp_attachments'][$attachID])) { |
|
521 | + $error = '$_SESSION[\'temp_attachments\'][$attachID]'; |
|
522 | + } elseif (empty($attachID)) { |
|
523 | + $error = '$attachID'; |
|
524 | + } elseif (empty($context['attachments'])) { |
|
525 | + $error = '$context[\'attachments\']'; |
|
526 | + } elseif (empty($context['attach_dir'])) { |
|
527 | + $error = '$context[\'attach_dir\']'; |
|
528 | + } |
|
502 | 529 | |
503 | 530 | // Let's get their attention. |
504 | - if (!empty($error)) |
|
505 | - fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
531 | + if (!empty($error)) { |
|
532 | + fatal_lang_error('attach_check_nag', 'debug', array($error)); |
|
533 | + } |
|
506 | 534 | |
507 | 535 | // Just in case this slipped by the first checks, we stop it here and now |
508 | 536 | if ($_SESSION['temp_attachments'][$attachID]['size'] == 0) |
@@ -531,8 +559,9 @@ discard block |
||
531 | 559 | $size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']); |
532 | 560 | if (!(empty($size)) && ($size[2] != $old_format)) |
533 | 561 | { |
534 | - if (isset($context['validImageTypes'][$size[2]])) |
|
535 | - $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
562 | + if (isset($context['validImageTypes'][$size[2]])) { |
|
563 | + $_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
564 | + } |
|
536 | 565 | } |
537 | 566 | } |
538 | 567 | } |
@@ -586,42 +615,48 @@ discard block |
||
586 | 615 | // Or, let the user know that it ain't gonna happen. |
587 | 616 | else |
588 | 617 | { |
589 | - if (isset($context['dir_creation_error'])) |
|
590 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
591 | - else |
|
592 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
618 | + if (isset($context['dir_creation_error'])) { |
|
619 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error']; |
|
620 | + } else { |
|
621 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
622 | + } |
|
593 | 623 | } |
624 | + } else { |
|
625 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
594 | 626 | } |
595 | - else |
|
596 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space'; |
|
597 | 627 | } |
598 | 628 | } |
599 | 629 | |
600 | 630 | // Is the file too big? |
601 | 631 | $context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size']; |
602 | - if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) |
|
603 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
632 | + if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) { |
|
633 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0))); |
|
634 | + } |
|
604 | 635 | |
605 | 636 | // Check the total upload size for this post... |
606 | - if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) |
|
607 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
637 | + if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) { |
|
638 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0))); |
|
639 | + } |
|
608 | 640 | |
609 | 641 | // Have we reached the maximum number of files we are allowed? |
610 | 642 | $context['attachments']['quantity']++; |
611 | 643 | |
612 | 644 | // Set a max limit if none exists |
613 | - if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) |
|
614 | - $modSettings['attachmentNumPerPostLimit'] = 50; |
|
645 | + if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) { |
|
646 | + $modSettings['attachmentNumPerPostLimit'] = 50; |
|
647 | + } |
|
615 | 648 | |
616 | - if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) |
|
617 | - $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
649 | + if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) { |
|
650 | + $_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit'])); |
|
651 | + } |
|
618 | 652 | |
619 | 653 | // File extension check |
620 | 654 | if (!empty($modSettings['attachmentCheckExtensions'])) |
621 | 655 | { |
622 | 656 | $allowed = explode(',', strtolower($modSettings['attachmentExtensions'])); |
623 | - foreach ($allowed as $k => $dummy) |
|
624 | - $allowed[$k] = trim($dummy); |
|
657 | + foreach ($allowed as $k => $dummy) { |
|
658 | + $allowed[$k] = trim($dummy); |
|
659 | + } |
|
625 | 660 | |
626 | 661 | if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed)) |
627 | 662 | { |
@@ -633,10 +668,12 @@ discard block |
||
633 | 668 | // Undo the math if there's an error |
634 | 669 | if (!empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
635 | 670 | { |
636 | - if (isset($context['dir_size'])) |
|
637 | - $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
638 | - if (isset($context['dir_files'])) |
|
639 | - $context['dir_files']--; |
|
671 | + if (isset($context['dir_size'])) { |
|
672 | + $context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
|
673 | + } |
|
674 | + if (isset($context['dir_files'])) { |
|
675 | + $context['dir_files']--; |
|
676 | + } |
|
640 | 677 | $context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size']; |
641 | 678 | $context['attachments']['quantity']--; |
642 | 679 | return false; |
@@ -668,12 +705,14 @@ discard block |
||
668 | 705 | if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width']) |
669 | 706 | { |
670 | 707 | // Got a proper mime type? |
671 | - if (!empty($size['mime'])) |
|
672 | - $attachmentOptions['mime_type'] = $size['mime']; |
|
708 | + if (!empty($size['mime'])) { |
|
709 | + $attachmentOptions['mime_type'] = $size['mime']; |
|
710 | + } |
|
673 | 711 | |
674 | 712 | // Otherwise a valid one? |
675 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
676 | - $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
713 | + elseif (isset($context['validImageTypes'][$size[2]])) { |
|
714 | + $attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]]; |
|
715 | + } |
|
677 | 716 | } |
678 | 717 | |
679 | 718 | // It is possible we might have a MIME type that isn't actually an image but still have a size. |
@@ -685,15 +724,17 @@ discard block |
||
685 | 724 | } |
686 | 725 | |
687 | 726 | // Get the hash if no hash has been given yet. |
688 | - if (empty($attachmentOptions['file_hash'])) |
|
689 | - $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
727 | + if (empty($attachmentOptions['file_hash'])) { |
|
728 | + $attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true); |
|
729 | + } |
|
690 | 730 | |
691 | 731 | // Assuming no-one set the extension let's take a look at it. |
692 | 732 | if (empty($attachmentOptions['fileext'])) |
693 | 733 | { |
694 | 734 | $attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : ''); |
695 | - if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) |
|
696 | - $attachmentOptions['fileext'] = ''; |
|
735 | + if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) { |
|
736 | + $attachmentOptions['fileext'] = ''; |
|
737 | + } |
|
697 | 738 | } |
698 | 739 | |
699 | 740 | // Last chance to change stuff! |
@@ -702,8 +743,9 @@ discard block |
||
702 | 743 | // Make sure the folder is valid... |
703 | 744 | $tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true); |
704 | 745 | $folders = array_keys($tmp); |
705 | - if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) |
|
706 | - $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
746 | + if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) { |
|
747 | + $attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir']; |
|
748 | + } |
|
707 | 749 | |
708 | 750 | $attachmentOptions['id'] = $smcFunc['db_insert']('', |
709 | 751 | '{db_prefix}attachments', |
@@ -734,8 +776,8 @@ discard block |
||
734 | 776 | rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']); |
735 | 777 | |
736 | 778 | // If it's not approved then add to the approval queue. |
737 | - if (!$attachmentOptions['approved']) |
|
738 | - $smcFunc['db_insert']('', |
|
779 | + if (!$attachmentOptions['approved']) { |
|
780 | + $smcFunc['db_insert']('', |
|
739 | 781 | '{db_prefix}approval_queue', |
740 | 782 | array( |
741 | 783 | 'id_attach' => 'int', 'id_msg' => 'int', |
@@ -745,9 +787,11 @@ discard block |
||
745 | 787 | ), |
746 | 788 | array() |
747 | 789 | ); |
790 | + } |
|
748 | 791 | |
749 | - if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) |
|
750 | - return true; |
|
792 | + if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) { |
|
793 | + return true; |
|
794 | + } |
|
751 | 795 | |
752 | 796 | // Like thumbnails, do we? |
753 | 797 | if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight'])) |
@@ -758,13 +802,15 @@ discard block |
||
758 | 802 | $size = @getimagesize($attachmentOptions['destination'] . '_thumb'); |
759 | 803 | list ($thumb_width, $thumb_height) = $size; |
760 | 804 | |
761 | - if (!empty($size['mime'])) |
|
762 | - $thumb_mime = $size['mime']; |
|
763 | - elseif (isset($context['validImageTypes'][$size[2]])) |
|
764 | - $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
805 | + if (!empty($size['mime'])) { |
|
806 | + $thumb_mime = $size['mime']; |
|
807 | + } elseif (isset($context['validImageTypes'][$size[2]])) { |
|
808 | + $thumb_mime = 'image/' . $context['validImageTypes'][$size[2]]; |
|
809 | + } |
|
765 | 810 | // Lord only knows how this happened... |
766 | - else |
|
767 | - $thumb_mime = ''; |
|
811 | + else { |
|
812 | + $thumb_mime = ''; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | $thumb_filename = $attachmentOptions['name'] . '_thumb'; |
770 | 816 | $thumb_size = filesize($attachmentOptions['destination'] . '_thumb'); |
@@ -844,15 +890,17 @@ discard block |
||
844 | 890 | global $smcFunc; |
845 | 891 | |
846 | 892 | // Oh, come on! |
847 | - if (empty($attachIDs) || empty($msgID)) |
|
848 | - return false; |
|
893 | + if (empty($attachIDs) || empty($msgID)) { |
|
894 | + return false; |
|
895 | + } |
|
849 | 896 | |
850 | 897 | // "I see what is right and approve, but I do what is wrong." |
851 | 898 | call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID)); |
852 | 899 | |
853 | 900 | // One last check |
854 | - if (empty($attachIDs)) |
|
855 | - return false; |
|
901 | + if (empty($attachIDs)) { |
|
902 | + return false; |
|
903 | + } |
|
856 | 904 | |
857 | 905 | // Perform. |
858 | 906 | $smcFunc['db_query']('', ' |
@@ -880,8 +928,9 @@ discard block |
||
880 | 928 | global $board, $modSettings, $context, $scripturl, $smcFunc; |
881 | 929 | |
882 | 930 | // Meh... |
883 | - if (empty($attachID)) |
|
884 | - return 'attachments_no_data_loaded'; |
|
931 | + if (empty($attachID)) { |
|
932 | + return 'attachments_no_data_loaded'; |
|
933 | + } |
|
885 | 934 | |
886 | 935 | // Make it easy. |
887 | 936 | $msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0; |
@@ -890,20 +939,23 @@ discard block |
||
890 | 939 | $externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID)); |
891 | 940 | |
892 | 941 | // "I am innocent of the blood of this just person: see ye to it." |
893 | - if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) |
|
894 | - return $externalParse; |
|
942 | + if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) { |
|
943 | + return $externalParse; |
|
944 | + } |
|
895 | 945 | |
896 | 946 | //Are attachments enable? |
897 | - if (empty($modSettings['attachmentEnable'])) |
|
898 | - return 'attachments_not_enable'; |
|
947 | + if (empty($modSettings['attachmentEnable'])) { |
|
948 | + return 'attachments_not_enable'; |
|
949 | + } |
|
899 | 950 | |
900 | 951 | // Previewing much? no msg ID has been set yet. |
901 | 952 | if (!empty($context['preview_message'])) |
902 | 953 | { |
903 | 954 | $allAttachments = getAttachsByMsg(0); |
904 | 955 | |
905 | - if (empty($allAttachments[0][$attachID])) |
|
906 | - return 'attachments_no_data_loaded'; |
|
956 | + if (empty($allAttachments[0][$attachID])) { |
|
957 | + return 'attachments_no_data_loaded'; |
|
958 | + } |
|
907 | 959 | |
908 | 960 | $attachLoaded = loadAttachmentContext(0, $allAttachments); |
909 | 961 | |
@@ -915,57 +967,66 @@ discard block |
||
915 | 967 | $attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>'; |
916 | 968 | |
917 | 969 | // Fix the thumbnail too, if the image has one. |
918 | - if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) |
|
919 | - $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
970 | + if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) { |
|
971 | + $attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview'; |
|
972 | + } |
|
920 | 973 | |
921 | 974 | return $attachContext; |
922 | 975 | } |
923 | 976 | |
924 | 977 | // There is always the chance someone else has already done our dirty work... |
925 | 978 | // If so, all pertinent checks were already done. Hopefully... |
926 | - if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) |
|
927 | - return $context['current_attachments'][$attachID]; |
|
979 | + if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) { |
|
980 | + return $context['current_attachments'][$attachID]; |
|
981 | + } |
|
928 | 982 | |
929 | 983 | // If we are lucky enough to be in $board's scope then check it! |
930 | - if (!empty($board) && !allowedTo('view_attachments', $board)) |
|
931 | - return 'attachments_not_allowed_to_see'; |
|
984 | + if (!empty($board) && !allowedTo('view_attachments', $board)) { |
|
985 | + return 'attachments_not_allowed_to_see'; |
|
986 | + } |
|
932 | 987 | |
933 | 988 | // Get the message info associated with this particular attach ID. |
934 | 989 | $attachInfo = getAttachMsgInfo($attachID); |
935 | 990 | |
936 | 991 | // There is always the chance this attachment no longer exists or isn't associated to a message anymore... |
937 | - if (empty($attachInfo) || empty($attachInfo['msg'])) |
|
938 | - return 'attachments_no_msg_associated'; |
|
992 | + if (empty($attachInfo) || empty($attachInfo['msg'])) { |
|
993 | + return 'attachments_no_msg_associated'; |
|
994 | + } |
|
939 | 995 | |
940 | 996 | // Hold it! got the info now check if you can see this attachment. |
941 | - if (!allowedTo('view_attachments', $attachInfo['board'])) |
|
942 | - return 'attachments_not_allowed_to_see'; |
|
997 | + if (!allowedTo('view_attachments', $attachInfo['board'])) { |
|
998 | + return 'attachments_not_allowed_to_see'; |
|
999 | + } |
|
943 | 1000 | |
944 | 1001 | $allAttachments = getAttachsByMsg($attachInfo['msg']); |
945 | 1002 | $attachContext = $allAttachments[$attachInfo['msg']][$attachID]; |
946 | 1003 | |
947 | 1004 | // No point in keep going further. |
948 | - if (!allowedTo('view_attachments', $attachContext['board'])) |
|
949 | - return 'attachments_not_allowed_to_see'; |
|
1005 | + if (!allowedTo('view_attachments', $attachContext['board'])) { |
|
1006 | + return 'attachments_not_allowed_to_see'; |
|
1007 | + } |
|
950 | 1008 | |
951 | 1009 | // Load this particular attach's context. |
952 | - if (!empty($attachContext)) |
|
953 | - $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1010 | + if (!empty($attachContext)) { |
|
1011 | + $attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments); |
|
1012 | + } |
|
954 | 1013 | |
955 | 1014 | // One last check, you know, gotta be paranoid... |
956 | - else |
|
957 | - return 'attachments_no_data_loaded'; |
|
1015 | + else { |
|
1016 | + return 'attachments_no_data_loaded'; |
|
1017 | + } |
|
958 | 1018 | |
959 | 1019 | // This is the last "if" I promise! |
960 | - if (empty($attachLoaded)) |
|
961 | - return 'attachments_no_data_loaded'; |
|
962 | - |
|
963 | - else |
|
964 | - $attachContext = $attachLoaded[$attachID]; |
|
1020 | + if (empty($attachLoaded)) { |
|
1021 | + return 'attachments_no_data_loaded'; |
|
1022 | + } else { |
|
1023 | + $attachContext = $attachLoaded[$attachID]; |
|
1024 | + } |
|
965 | 1025 | |
966 | 1026 | // You may or may not want to show this under the post. |
967 | - if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) |
|
968 | - $context['show_attach_under_post'][$attachID] = $attachID; |
|
1027 | + if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) { |
|
1028 | + $context['show_attach_under_post'][$attachID] = $attachID; |
|
1029 | + } |
|
969 | 1030 | |
970 | 1031 | // Last minute changes? |
971 | 1032 | call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext)); |
@@ -985,8 +1046,9 @@ discard block |
||
985 | 1046 | { |
986 | 1047 | global $smcFunc, $modSettings; |
987 | 1048 | |
988 | - if (empty($attachIDs)) |
|
989 | - return array(); |
|
1049 | + if (empty($attachIDs)) { |
|
1050 | + return array(); |
|
1051 | + } |
|
990 | 1052 | |
991 | 1053 | $return = array(); |
992 | 1054 | |
@@ -1002,11 +1064,12 @@ discard block |
||
1002 | 1064 | ) |
1003 | 1065 | ); |
1004 | 1066 | |
1005 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1006 | - return array(); |
|
1067 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1068 | + return array(); |
|
1069 | + } |
|
1007 | 1070 | |
1008 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1009 | - $return[$row['id_attach']] = array( |
|
1071 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1072 | + $return[$row['id_attach']] = array( |
|
1010 | 1073 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
1011 | 1074 | 'size' => $row['size'], |
1012 | 1075 | 'attachID' => $row['id_attach'], |
@@ -1015,6 +1078,7 @@ discard block |
||
1015 | 1078 | 'mime_type' => $row['mime_type'], |
1016 | 1079 | 'thumb' => $row['id_thumb'], |
1017 | 1080 | ); |
1081 | + } |
|
1018 | 1082 | $smcFunc['db_free_result']($request); |
1019 | 1083 | |
1020 | 1084 | return $return; |
@@ -1031,8 +1095,9 @@ discard block |
||
1031 | 1095 | { |
1032 | 1096 | global $smcFunc; |
1033 | 1097 | |
1034 | - if (empty($attachID)) |
|
1035 | - return array(); |
|
1098 | + if (empty($attachID)) { |
|
1099 | + return array(); |
|
1100 | + } |
|
1036 | 1101 | |
1037 | 1102 | $request = $smcFunc['db_query']('', ' |
1038 | 1103 | SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board |
@@ -1045,8 +1110,9 @@ discard block |
||
1045 | 1110 | ) |
1046 | 1111 | ); |
1047 | 1112 | |
1048 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1049 | - return array(); |
|
1113 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1114 | + return array(); |
|
1115 | + } |
|
1050 | 1116 | |
1051 | 1117 | $row = $smcFunc['db_fetch_assoc']($request); |
1052 | 1118 | $smcFunc['db_free_result']($request); |
@@ -1087,8 +1153,9 @@ discard block |
||
1087 | 1153 | $temp = array(); |
1088 | 1154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1089 | 1155 | { |
1090 | - if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) |
|
1091 | - continue; |
|
1156 | + if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) { |
|
1157 | + continue; |
|
1158 | + } |
|
1092 | 1159 | |
1093 | 1160 | $temp[$row['id_attach']] = $row; |
1094 | 1161 | } |
@@ -1117,8 +1184,9 @@ discard block |
||
1117 | 1184 | { |
1118 | 1185 | global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc; |
1119 | 1186 | |
1120 | - if (empty($attachments) || empty($attachments[$id_msg])) |
|
1121 | - return array(); |
|
1187 | + if (empty($attachments) || empty($attachments[$id_msg])) { |
|
1188 | + return array(); |
|
1189 | + } |
|
1122 | 1190 | |
1123 | 1191 | // Set up the attachment info - based on code by Meriadoc. |
1124 | 1192 | $attachmentData = array(); |
@@ -1142,11 +1210,13 @@ discard block |
||
1142 | 1210 | ); |
1143 | 1211 | |
1144 | 1212 | // If something is unapproved we'll note it so we can sort them. |
1145 | - if (!$attachment['approved']) |
|
1146 | - $have_unapproved = true; |
|
1213 | + if (!$attachment['approved']) { |
|
1214 | + $have_unapproved = true; |
|
1215 | + } |
|
1147 | 1216 | |
1148 | - if (!$attachmentData[$i]['is_image']) |
|
1149 | - continue; |
|
1217 | + if (!$attachmentData[$i]['is_image']) { |
|
1218 | + continue; |
|
1219 | + } |
|
1150 | 1220 | |
1151 | 1221 | $attachmentData[$i]['real_width'] = $attachment['width']; |
1152 | 1222 | $attachmentData[$i]['width'] = $attachment['width']; |
@@ -1167,11 +1237,11 @@ discard block |
||
1167 | 1237 | // So what folder are we putting this image in? |
1168 | 1238 | if (!empty($modSettings['currentAttachmentUploadDir'])) |
1169 | 1239 | { |
1170 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
1171 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1240 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
1241 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
1242 | + } |
|
1172 | 1243 | $id_folder_thumb = $modSettings['currentAttachmentUploadDir']; |
1173 | - } |
|
1174 | - else |
|
1244 | + } else |
|
1175 | 1245 | { |
1176 | 1246 | $id_folder_thumb = 1; |
1177 | 1247 | } |
@@ -1185,10 +1255,11 @@ discard block |
||
1185 | 1255 | $thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : ''; |
1186 | 1256 | |
1187 | 1257 | // Figure out the mime type. |
1188 | - if (!empty($size['mime'])) |
|
1189 | - $thumb_mime = $size['mime']; |
|
1190 | - else |
|
1191 | - $thumb_mime = 'image/' . $thumb_ext; |
|
1258 | + if (!empty($size['mime'])) { |
|
1259 | + $thumb_mime = $size['mime']; |
|
1260 | + } else { |
|
1261 | + $thumb_mime = 'image/' . $thumb_ext; |
|
1262 | + } |
|
1192 | 1263 | |
1193 | 1264 | $thumb_filename = $attachment['filename'] . '_thumb'; |
1194 | 1265 | $thumb_hash = getAttachmentFilename($thumb_filename, false, null, true); |
@@ -1235,11 +1306,12 @@ discard block |
||
1235 | 1306 | } |
1236 | 1307 | } |
1237 | 1308 | |
1238 | - if (!empty($attachment['id_thumb'])) |
|
1239 | - $attachmentData[$i]['thumbnail'] = array( |
|
1309 | + if (!empty($attachment['id_thumb'])) { |
|
1310 | + $attachmentData[$i]['thumbnail'] = array( |
|
1240 | 1311 | 'id' => $attachment['id_thumb'], |
1241 | 1312 | 'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image', |
1242 | 1313 | ); |
1314 | + } |
|
1243 | 1315 | $attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']); |
1244 | 1316 | |
1245 | 1317 | // If thumbnails are disabled, check the maximum size of the image. |
@@ -1249,30 +1321,31 @@ discard block |
||
1249 | 1321 | { |
1250 | 1322 | $attachmentData[$i]['width'] = $modSettings['max_image_width']; |
1251 | 1323 | $attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']); |
1252 | - } |
|
1253 | - elseif (!empty($modSettings['max_image_width'])) |
|
1324 | + } elseif (!empty($modSettings['max_image_width'])) |
|
1254 | 1325 | { |
1255 | 1326 | $attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']); |
1256 | 1327 | $attachmentData[$i]['height'] = $modSettings['max_image_height']; |
1257 | 1328 | } |
1258 | - } |
|
1259 | - elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1329 | + } elseif ($attachmentData[$i]['thumbnail']['has_thumb']) |
|
1260 | 1330 | { |
1261 | 1331 | // If the image is too large to show inline, make it a popup. |
1262 | - if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) |
|
1263 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1264 | - else |
|
1265 | - $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1332 | + if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) { |
|
1333 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);'; |
|
1334 | + } else { |
|
1335 | + $attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');'; |
|
1336 | + } |
|
1266 | 1337 | } |
1267 | 1338 | |
1268 | - if (!$attachmentData[$i]['thumbnail']['has_thumb']) |
|
1269 | - $attachmentData[$i]['downloads']++; |
|
1339 | + if (!$attachmentData[$i]['thumbnail']['has_thumb']) { |
|
1340 | + $attachmentData[$i]['downloads']++; |
|
1341 | + } |
|
1270 | 1342 | } |
1271 | 1343 | } |
1272 | 1344 | |
1273 | 1345 | // Do we need to instigate a sort? |
1274 | - if ($have_unapproved) |
|
1275 | - usort($attachmentData, 'approved_attach_sort'); |
|
1346 | + if ($have_unapproved) { |
|
1347 | + usort($attachmentData, 'approved_attach_sort'); |
|
1348 | + } |
|
1276 | 1349 | |
1277 | 1350 | return $attachmentData; |
1278 | 1351 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * This is the notoriously defunct package manager..... :/. |
@@ -57,10 +58,11 @@ discard block |
||
57 | 58 | ); |
58 | 59 | |
59 | 60 | // Work out exactly who it is we are calling. |
60 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
61 | - $context['sub_action'] = $_REQUEST['sa']; |
|
62 | - else |
|
63 | - $context['sub_action'] = 'browse'; |
|
61 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
62 | + $context['sub_action'] = $_REQUEST['sa']; |
|
63 | + } else { |
|
64 | + $context['sub_action'] = 'browse'; |
|
65 | + } |
|
64 | 66 | |
65 | 67 | // Set up some tabs... |
66 | 68 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -82,8 +84,9 @@ discard block |
||
82 | 84 | ), |
83 | 85 | ); |
84 | 86 | |
85 | - if ($context['sub_action'] == 'browse') |
|
86 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
87 | + if ($context['sub_action'] == 'browse') { |
|
88 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
89 | + } |
|
87 | 90 | |
88 | 91 | call_integration_hook('integrate_manage_packages', array(&$subActions)); |
89 | 92 | |
@@ -99,8 +102,9 @@ discard block |
||
99 | 102 | global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings; |
100 | 103 | |
101 | 104 | // You have to specify a file!! |
102 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
103 | - redirectexit('action=admin;area=packages'); |
|
105 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
106 | + redirectexit('action=admin;area=packages'); |
|
107 | + } |
|
104 | 108 | $context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']); |
105 | 109 | |
106 | 110 | // Do we have an existing id, for uninstalls and the like. |
@@ -112,8 +116,9 @@ discard block |
||
112 | 116 | create_chmod_control(); |
113 | 117 | |
114 | 118 | // Make sure temp directory exists and is empty. |
115 | - if (file_exists($packagesdir . '/temp')) |
|
116 | - deltree($packagesdir . '/temp', false); |
|
119 | + if (file_exists($packagesdir . '/temp')) { |
|
120 | + deltree($packagesdir . '/temp', false); |
|
121 | + } |
|
117 | 122 | |
118 | 123 | if (!mktree($packagesdir . '/temp', 0755)) |
119 | 124 | { |
@@ -124,8 +129,9 @@ discard block |
||
124 | 129 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true)); |
125 | 130 | |
126 | 131 | deltree($packagesdir . '/temp', false); |
127 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
128 | - fatal_lang_error('package_cant_download', false); |
|
132 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
133 | + fatal_lang_error('package_cant_download', false); |
|
134 | + } |
|
129 | 135 | } |
130 | 136 | } |
131 | 137 | |
@@ -151,25 +157,26 @@ discard block |
||
151 | 157 | { |
152 | 158 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
153 | 159 | |
154 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
155 | - foreach ($context['extracted_files'] as $file) |
|
160 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
161 | + foreach ($context['extracted_files'] as $file) |
|
156 | 162 | if (basename($file['filename']) == 'package-info.xml') |
157 | 163 | { |
158 | 164 | $context['base_path'] = dirname($file['filename']) . '/'; |
165 | + } |
|
159 | 166 | break; |
160 | 167 | } |
161 | 168 | |
162 | - if (!isset($context['base_path'])) |
|
163 | - $context['base_path'] = ''; |
|
164 | - } |
|
165 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
169 | + if (!isset($context['base_path'])) { |
|
170 | + $context['base_path'] = ''; |
|
171 | + } |
|
172 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
166 | 173 | { |
167 | 174 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
168 | 175 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
169 | 176 | $context['base_path'] = ''; |
177 | + } else { |
|
178 | + fatal_lang_error('no_access', false); |
|
170 | 179 | } |
171 | - else |
|
172 | - fatal_lang_error('no_access', false); |
|
173 | 180 | |
174 | 181 | // Load up any custom themes we may want to install into... |
175 | 182 | $request = $smcFunc['db_query']('', ' |
@@ -185,15 +192,17 @@ discard block |
||
185 | 192 | ) |
186 | 193 | ); |
187 | 194 | $theme_paths = array(); |
188 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
189 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
195 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
196 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
197 | + } |
|
190 | 198 | $smcFunc['db_free_result']($request); |
191 | 199 | |
192 | 200 | // Get the package info... |
193 | 201 | $packageInfo = getPackageInfo($context['filename']); |
194 | 202 | |
195 | - if (!is_array($packageInfo)) |
|
196 | - fatal_lang_error($packageInfo); |
|
203 | + if (!is_array($packageInfo)) { |
|
204 | + fatal_lang_error($packageInfo); |
|
205 | + } |
|
197 | 206 | |
198 | 207 | $packageInfo['filename'] = $context['filename']; |
199 | 208 | $context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename']; |
@@ -227,18 +236,19 @@ discard block |
||
227 | 236 | $smcFunc['db_free_result']($request); |
228 | 237 | |
229 | 238 | $context['database_changes'] = array(); |
230 | - if (isset($packageInfo['uninstall']['database'])) |
|
231 | - $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
232 | - elseif (!empty($db_changes)) |
|
239 | + if (isset($packageInfo['uninstall']['database'])) { |
|
240 | + $context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database']; |
|
241 | + } elseif (!empty($db_changes)) |
|
233 | 242 | { |
234 | 243 | foreach ($db_changes as $change) |
235 | 244 | { |
236 | - if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) |
|
237 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
238 | - elseif (isset($txt['package_db_' . $change[0]])) |
|
239 | - $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
240 | - else |
|
241 | - $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
245 | + if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) { |
|
246 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]); |
|
247 | + } elseif (isset($txt['package_db_' . $change[0]])) { |
|
248 | + $context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]); |
|
249 | + } else { |
|
250 | + $context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : ''); |
|
251 | + } |
|
242 | 252 | } |
243 | 253 | } |
244 | 254 | |
@@ -265,31 +275,33 @@ discard block |
||
265 | 275 | $context['themes_locked'] = true; |
266 | 276 | |
267 | 277 | // Only let them uninstall themes it was installed into. |
268 | - foreach ($theme_paths as $id => $data) |
|
269 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
278 | + foreach ($theme_paths as $id => $data) { |
|
279 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
270 | 280 | unset($theme_paths[$id]); |
271 | - } |
|
272 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
281 | + } |
|
282 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
273 | 283 | { |
274 | 284 | // Look for an upgrade... |
275 | 285 | $actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version); |
276 | 286 | |
277 | 287 | // There was no upgrade.... |
278 | - if (empty($actions)) |
|
279 | - $context['is_installed'] = true; |
|
280 | - else |
|
288 | + if (empty($actions)) { |
|
289 | + $context['is_installed'] = true; |
|
290 | + } else |
|
281 | 291 | { |
282 | 292 | // Otherwise they can only upgrade themes from the first time around. |
283 | - foreach ($theme_paths as $id => $data) |
|
284 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
293 | + foreach ($theme_paths as $id => $data) { |
|
294 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
285 | 295 | unset($theme_paths[$id]); |
296 | + } |
|
286 | 297 | } |
298 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
299 | + $context['is_installed'] = true; |
|
287 | 300 | } |
288 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
289 | - $context['is_installed'] = true; |
|
290 | 301 | |
291 | - if (!isset($old_version) || $context['is_installed']) |
|
292 | - $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
302 | + if (!isset($old_version) || $context['is_installed']) { |
|
303 | + $actions = parsePackageInfo($packageInfo['xml'], true, 'install'); |
|
304 | + } |
|
293 | 305 | |
294 | 306 | $context['actions'] = array(); |
295 | 307 | $context['ftp_needed'] = false; |
@@ -297,8 +309,9 @@ discard block |
||
297 | 309 | $chmod_files = array(); |
298 | 310 | |
299 | 311 | // no actions found, return so we can display an error |
300 | - if (empty($actions)) |
|
301 | - return; |
|
312 | + if (empty($actions)) { |
|
313 | + return; |
|
314 | + } |
|
302 | 315 | |
303 | 316 | // This will hold data about anything that can be installed in other themes. |
304 | 317 | $themeFinds = array( |
@@ -317,14 +330,14 @@ discard block |
||
317 | 330 | { |
318 | 331 | $chmod_files[] = $action['filename']; |
319 | 332 | continue; |
320 | - } |
|
321 | - elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
333 | + } elseif ($action['type'] == 'readme' || $action['type'] == 'license') |
|
322 | 334 | { |
323 | 335 | $type = 'package_' . $action['type']; |
324 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
325 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
326 | - elseif (file_exists($action['filename'])) |
|
327 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
336 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
337 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r")); |
|
338 | + } elseif (file_exists($action['filename'])) { |
|
339 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
340 | + } |
|
328 | 341 | |
329 | 342 | if (!empty($action['parse_bbc'])) |
330 | 343 | { |
@@ -332,24 +345,24 @@ discard block |
||
332 | 345 | $context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]); |
333 | 346 | preparsecode($context[$type]); |
334 | 347 | $context[$type] = parse_bbc($context[$type]); |
348 | + } else { |
|
349 | + $context[$type] = nl2br($context[$type]); |
|
335 | 350 | } |
336 | - else |
|
337 | - $context[$type] = nl2br($context[$type]); |
|
338 | 351 | |
339 | 352 | continue; |
340 | 353 | } |
341 | 354 | // Don't show redirects. |
342 | - elseif ($action['type'] == 'redirect') |
|
343 | - continue; |
|
344 | - elseif ($action['type'] == 'error') |
|
355 | + elseif ($action['type'] == 'redirect') { |
|
356 | + continue; |
|
357 | + } elseif ($action['type'] == 'error') |
|
345 | 358 | { |
346 | 359 | $context['has_failure'] = true; |
347 | - if (isset($action['error_msg']) && isset($action['error_var'])) |
|
348 | - $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
349 | - elseif (isset($action['error_msg'])) |
|
350 | - $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
351 | - } |
|
352 | - elseif ($action['type'] == 'modification') |
|
360 | + if (isset($action['error_msg']) && isset($action['error_var'])) { |
|
361 | + $context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']); |
|
362 | + } elseif (isset($action['error_msg'])) { |
|
363 | + $context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg']; |
|
364 | + } |
|
365 | + } elseif ($action['type'] == 'modification') |
|
353 | 366 | { |
354 | 367 | if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
355 | 368 | { |
@@ -361,52 +374,54 @@ discard block |
||
361 | 374 | 'description' => $txt['package_action_missing'], |
362 | 375 | 'failed' => true, |
363 | 376 | ); |
364 | - } |
|
365 | - else |
|
377 | + } else |
|
366 | 378 | { |
367 | 379 | |
368 | - if ($action['boardmod']) |
|
369 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
370 | - else |
|
371 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
380 | + if ($action['boardmod']) { |
|
381 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
382 | + } else { |
|
383 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths); |
|
384 | + } |
|
372 | 385 | |
373 | - if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') |
|
374 | - $mod_actions[0]['filename'] = $action['filename']; |
|
386 | + if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') { |
|
387 | + $mod_actions[0]['filename'] = $action['filename']; |
|
388 | + } |
|
375 | 389 | |
376 | 390 | foreach ($mod_actions as $key => $mod_action) |
377 | 391 | { |
378 | 392 | // Lets get the last section of the file name. |
379 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
380 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
381 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
382 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
383 | - else |
|
384 | - $actual_filename = $key; |
|
385 | - |
|
386 | - if ($mod_action['type'] == 'opened') |
|
387 | - $failed = false; |
|
388 | - elseif ($mod_action['type'] == 'failure') |
|
393 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
394 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
395 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
396 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
397 | + } else { |
|
398 | + $actual_filename = $key; |
|
399 | + } |
|
400 | + |
|
401 | + if ($mod_action['type'] == 'opened') { |
|
402 | + $failed = false; |
|
403 | + } elseif ($mod_action['type'] == 'failure') |
|
389 | 404 | { |
390 | - if (empty($mod_action['is_custom'])) |
|
391 | - $context['has_failure'] = true; |
|
405 | + if (empty($mod_action['is_custom'])) { |
|
406 | + $context['has_failure'] = true; |
|
407 | + } |
|
392 | 408 | $failed = true; |
393 | - } |
|
394 | - elseif ($mod_action['type'] == 'chmod') |
|
409 | + } elseif ($mod_action['type'] == 'chmod') |
|
395 | 410 | { |
396 | 411 | $chmod_files[] = $mod_action['filename']; |
397 | - } |
|
398 | - elseif ($mod_action['type'] == 'saved') |
|
412 | + } elseif ($mod_action['type'] == 'saved') |
|
399 | 413 | { |
400 | 414 | if (!empty($mod_action['is_custom'])) |
401 | 415 | { |
402 | - if (!isset($context['theme_actions'][$mod_action['is_custom']])) |
|
403 | - $context['theme_actions'][$mod_action['is_custom']] = array( |
|
416 | + if (!isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
417 | + $context['theme_actions'][$mod_action['is_custom']] = array( |
|
404 | 418 | 'name' => $theme_paths[$mod_action['is_custom']]['name'], |
405 | 419 | 'actions' => array(), |
406 | 420 | 'has_failure' => $failed, |
407 | 421 | ); |
408 | - else |
|
409 | - $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
422 | + } else { |
|
423 | + $context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed; |
|
424 | + } |
|
410 | 425 | |
411 | 426 | $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array( |
412 | 427 | 'type' => $txt['execute_modification'], |
@@ -414,8 +429,7 @@ discard block |
||
414 | 429 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
415 | 430 | 'failed' => $failed, |
416 | 431 | ); |
417 | - } |
|
418 | - elseif (!isset($context['actions'][$actual_filename])) |
|
432 | + } elseif (!isset($context['actions'][$actual_filename])) |
|
419 | 433 | { |
420 | 434 | $context['actions'][$actual_filename] = array( |
421 | 435 | 'type' => $txt['execute_modification'], |
@@ -423,22 +437,19 @@ discard block |
||
423 | 437 | 'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'], |
424 | 438 | 'failed' => $failed, |
425 | 439 | ); |
426 | - } |
|
427 | - else |
|
440 | + } else |
|
428 | 441 | { |
429 | 442 | $context['actions'][$actual_filename]['failed'] |= $failed; |
430 | 443 | $context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success']; |
431 | 444 | } |
432 | - } |
|
433 | - elseif ($mod_action['type'] == 'skipping') |
|
445 | + } elseif ($mod_action['type'] == 'skipping') |
|
434 | 446 | { |
435 | 447 | $context['actions'][$actual_filename] = array( |
436 | 448 | 'type' => $txt['execute_modification'], |
437 | 449 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
438 | 450 | 'description' => $txt['package_action_skipping'] |
439 | 451 | ); |
440 | - } |
|
441 | - elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
452 | + } elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom'])) |
|
442 | 453 | { |
443 | 454 | $context['has_failure'] = true; |
444 | 455 | $context['actions'][$actual_filename] = array( |
@@ -447,32 +458,33 @@ discard block |
||
447 | 458 | 'description' => $txt['package_action_missing'], |
448 | 459 | 'failed' => true, |
449 | 460 | ); |
450 | - } |
|
451 | - elseif ($mod_action['type'] == 'error') |
|
452 | - $context['actions'][$actual_filename] = array( |
|
461 | + } elseif ($mod_action['type'] == 'error') { |
|
462 | + $context['actions'][$actual_filename] = array( |
|
453 | 463 | 'type' => $txt['execute_modification'], |
454 | 464 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
455 | 465 | 'description' => $txt['package_action_error'], |
456 | 466 | 'failed' => true, |
457 | 467 | ); |
468 | + } |
|
458 | 469 | } |
459 | 470 | |
460 | 471 | // We need to loop again just to get the operations down correctly. |
461 | 472 | foreach ($mod_actions as $operation_key => $mod_action) |
462 | 473 | { |
463 | 474 | // Lets get the last section of the file name. |
464 | - if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') |
|
465 | - $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
466 | - elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) |
|
467 | - $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
468 | - else |
|
469 | - $actual_filename = $key; |
|
475 | + if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') { |
|
476 | + $actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']); |
|
477 | + } elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) { |
|
478 | + $actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']); |
|
479 | + } else { |
|
480 | + $actual_filename = $key; |
|
481 | + } |
|
470 | 482 | |
471 | 483 | // We just need it for actual parse changes. |
472 | 484 | if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod'))) |
473 | 485 | { |
474 | - if (empty($mod_action['is_custom'])) |
|
475 | - $context['actions'][$actual_filename]['operations'][] = array( |
|
486 | + if (empty($mod_action['is_custom'])) { |
|
487 | + $context['actions'][$actual_filename]['operations'][] = array( |
|
476 | 488 | 'type' => $txt['execute_modification'], |
477 | 489 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
478 | 490 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -483,10 +495,11 @@ discard block |
||
483 | 495 | 'failed' => $mod_action['failed'], |
484 | 496 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
485 | 497 | ); |
498 | + } |
|
486 | 499 | |
487 | 500 | // Themes are under the saved type. |
488 | - if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) |
|
489 | - $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
501 | + if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) { |
|
502 | + $context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array( |
|
490 | 503 | 'type' => $txt['execute_modification'], |
491 | 504 | 'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))), |
492 | 505 | 'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'], |
@@ -497,59 +510,55 @@ discard block |
||
497 | 510 | 'failed' => $mod_action['failed'], |
498 | 511 | 'ignore_failure' => !empty($mod_action['ignore_failure']), |
499 | 512 | ); |
513 | + } |
|
500 | 514 | } |
501 | 515 | } |
502 | 516 | } |
503 | - } |
|
504 | - elseif ($action['type'] == 'code') |
|
517 | + } elseif ($action['type'] == 'code') |
|
505 | 518 | { |
506 | 519 | $thisAction = array( |
507 | 520 | 'type' => $txt['execute_code'], |
508 | 521 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
509 | 522 | ); |
510 | - } |
|
511 | - elseif ($action['type'] == 'database') |
|
523 | + } elseif ($action['type'] == 'database') |
|
512 | 524 | { |
513 | 525 | $thisAction = array( |
514 | 526 | 'type' => $txt['execute_database_changes'], |
515 | 527 | 'action' => $smcFunc['htmlspecialchars']($action['filename']), |
516 | 528 | ); |
517 | - } |
|
518 | - elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
529 | + } elseif (in_array($action['type'], array('create-dir', 'create-file'))) |
|
519 | 530 | { |
520 | 531 | $thisAction = array( |
521 | 532 | 'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']), |
522 | 533 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
523 | 534 | ); |
524 | - } |
|
525 | - elseif ($action['type'] == 'hook') |
|
535 | + } elseif ($action['type'] == 'hook') |
|
526 | 536 | { |
527 | 537 | $action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success']; |
528 | 538 | |
529 | - if (!isset($action['hook'], $action['function'])) |
|
530 | - $context['has_failure'] = true; |
|
539 | + if (!isset($action['hook'], $action['function'])) { |
|
540 | + $context['has_failure'] = true; |
|
541 | + } |
|
531 | 542 | |
532 | 543 | $thisAction = array( |
533 | 544 | 'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'], |
534 | 545 | 'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])), |
535 | 546 | ); |
536 | - } |
|
537 | - elseif ($action['type'] == 'credits') |
|
547 | + } elseif ($action['type'] == 'credits') |
|
538 | 548 | { |
539 | 549 | $thisAction = array( |
540 | 550 | 'type' => $txt['execute_credits_add'], |
541 | 551 | 'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])), |
542 | 552 | ); |
543 | - } |
|
544 | - elseif ($action['type'] == 'requires') |
|
553 | + } elseif ($action['type'] == 'requires') |
|
545 | 554 | { |
546 | 555 | $installed = false; |
547 | 556 | $version = true; |
548 | 557 | |
549 | 558 | // package missing required values? |
550 | - if (!isset($action['id'])) |
|
551 | - $context['has_failure'] = true; |
|
552 | - else |
|
559 | + if (!isset($action['id'])) { |
|
560 | + $context['has_failure'] = true; |
|
561 | + } else |
|
553 | 562 | { |
554 | 563 | // See if this dependancy is installed |
555 | 564 | $request = $smcFunc['db_query']('', ' |
@@ -565,8 +574,9 @@ discard block |
||
565 | 574 | ) |
566 | 575 | ); |
567 | 576 | $installed = ($smcFunc['db_num_rows']($request) !== 0); |
568 | - if ($installed) |
|
569 | - list ($version) = $smcFunc['db_fetch_row']($request); |
|
577 | + if ($installed) { |
|
578 | + list ($version) = $smcFunc['db_fetch_row']($request); |
|
579 | + } |
|
570 | 580 | $smcFunc['db_free_result']($request); |
571 | 581 | |
572 | 582 | // do a version level check (if requested) in the most basic way |
@@ -581,8 +591,7 @@ discard block |
||
581 | 591 | 'type' => $txt['package_requires'], |
582 | 592 | 'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''), |
583 | 593 | ); |
584 | - } |
|
585 | - elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
594 | + } elseif (in_array($action['type'], array('require-dir', 'require-file'))) |
|
586 | 595 | { |
587 | 596 | // Do this one... |
588 | 597 | $thisAction = array( |
@@ -596,26 +605,29 @@ discard block |
||
596 | 605 | // Is the action already stated? |
597 | 606 | $theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto'; |
598 | 607 | // If it's not auto do we think we have something we can act upon? |
599 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
600 | - $theme_action = ''; |
|
608 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
609 | + $theme_action = ''; |
|
610 | + } |
|
601 | 611 | // ... or if it's auto do we even want to do anything? |
602 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
603 | - $theme_action = ''; |
|
612 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
613 | + $theme_action = ''; |
|
614 | + } |
|
604 | 615 | |
605 | 616 | // So, we still want to do something? |
606 | - if ($theme_action != '') |
|
607 | - $themeFinds['candidates'][] = $action; |
|
617 | + if ($theme_action != '') { |
|
618 | + $themeFinds['candidates'][] = $action; |
|
619 | + } |
|
608 | 620 | // Otherwise is this is going into another theme record it. |
609 | - elseif ($matches[1] == 'themes_dir') |
|
610 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
621 | + elseif ($matches[1] == 'themes_dir') { |
|
622 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
623 | + } |
|
611 | 624 | } |
612 | - } |
|
613 | - elseif (in_array($action['type'], array('move-dir', 'move-file'))) |
|
614 | - $thisAction = array( |
|
625 | + } elseif (in_array($action['type'], array('move-dir', 'move-file'))) { |
|
626 | + $thisAction = array( |
|
615 | 627 | 'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']), |
616 | 628 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
617 | 629 | ); |
618 | - elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
630 | + } elseif (in_array($action['type'], array('remove-dir', 'remove-file'))) |
|
619 | 631 | { |
620 | 632 | $thisAction = array( |
621 | 633 | 'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']), |
@@ -631,30 +643,36 @@ discard block |
||
631 | 643 | $action['unparsed_destination'] = $action['unparsed_filename']; |
632 | 644 | |
633 | 645 | // If it's not auto do we think we have something we can act upon? |
634 | - if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) |
|
635 | - $theme_action = ''; |
|
646 | + if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) { |
|
647 | + $theme_action = ''; |
|
648 | + } |
|
636 | 649 | // ... or if it's auto do we even want to do anything? |
637 | - elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') |
|
638 | - $theme_action = ''; |
|
650 | + elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') { |
|
651 | + $theme_action = ''; |
|
652 | + } |
|
639 | 653 | |
640 | 654 | // So, we still want to do something? |
641 | - if ($theme_action != '') |
|
642 | - $themeFinds['candidates'][] = $action; |
|
655 | + if ($theme_action != '') { |
|
656 | + $themeFinds['candidates'][] = $action; |
|
657 | + } |
|
643 | 658 | // Otherwise is this is going into another theme record it. |
644 | - elseif ($matches[1] == 'themes_dir') |
|
645 | - $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
659 | + elseif ($matches[1] == 'themes_dir') { |
|
660 | + $themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename'])); |
|
661 | + } |
|
646 | 662 | } |
647 | 663 | } |
648 | 664 | |
649 | - if (empty($thisAction)) |
|
650 | - continue; |
|
665 | + if (empty($thisAction)) { |
|
666 | + continue; |
|
667 | + } |
|
651 | 668 | |
652 | 669 | if (!in_array($action['type'], array('hook', 'credits'))) |
653 | 670 | { |
654 | - if ($context['uninstalling']) |
|
655 | - $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
656 | - else |
|
657 | - $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
671 | + if ($context['uninstalling']) { |
|
672 | + $file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
673 | + } else { |
|
674 | + $file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename']; |
|
675 | + } |
|
658 | 676 | } |
659 | 677 | |
660 | 678 | // Don't fail if a file/directory we're trying to create doesn't exist... |
@@ -669,8 +687,9 @@ discard block |
||
669 | 687 | } |
670 | 688 | |
671 | 689 | // @todo None given? |
672 | - if (empty($thisAction['description'])) |
|
673 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
690 | + if (empty($thisAction['description'])) { |
|
691 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
692 | + } |
|
674 | 693 | |
675 | 694 | $context['actions'][] = $thisAction; |
676 | 695 | } |
@@ -683,18 +702,21 @@ discard block |
||
683 | 702 | // Get the part of the file we'll be dealing with. |
684 | 703 | preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches); |
685 | 704 | |
686 | - if ($matches[1] == 'imagesdir') |
|
687 | - $path = '/' . basename($settings['default_images_url']); |
|
688 | - elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') |
|
689 | - $path = '/languages'; |
|
690 | - else |
|
691 | - $path = ''; |
|
705 | + if ($matches[1] == 'imagesdir') { |
|
706 | + $path = '/' . basename($settings['default_images_url']); |
|
707 | + } elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') { |
|
708 | + $path = '/languages'; |
|
709 | + } else { |
|
710 | + $path = ''; |
|
711 | + } |
|
692 | 712 | |
693 | - if (!empty($matches[3])) |
|
694 | - $path .= $matches[3]; |
|
713 | + if (!empty($matches[3])) { |
|
714 | + $path .= $matches[3]; |
|
715 | + } |
|
695 | 716 | |
696 | - if (!$context['uninstalling']) |
|
697 | - $path .= '/' . basename($action_data['filename']); |
|
717 | + if (!$context['uninstalling']) { |
|
718 | + $path .= '/' . basename($action_data['filename']); |
|
719 | + } |
|
698 | 720 | |
699 | 721 | // Loop through each custom theme to note it's candidacy! |
700 | 722 | foreach ($theme_paths as $id => $theme_data) |
@@ -710,36 +732,40 @@ discard block |
||
710 | 732 | if (!mktree(dirname($real_path), false)) |
711 | 733 | { |
712 | 734 | $temp = dirname($real_path); |
713 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
714 | - $temp = dirname($temp); |
|
735 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
736 | + $temp = dirname($temp); |
|
737 | + } |
|
715 | 738 | $chmod_files[] = $temp; |
716 | 739 | } |
717 | 740 | |
718 | - if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) |
|
719 | - $chmod_files[] = $real_path; |
|
741 | + if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) { |
|
742 | + $chmod_files[] = $real_path; |
|
743 | + } |
|
720 | 744 | |
721 | - if (!isset($context['theme_actions'][$id])) |
|
722 | - $context['theme_actions'][$id] = array( |
|
745 | + if (!isset($context['theme_actions'][$id])) { |
|
746 | + $context['theme_actions'][$id] = array( |
|
723 | 747 | 'name' => $theme_data['name'], |
724 | 748 | 'actions' => array(), |
725 | 749 | ); |
750 | + } |
|
726 | 751 | |
727 | - if ($context['uninstalling']) |
|
728 | - $context['theme_actions'][$id]['actions'][] = array( |
|
752 | + if ($context['uninstalling']) { |
|
753 | + $context['theme_actions'][$id]['actions'][] = array( |
|
729 | 754 | 'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
730 | 755 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
731 | 756 | 'description' => '', |
732 | 757 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))), |
733 | 758 | 'not_mod' => true, |
734 | 759 | ); |
735 | - else |
|
736 | - $context['theme_actions'][$id]['actions'][] = array( |
|
760 | + } else { |
|
761 | + $context['theme_actions'][$id]['actions'][] = array( |
|
737 | 762 | 'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']), |
738 | 763 | 'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')), |
739 | 764 | 'description' => '', |
740 | 765 | 'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))), |
741 | 766 | 'not_mod' => true, |
742 | 767 | ); |
768 | + } |
|
743 | 769 | } |
744 | 770 | } |
745 | 771 | } |
@@ -749,8 +775,9 @@ discard block |
||
749 | 775 | // Trash the cache... which will also check permissions for us! |
750 | 776 | package_flush_cache(true); |
751 | 777 | |
752 | - if (file_exists($packagesdir . '/temp')) |
|
753 | - deltree($packagesdir . '/temp'); |
|
778 | + if (file_exists($packagesdir . '/temp')) { |
|
779 | + deltree($packagesdir . '/temp'); |
|
780 | + } |
|
754 | 781 | |
755 | 782 | if (!empty($chmod_files)) |
756 | 783 | { |
@@ -775,8 +802,9 @@ discard block |
||
775 | 802 | checkSession(); |
776 | 803 | |
777 | 804 | // If there's no file, what are we installing? |
778 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
779 | - redirectexit('action=admin;area=packages'); |
|
805 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
806 | + redirectexit('action=admin;area=packages'); |
|
807 | + } |
|
780 | 808 | $context['filename'] = $_REQUEST['package']; |
781 | 809 | |
782 | 810 | // If this is an uninstall, we'll have an id. |
@@ -797,51 +825,55 @@ discard block |
||
797 | 825 | |
798 | 826 | $context['sub_template'] = 'extract_package'; |
799 | 827 | |
800 | - if (!file_exists($packagesdir . '/' . $context['filename'])) |
|
801 | - fatal_lang_error('package_no_file', false); |
|
828 | + if (!file_exists($packagesdir . '/' . $context['filename'])) { |
|
829 | + fatal_lang_error('package_no_file', false); |
|
830 | + } |
|
802 | 831 | |
803 | 832 | // Load up the package FTP information? |
804 | 833 | create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'])); |
805 | 834 | |
806 | 835 | // Make sure temp directory exists and is empty! |
807 | - if (file_exists($packagesdir . '/temp')) |
|
808 | - deltree($packagesdir . '/temp', false); |
|
809 | - else |
|
810 | - mktree($packagesdir . '/temp', 0777); |
|
836 | + if (file_exists($packagesdir . '/temp')) { |
|
837 | + deltree($packagesdir . '/temp', false); |
|
838 | + } else { |
|
839 | + mktree($packagesdir . '/temp', 0777); |
|
840 | + } |
|
811 | 841 | |
812 | 842 | // Let the unpacker do the work. |
813 | 843 | if (is_file($packagesdir . '/' . $context['filename'])) |
814 | 844 | { |
815 | 845 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
816 | 846 | |
817 | - if (!file_exists($packagesdir . '/temp/package-info.xml')) |
|
818 | - foreach ($context['extracted_files'] as $file) |
|
847 | + if (!file_exists($packagesdir . '/temp/package-info.xml')) { |
|
848 | + foreach ($context['extracted_files'] as $file) |
|
819 | 849 | if (basename($file['filename']) == 'package-info.xml') |
820 | 850 | { |
821 | 851 | $context['base_path'] = dirname($file['filename']) . '/'; |
852 | + } |
|
822 | 853 | break; |
823 | 854 | } |
824 | 855 | |
825 | - if (!isset($context['base_path'])) |
|
826 | - $context['base_path'] = ''; |
|
827 | - } |
|
828 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
856 | + if (!isset($context['base_path'])) { |
|
857 | + $context['base_path'] = ''; |
|
858 | + } |
|
859 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
829 | 860 | { |
830 | 861 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
831 | 862 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
832 | 863 | $context['base_path'] = ''; |
864 | + } else { |
|
865 | + fatal_lang_error('no_access', false); |
|
833 | 866 | } |
834 | - else |
|
835 | - fatal_lang_error('no_access', false); |
|
836 | 867 | |
837 | 868 | // Are we installing this into any custom themes? |
838 | 869 | $custom_themes = array(1); |
839 | 870 | $known_themes = explode(',', $modSettings['knownThemes']); |
840 | 871 | if (!empty($_POST['custom_theme'])) |
841 | 872 | { |
842 | - foreach ($_POST['custom_theme'] as $tid) |
|
843 | - if (in_array($tid, $known_themes)) |
|
873 | + foreach ($_POST['custom_theme'] as $tid) { |
|
874 | + if (in_array($tid, $known_themes)) |
|
844 | 875 | $custom_themes[] = (int) $tid; |
876 | + } |
|
845 | 877 | } |
846 | 878 | |
847 | 879 | // Now load up the paths of the themes that we need to know about. |
@@ -858,8 +890,9 @@ discard block |
||
858 | 890 | ); |
859 | 891 | $theme_paths = array(); |
860 | 892 | $themes_installed = array(1); |
861 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
862 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
893 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
894 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
895 | + } |
|
863 | 896 | $smcFunc['db_free_result']($request); |
864 | 897 | |
865 | 898 | // Are there any theme copying that we want to take place? |
@@ -871,11 +904,13 @@ discard block |
||
871 | 904 | { |
872 | 905 | foreach ($_POST['theme_changes'] as $change) |
873 | 906 | { |
874 | - if (empty($change)) |
|
875 | - continue; |
|
907 | + if (empty($change)) { |
|
908 | + continue; |
|
909 | + } |
|
876 | 910 | $theme_data = smf_json_decode(base64_decode($change), true); |
877 | - if (empty($theme_data['type'])) |
|
878 | - continue; |
|
911 | + if (empty($theme_data['type'])) { |
|
912 | + continue; |
|
913 | + } |
|
879 | 914 | |
880 | 915 | $themes_installed[] = $theme_data['id']; |
881 | 916 | $context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future']; |
@@ -884,8 +919,9 @@ discard block |
||
884 | 919 | |
885 | 920 | // Get the package info... |
886 | 921 | $packageInfo = getPackageInfo($context['filename']); |
887 | - if (!is_array($packageInfo)) |
|
888 | - fatal_lang_error($packageInfo); |
|
922 | + if (!is_array($packageInfo)) { |
|
923 | + fatal_lang_error($packageInfo); |
|
924 | + } |
|
889 | 925 | |
890 | 926 | $packageInfo['filename'] = $context['filename']; |
891 | 927 | |
@@ -897,8 +933,9 @@ discard block |
||
897 | 933 | { |
898 | 934 | $_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$'); |
899 | 935 | $result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.')); |
900 | - if (!$result) |
|
901 | - fatal_lang_error('could_not_package_backup', false); |
|
936 | + if (!$result) { |
|
937 | + fatal_lang_error('could_not_package_backup', false); |
|
938 | + } |
|
902 | 939 | } |
903 | 940 | |
904 | 941 | // The mod isn't installed.... unless proven otherwise. |
@@ -938,35 +975,38 @@ discard block |
||
938 | 975 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall'); |
939 | 976 | |
940 | 977 | // Gadzooks! There's no uninstaller at all!? |
941 | - if (empty($install_log)) |
|
942 | - fatal_lang_error('package_uninstall_cannot', false); |
|
978 | + if (empty($install_log)) { |
|
979 | + fatal_lang_error('package_uninstall_cannot', false); |
|
980 | + } |
|
943 | 981 | |
944 | 982 | // They can only uninstall from what it was originally installed into. |
945 | - foreach ($theme_paths as $id => $data) |
|
946 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
983 | + foreach ($theme_paths as $id => $data) { |
|
984 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
947 | 985 | unset($theme_paths[$id]); |
948 | - } |
|
949 | - elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
986 | + } |
|
987 | + } elseif (isset($old_version) && $old_version != $packageInfo['version']) |
|
950 | 988 | { |
951 | 989 | // Look for an upgrade... |
952 | 990 | $install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version); |
953 | 991 | |
954 | 992 | // There was no upgrade.... |
955 | - if (empty($install_log)) |
|
956 | - $context['is_installed'] = true; |
|
957 | - else |
|
993 | + if (empty($install_log)) { |
|
994 | + $context['is_installed'] = true; |
|
995 | + } else |
|
958 | 996 | { |
959 | 997 | // Upgrade previous themes only! |
960 | - foreach ($theme_paths as $id => $data) |
|
961 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
998 | + foreach ($theme_paths as $id => $data) { |
|
999 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
962 | 1000 | unset($theme_paths[$id]); |
1001 | + } |
|
963 | 1002 | } |
1003 | + } elseif (isset($old_version) && $old_version == $packageInfo['version']) { |
|
1004 | + $context['is_installed'] = true; |
|
964 | 1005 | } |
965 | - elseif (isset($old_version) && $old_version == $packageInfo['version']) |
|
966 | - $context['is_installed'] = true; |
|
967 | 1006 | |
968 | - if (!isset($old_version) || $context['is_installed']) |
|
969 | - $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1007 | + if (!isset($old_version) || $context['is_installed']) { |
|
1008 | + $install_log = parsePackageInfo($packageInfo['xml'], false, 'install'); |
|
1009 | + } |
|
970 | 1010 | |
971 | 1011 | $context['install_finished'] = false; |
972 | 1012 | |
@@ -983,37 +1023,39 @@ discard block |
||
983 | 1023 | |
984 | 1024 | if ($action['type'] == 'modification' && !empty($action['filename'])) |
985 | 1025 | { |
986 | - if ($action['boardmod']) |
|
987 | - $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
988 | - else |
|
989 | - $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1026 | + if ($action['boardmod']) { |
|
1027 | + $mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1028 | + } else { |
|
1029 | + $mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths); |
|
1030 | + } |
|
990 | 1031 | |
991 | 1032 | // Any errors worth noting? |
992 | 1033 | foreach ($mod_actions as $key => $modAction) |
993 | 1034 | { |
994 | - if ($modAction['type'] == 'failure') |
|
995 | - $failed_steps[] = array( |
|
1035 | + if ($modAction['type'] == 'failure') { |
|
1036 | + $failed_steps[] = array( |
|
996 | 1037 | 'file' => $modAction['filename'], |
997 | 1038 | 'large_step' => $failed_count, |
998 | 1039 | 'sub_step' => $key, |
999 | 1040 | 'theme' => 1, |
1000 | 1041 | ); |
1042 | + } |
|
1001 | 1043 | |
1002 | 1044 | // Gather the themes we installed into. |
1003 | - if (!empty($modAction['is_custom'])) |
|
1004 | - $themes_installed[] = $modAction['is_custom']; |
|
1045 | + if (!empty($modAction['is_custom'])) { |
|
1046 | + $themes_installed[] = $modAction['is_custom']; |
|
1047 | + } |
|
1005 | 1048 | } |
1006 | - } |
|
1007 | - elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1049 | + } elseif ($action['type'] == 'code' && !empty($action['filename'])) |
|
1008 | 1050 | { |
1009 | 1051 | // This is just here as reference for what is available. |
1010 | 1052 | global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc; |
1011 | 1053 | |
1012 | 1054 | // Now include the file and be done with it ;). |
1013 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1014 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1015 | - } |
|
1016 | - elseif ($action['type'] == 'credits') |
|
1055 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1056 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1057 | + } |
|
1058 | + } elseif ($action['type'] == 'credits') |
|
1017 | 1059 | { |
1018 | 1060 | // Time to build the billboard |
1019 | 1061 | $credits_tag = array( |
@@ -1023,13 +1065,13 @@ discard block |
||
1023 | 1065 | 'copyright' => $action['copyright'], |
1024 | 1066 | 'title' => $action['title'], |
1025 | 1067 | ); |
1026 | - } |
|
1027 | - elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1068 | + } elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function'])) |
|
1028 | 1069 | { |
1029 | - if ($action['reverse']) |
|
1030 | - remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1031 | - else |
|
1032 | - add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1070 | + if ($action['reverse']) { |
|
1071 | + remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1072 | + } else { |
|
1073 | + add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']); |
|
1074 | + } |
|
1033 | 1075 | } |
1034 | 1076 | // Only do the database changes on uninstall if requested. |
1035 | 1077 | elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes']))) |
@@ -1042,8 +1084,9 @@ discard block |
||
1042 | 1084 | db_extend('packages'); |
1043 | 1085 | |
1044 | 1086 | // Let the file work its magic ;) |
1045 | - if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) |
|
1046 | - require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1087 | + if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) { |
|
1088 | + require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']); |
|
1089 | + } |
|
1047 | 1090 | } |
1048 | 1091 | // Handle a redirect... |
1049 | 1092 | elseif ($action['type'] == 'redirect' && !empty($action['redirect_url'])) |
@@ -1125,8 +1168,9 @@ discard block |
||
1125 | 1168 | reloadSettings(); |
1126 | 1169 | |
1127 | 1170 | // Any db changes from older version? |
1128 | - if (!empty($old_db_changes)) |
|
1129 | - $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1171 | + if (!empty($old_db_changes)) { |
|
1172 | + $db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log); |
|
1173 | + } |
|
1130 | 1174 | |
1131 | 1175 | // If there are some database changes we might want to remove then filter them out. |
1132 | 1176 | if (!empty($db_package_log)) |
@@ -1142,22 +1186,24 @@ discard block |
||
1142 | 1186 | */ |
1143 | 1187 | function sort_table_first($a, $b) |
1144 | 1188 | { |
1145 | - if ($a[0] == $b[0]) |
|
1146 | - return 0; |
|
1189 | + if ($a[0] == $b[0]) { |
|
1190 | + return 0; |
|
1191 | + } |
|
1147 | 1192 | return $a[0] == 'remove_table' ? -1 : 1; |
1148 | 1193 | } |
1149 | 1194 | usort($db_package_log, 'sort_table_first'); |
1150 | 1195 | foreach ($db_package_log as $k => $log) |
1151 | 1196 | { |
1152 | - if ($log[0] == 'remove_table') |
|
1153 | - $tables[] = $log[1]; |
|
1154 | - elseif (in_array($log[1], $tables)) |
|
1155 | - unset($db_package_log[$k]); |
|
1197 | + if ($log[0] == 'remove_table') { |
|
1198 | + $tables[] = $log[1]; |
|
1199 | + } elseif (in_array($log[1], $tables)) { |
|
1200 | + unset($db_package_log[$k]); |
|
1201 | + } |
|
1156 | 1202 | } |
1157 | 1203 | $db_changes = json_encode($db_package_log); |
1204 | + } else { |
|
1205 | + $db_changes = ''; |
|
1158 | 1206 | } |
1159 | - else |
|
1160 | - $db_changes = ''; |
|
1161 | 1207 | |
1162 | 1208 | // What themes did we actually install? |
1163 | 1209 | $themes_installed = array_unique($themes_installed); |
@@ -1206,18 +1252,20 @@ discard block |
||
1206 | 1252 | |
1207 | 1253 | foreach ($db_changes as $change) |
1208 | 1254 | { |
1209 | - if ($change[0] == 'remove_table' && isset($change[1])) |
|
1210 | - $smcFunc['db_drop_table']($change[1]); |
|
1211 | - elseif ($change[0] == 'remove_column' && isset($change[2])) |
|
1212 | - $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1213 | - elseif ($change[0] == 'remove_index' && isset($change[2])) |
|
1214 | - $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1255 | + if ($change[0] == 'remove_table' && isset($change[1])) { |
|
1256 | + $smcFunc['db_drop_table']($change[1]); |
|
1257 | + } elseif ($change[0] == 'remove_column' && isset($change[2])) { |
|
1258 | + $smcFunc['db_remove_column']($change[1], $change[2]); |
|
1259 | + } elseif ($change[0] == 'remove_index' && isset($change[2])) { |
|
1260 | + $smcFunc['db_remove_index']($change[1], $change[2]); |
|
1261 | + } |
|
1215 | 1262 | } |
1216 | 1263 | } |
1217 | 1264 | |
1218 | 1265 | // Clean house... get rid of the evidence ;). |
1219 | - if (file_exists($packagesdir . '/temp')) |
|
1220 | - deltree($packagesdir . '/temp'); |
|
1266 | + if (file_exists($packagesdir . '/temp')) { |
|
1267 | + deltree($packagesdir . '/temp'); |
|
1268 | + } |
|
1221 | 1269 | |
1222 | 1270 | // Log what we just did. |
1223 | 1271 | logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin'); |
@@ -1239,8 +1287,9 @@ discard block |
||
1239 | 1287 | require_once($sourcedir . '/Subs-Package.php'); |
1240 | 1288 | |
1241 | 1289 | // No package? Show him or her the door. |
1242 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1243 | - redirectexit('action=admin;area=packages'); |
|
1290 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1291 | + redirectexit('action=admin;area=packages'); |
|
1292 | + } |
|
1244 | 1293 | |
1245 | 1294 | $context['linktree'][] = array( |
1246 | 1295 | 'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'], |
@@ -1253,11 +1302,12 @@ discard block |
||
1253 | 1302 | $context['filename'] = $_REQUEST['package']; |
1254 | 1303 | |
1255 | 1304 | // Let the unpacker do the work. |
1256 | - if (is_file($packagesdir . '/' . $context['filename'])) |
|
1257 | - $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1258 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1259 | - $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1260 | -} |
|
1305 | + if (is_file($packagesdir . '/' . $context['filename'])) { |
|
1306 | + $context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null); |
|
1307 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) { |
|
1308 | + $context['files'] = listtree($packagesdir . '/' . $context['filename']); |
|
1309 | + } |
|
1310 | + } |
|
1261 | 1311 | |
1262 | 1312 | /** |
1263 | 1313 | * Display one of the files in a package. |
@@ -1269,22 +1319,25 @@ discard block |
||
1269 | 1319 | require_once($sourcedir . '/Subs-Package.php'); |
1270 | 1320 | |
1271 | 1321 | // No package? Show him or her the door. |
1272 | - if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') |
|
1273 | - redirectexit('action=admin;area=packages'); |
|
1322 | + if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') { |
|
1323 | + redirectexit('action=admin;area=packages'); |
|
1324 | + } |
|
1274 | 1325 | |
1275 | 1326 | // No file? Show him or her the door. |
1276 | - if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') |
|
1277 | - redirectexit('action=admin;area=packages'); |
|
1327 | + if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') { |
|
1328 | + redirectexit('action=admin;area=packages'); |
|
1329 | + } |
|
1278 | 1330 | |
1279 | 1331 | $_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_'))); |
1280 | 1332 | $_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']); |
1281 | 1333 | |
1282 | 1334 | if (isset($_REQUEST['raw'])) |
1283 | 1335 | { |
1284 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1285 | - echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1286 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1287 | - echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1336 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1337 | + echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true); |
|
1338 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1339 | + echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']); |
|
1340 | + } |
|
1288 | 1341 | |
1289 | 1342 | obExit(false); |
1290 | 1343 | } |
@@ -1301,17 +1354,19 @@ discard block |
||
1301 | 1354 | $context['filename'] = $_REQUEST['file']; |
1302 | 1355 | |
1303 | 1356 | // Let the unpacker do the work.... but make sure we handle images properly. |
1304 | - if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) |
|
1305 | - $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1306 | - else |
|
1357 | + if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) { |
|
1358 | + $context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">'; |
|
1359 | + } else |
|
1307 | 1360 | { |
1308 | - if (is_file($packagesdir . '/' . $_REQUEST['package'])) |
|
1309 | - $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1310 | - elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) |
|
1311 | - $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1361 | + if (is_file($packagesdir . '/' . $_REQUEST['package'])) { |
|
1362 | + $context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true)); |
|
1363 | + } elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) { |
|
1364 | + $context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file'])); |
|
1365 | + } |
|
1312 | 1366 | |
1313 | - if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') |
|
1314 | - $context['filedata'] = highlight_php_code($context['filedata']); |
|
1367 | + if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') { |
|
1368 | + $context['filedata'] = highlight_php_code($context['filedata']); |
|
1369 | + } |
|
1315 | 1370 | } |
1316 | 1371 | } |
1317 | 1372 | |
@@ -1326,8 +1381,9 @@ discard block |
||
1326 | 1381 | checkSession('get'); |
1327 | 1382 | |
1328 | 1383 | // Ack, don't allow deletion of arbitrary files here, could become a security hole somehow! |
1329 | - if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') |
|
1330 | - redirectexit('action=admin;area=packages;sa=browse'); |
|
1384 | + if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') { |
|
1385 | + redirectexit('action=admin;area=packages;sa=browse'); |
|
1386 | + } |
|
1331 | 1387 | $_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_'))); |
1332 | 1388 | |
1333 | 1389 | // Can't delete what's not there. |
@@ -1335,9 +1391,9 @@ discard block |
||
1335 | 1391 | { |
1336 | 1392 | create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true)); |
1337 | 1393 | |
1338 | - if (is_dir($packagesdir . '/' . $_GET['package'])) |
|
1339 | - deltree($packagesdir . '/' . $_GET['package']); |
|
1340 | - else |
|
1394 | + if (is_dir($packagesdir . '/' . $_GET['package'])) { |
|
1395 | + deltree($packagesdir . '/' . $_GET['package']); |
|
1396 | + } else |
|
1341 | 1397 | { |
1342 | 1398 | smf_chmod($packagesdir . '/' . $_GET['package'], 0777); |
1343 | 1399 | unlink($packagesdir . '/' . $_GET['package']); |
@@ -1385,8 +1441,9 @@ discard block |
||
1385 | 1441 | 'data' => array( |
1386 | 1442 | 'function' => function($package_md5) use ($type, &$context) |
1387 | 1443 | { |
1388 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1389 | - return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1444 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1445 | + return $context['available_' . $type . ''][$package_md5]['sort_id']; |
|
1446 | + } |
|
1390 | 1447 | }, |
1391 | 1448 | ), |
1392 | 1449 | 'sort' => array( |
@@ -1402,8 +1459,9 @@ discard block |
||
1402 | 1459 | 'data' => array( |
1403 | 1460 | 'function' => function($package_md5) use ($type, &$context) |
1404 | 1461 | { |
1405 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1406 | - return $context['available_' . $type . ''][$package_md5]['name']; |
|
1462 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1463 | + return $context['available_' . $type . ''][$package_md5]['name']; |
|
1464 | + } |
|
1407 | 1465 | }, |
1408 | 1466 | ), |
1409 | 1467 | 'sort' => array( |
@@ -1418,8 +1476,9 @@ discard block |
||
1418 | 1476 | 'data' => array( |
1419 | 1477 | 'function' => function($package_md5) use ($type, &$context) |
1420 | 1478 | { |
1421 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1422 | - return $context['available_' . $type . ''][$package_md5]['version']; |
|
1479 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1480 | + return $context['available_' . $type . ''][$package_md5]['version']; |
|
1481 | + } |
|
1423 | 1482 | }, |
1424 | 1483 | ), |
1425 | 1484 | 'sort' => array( |
@@ -1434,8 +1493,9 @@ discard block |
||
1434 | 1493 | 'data' => array( |
1435 | 1494 | 'function' => function($package_md5) use ($type, $txt, &$context) |
1436 | 1495 | { |
1437 | - if (isset($context['available_' . $type . ''][$package_md5])) |
|
1438 | - return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1496 | + if (isset($context['available_' . $type . ''][$package_md5])) { |
|
1497 | + return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable']; |
|
1498 | + } |
|
1439 | 1499 | }, |
1440 | 1500 | 'class' => 'smalltext', |
1441 | 1501 | ), |
@@ -1451,28 +1511,30 @@ discard block |
||
1451 | 1511 | 'data' => array( |
1452 | 1512 | 'function' => function($package_md5) use ($type, &$context, $scripturl, $txt) |
1453 | 1513 | { |
1454 | - if (!isset($context['available_' . $type . ''][$package_md5])) |
|
1455 | - return ''; |
|
1514 | + if (!isset($context['available_' . $type . ''][$package_md5])) { |
|
1515 | + return ''; |
|
1516 | + } |
|
1456 | 1517 | |
1457 | 1518 | // Rewrite shortcut |
1458 | 1519 | $package = $context['available_' . $type . ''][$package_md5]; |
1459 | 1520 | $return = ''; |
1460 | 1521 | |
1461 | - if ($package['can_uninstall']) |
|
1462 | - $return = ' |
|
1522 | + if ($package['can_uninstall']) { |
|
1523 | + $return = ' |
|
1463 | 1524 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>'; |
1464 | - elseif ($package['can_emulate_uninstall']) |
|
1465 | - $return = ' |
|
1525 | + } elseif ($package['can_emulate_uninstall']) { |
|
1526 | + $return = ' |
|
1466 | 1527 | <a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>'; |
1467 | - elseif ($package['can_upgrade']) |
|
1468 | - $return = ' |
|
1528 | + } elseif ($package['can_upgrade']) { |
|
1529 | + $return = ' |
|
1469 | 1530 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>'; |
1470 | - elseif ($package['can_install']) |
|
1471 | - $return = ' |
|
1531 | + } elseif ($package['can_install']) { |
|
1532 | + $return = ' |
|
1472 | 1533 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>'; |
1473 | - elseif ($package['can_emulate_install']) |
|
1474 | - $return = ' |
|
1534 | + } elseif ($package['can_emulate_install']) { |
|
1535 | + $return = ' |
|
1475 | 1536 | <a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>'; |
1537 | + } |
|
1476 | 1538 | |
1477 | 1539 | return $return . ' |
1478 | 1540 | <a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a> |
@@ -1537,12 +1599,14 @@ discard block |
||
1537 | 1599 | static $packages, $installed_mods; |
1538 | 1600 | |
1539 | 1601 | // Start things up |
1540 | - if (!isset($packages[$params])) |
|
1541 | - $packages[$params] = array(); |
|
1602 | + if (!isset($packages[$params])) { |
|
1603 | + $packages[$params] = array(); |
|
1604 | + } |
|
1542 | 1605 | |
1543 | 1606 | // We need the packages directory to be writable for this. |
1544 | - if (!@is_writable($packagesdir)) |
|
1545 | - create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1607 | + if (!@is_writable($packagesdir)) { |
|
1608 | + create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true)); |
|
1609 | + } |
|
1546 | 1610 | |
1547 | 1611 | $the_version = strtr($forum_version, array('SMF ' => '')); |
1548 | 1612 | |
@@ -1550,41 +1614,44 @@ discard block |
||
1550 | 1614 | if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version) |
1551 | 1615 | { |
1552 | 1616 | unset($_SESSION['version_emulate']); |
1553 | - } |
|
1554 | - elseif (isset($_GET['version_emulate'])) |
|
1617 | + } elseif (isset($_GET['version_emulate'])) |
|
1555 | 1618 | { |
1556 | - if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) |
|
1557 | - unset($_SESSION['version_emulate']); |
|
1558 | - elseif ($_GET['version_emulate'] !== 0) |
|
1559 | - $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1619 | + if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) { |
|
1620 | + unset($_SESSION['version_emulate']); |
|
1621 | + } elseif ($_GET['version_emulate'] !== 0) { |
|
1622 | + $_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => '')); |
|
1623 | + } |
|
1560 | 1624 | } |
1561 | 1625 | if (!empty($_SESSION['version_emulate'])) |
1562 | 1626 | { |
1563 | 1627 | $context['forum_version'] = 'SMF ' . $_SESSION['version_emulate']; |
1564 | 1628 | $the_version = $_SESSION['version_emulate']; |
1565 | 1629 | } |
1566 | - if (isset($_SESSION['single_version_emulate'])) |
|
1567 | - unset($_SESSION['single_version_emulate']); |
|
1630 | + if (isset($_SESSION['single_version_emulate'])) { |
|
1631 | + unset($_SESSION['single_version_emulate']); |
|
1632 | + } |
|
1568 | 1633 | |
1569 | 1634 | if (empty($installed_mods)) |
1570 | 1635 | { |
1571 | 1636 | $instmods = loadInstalledPackages(); |
1572 | 1637 | $installed_mods = array(); |
1573 | 1638 | // Look through the list of installed mods... |
1574 | - foreach ($instmods as $installed_mod) |
|
1575 | - $installed_mods[$installed_mod['package_id']] = array( |
|
1639 | + foreach ($instmods as $installed_mod) { |
|
1640 | + $installed_mods[$installed_mod['package_id']] = array( |
|
1576 | 1641 | 'id' => $installed_mod['id'], |
1577 | 1642 | 'version' => $installed_mod['version'], |
1578 | 1643 | 'time_installed' => $installed_mod['time_installed'], |
1579 | 1644 | ); |
1645 | + } |
|
1580 | 1646 | |
1581 | 1647 | // Get a list of all the ids installed, so the latest packages won't include already installed ones. |
1582 | 1648 | $context['installed_mods'] = array_keys($installed_mods); |
1583 | 1649 | } |
1584 | 1650 | |
1585 | - if (empty($packages)) |
|
1586 | - foreach ($context['modification_types'] as $type) |
|
1651 | + if (empty($packages)) { |
|
1652 | + foreach ($context['modification_types'] as $type) |
|
1587 | 1653 | $packages[$type] = array(); |
1654 | + } |
|
1588 | 1655 | |
1589 | 1656 | if ($dir = @opendir($packagesdir)) |
1590 | 1657 | { |
@@ -1600,50 +1667,56 @@ discard block |
||
1600 | 1667 | |
1601 | 1668 | while ($package = readdir($dir)) |
1602 | 1669 | { |
1603 | - if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) |
|
1604 | - continue; |
|
1670 | + if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) { |
|
1671 | + continue; |
|
1672 | + } |
|
1605 | 1673 | |
1606 | 1674 | $skip = false; |
1607 | - foreach ($context['modification_types'] as $type) |
|
1608 | - if (isset($context['available_' . $type][md5($package)])) |
|
1675 | + foreach ($context['modification_types'] as $type) { |
|
1676 | + if (isset($context['available_' . $type][md5($package)])) |
|
1609 | 1677 | $skip = true; |
1678 | + } |
|
1610 | 1679 | |
1611 | - if ($skip) |
|
1612 | - continue; |
|
1680 | + if ($skip) { |
|
1681 | + continue; |
|
1682 | + } |
|
1613 | 1683 | |
1614 | 1684 | // Skip directories or files that are named the same. |
1615 | 1685 | if (is_dir($packagesdir . '/' . $package)) |
1616 | 1686 | { |
1617 | - if (in_array($package, $dirs)) |
|
1618 | - continue; |
|
1687 | + if (in_array($package, $dirs)) { |
|
1688 | + continue; |
|
1689 | + } |
|
1619 | 1690 | $dirs[] = $package; |
1620 | - } |
|
1621 | - elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1691 | + } elseif (substr(strtolower($package), -7) == '.tar.gz') |
|
1622 | 1692 | { |
1623 | - if (in_array(substr($package, 0, -7), $dirs)) |
|
1624 | - continue; |
|
1693 | + if (in_array(substr($package, 0, -7), $dirs)) { |
|
1694 | + continue; |
|
1695 | + } |
|
1625 | 1696 | $dirs[] = substr($package, 0, -7); |
1626 | - } |
|
1627 | - elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1697 | + } elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz') |
|
1628 | 1698 | { |
1629 | - if (in_array(substr($package, 0, -4), $dirs)) |
|
1630 | - continue; |
|
1699 | + if (in_array(substr($package, 0, -4), $dirs)) { |
|
1700 | + continue; |
|
1701 | + } |
|
1631 | 1702 | $dirs[] = substr($package, 0, -4); |
1632 | 1703 | } |
1633 | 1704 | |
1634 | 1705 | $packageInfo = getPackageInfo($package); |
1635 | - if (!is_array($packageInfo)) |
|
1636 | - continue; |
|
1706 | + if (!is_array($packageInfo)) { |
|
1707 | + continue; |
|
1708 | + } |
|
1637 | 1709 | |
1638 | 1710 | if (!empty($packageInfo)) |
1639 | 1711 | { |
1640 | 1712 | $packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0; |
1641 | 1713 | $packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0; |
1642 | 1714 | |
1643 | - if (!isset($sort_id[$packageInfo['type']])) |
|
1644 | - $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1645 | - else |
|
1646 | - $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1715 | + if (!isset($sort_id[$packageInfo['type']])) { |
|
1716 | + $packageInfo['sort_id'] = $sort_id['unknown']; |
|
1717 | + } else { |
|
1718 | + $packageInfo['sort_id'] = $sort_id[$packageInfo['type']]; |
|
1719 | + } |
|
1647 | 1720 | |
1648 | 1721 | $packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]); |
1649 | 1722 | $packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']); |
@@ -1692,10 +1765,11 @@ discard block |
||
1692 | 1765 | foreach ($upgrades as $upgrade) |
1693 | 1766 | { |
1694 | 1767 | // Even if it is for this SMF, is it for the installed version of the mod? |
1695 | - if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) |
|
1696 | - if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1768 | + if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) { |
|
1769 | + if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from'))) |
|
1697 | 1770 | { |
1698 | 1771 | $packageInfo['can_upgrade'] = true; |
1772 | + } |
|
1699 | 1773 | break; |
1700 | 1774 | } |
1701 | 1775 | } |
@@ -1772,10 +1846,11 @@ discard block |
||
1772 | 1846 | |
1773 | 1847 | if (isset($_GET['type']) && $_GET['type'] == $params) |
1774 | 1848 | { |
1775 | - if (isset($_GET['desc'])) |
|
1776 | - krsort($packages[$params]); |
|
1777 | - else |
|
1778 | - ksort($packages[$params]); |
|
1849 | + if (isset($_GET['desc'])) { |
|
1850 | + krsort($packages[$params]); |
|
1851 | + } else { |
|
1852 | + ksort($packages[$params]); |
|
1853 | + } |
|
1779 | 1854 | } |
1780 | 1855 | |
1781 | 1856 | return $packages[$params]; |
@@ -1804,10 +1879,11 @@ discard block |
||
1804 | 1879 | redirectexit('action=admin;area=packages;sa=options'); |
1805 | 1880 | } |
1806 | 1881 | |
1807 | - if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) |
|
1808 | - $default_username = $match[1]; |
|
1809 | - else |
|
1810 | - $default_username = ''; |
|
1882 | + if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) { |
|
1883 | + $default_username = $match[1]; |
|
1884 | + } else { |
|
1885 | + $default_username = ''; |
|
1886 | + } |
|
1811 | 1887 | |
1812 | 1888 | $context['page_title'] = $txt['package_settings']; |
1813 | 1889 | $context['sub_template'] = 'install_options'; |
@@ -1836,8 +1912,9 @@ discard block |
||
1836 | 1912 | isAllowedTo('admin_forum'); |
1837 | 1913 | |
1838 | 1914 | // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? |
1839 | - if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) |
|
1840 | - fatal_lang_error('operation_invalid', 'general'); |
|
1915 | + if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { |
|
1916 | + fatal_lang_error('operation_invalid', 'general'); |
|
1917 | + } |
|
1841 | 1918 | |
1842 | 1919 | // Load the required file. |
1843 | 1920 | require_once($sourcedir . '/Subs-Package.php'); |
@@ -1853,18 +1930,19 @@ discard block |
||
1853 | 1930 | { |
1854 | 1931 | $context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1855 | 1932 | |
1856 | - if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1857 | - foreach ($context['extracted_files'] as $file) |
|
1933 | + if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1934 | + foreach ($context['extracted_files'] as $file) |
|
1858 | 1935 | if (basename($file['filename']) == 'package-info.xml') |
1859 | 1936 | { |
1860 | 1937 | $context['base_path'] = dirname($file['filename']) . '/'; |
1938 | + } |
|
1861 | 1939 | break; |
1862 | 1940 | } |
1863 | 1941 | |
1864 | - if (!isset($context['base_path'])) |
|
1865 | - $context['base_path'] = ''; |
|
1866 | - } |
|
1867 | - elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1942 | + if (!isset($context['base_path'])) { |
|
1943 | + $context['base_path'] = ''; |
|
1944 | + } |
|
1945 | + } elseif (is_dir($packagesdir . '/' . $context['filename'])) |
|
1868 | 1946 | { |
1869 | 1947 | copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp'); |
1870 | 1948 | $context['extracted_files'] = listtree($packagesdir . '/temp'); |
@@ -1885,8 +1963,9 @@ discard block |
||
1885 | 1963 | ) |
1886 | 1964 | ); |
1887 | 1965 | $theme_paths = array(); |
1888 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1889 | - $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1966 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1967 | + $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; |
|
1968 | + } |
|
1890 | 1969 | $smcFunc['db_free_result']($request); |
1891 | 1970 | |
1892 | 1971 | // If we're viewing uninstall operations, only consider themes that |
@@ -1911,19 +1990,21 @@ discard block |
||
1911 | 1990 | list ($old_themes) = $smcFunc['db_fetch_row']($request); |
1912 | 1991 | $old_themes = explode(',', $old_themes); |
1913 | 1992 | |
1914 | - foreach ($theme_paths as $id => $data) |
|
1915 | - if ($id != 1 && !in_array($id, $old_themes)) |
|
1993 | + foreach ($theme_paths as $id => $data) { |
|
1994 | + if ($id != 1 && !in_array($id, $old_themes)) |
|
1916 | 1995 | unset($theme_paths[$id]); |
1996 | + } |
|
1917 | 1997 | } |
1918 | 1998 | $smcFunc['db_free_result']($request); |
1919 | 1999 | } |
1920 | 2000 | } |
1921 | 2001 | |
1922 | 2002 | // Boardmod? |
1923 | - if (isset($_REQUEST['boardmod'])) |
|
1924 | - $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
1925 | - else |
|
1926 | - $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2003 | + if (isset($_REQUEST['boardmod'])) { |
|
2004 | + $mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2005 | + } else { |
|
2006 | + $mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); |
|
2007 | + } |
|
1927 | 2008 | |
1928 | 2009 | // Ok lets get the content of the file. |
1929 | 2010 | $context['operations'] = array( |
@@ -1979,9 +2060,9 @@ discard block |
||
1979 | 2060 | 'path' => $detect_path, |
1980 | 2061 | 'form_elements_only' => true, |
1981 | 2062 | ); |
2063 | + } else { |
|
2064 | + $context['ftp_connected'] = true; |
|
1982 | 2065 | } |
1983 | - else |
|
1984 | - $context['ftp_connected'] = true; |
|
1985 | 2066 | |
1986 | 2067 | // Define the template. |
1987 | 2068 | $context['page_title'] = $txt['package_file_perms']; |
@@ -2094,18 +2175,19 @@ discard block |
||
2094 | 2175 | { |
2095 | 2176 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2096 | 2177 | |
2097 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
2098 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
2178 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
2179 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
2180 | + } |
|
2099 | 2181 | |
2100 | 2182 | // @todo Should we suggest non-current directories be read only? |
2101 | - foreach ($modSettings['attachmentUploadDir'] as $dir) |
|
2102 | - $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2183 | + foreach ($modSettings['attachmentUploadDir'] as $dir) { |
|
2184 | + $context['file_tree'][strtr($dir, array('\\' => '/'))] = array( |
|
2103 | 2185 | 'type' => 'dir', |
2104 | 2186 | 'writable_on' => 'restrictive', |
2105 | 2187 | ); |
2188 | + } |
|
2106 | 2189 | |
2107 | - } |
|
2108 | - elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2190 | + } elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir) |
|
2109 | 2191 | { |
2110 | 2192 | unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']); |
2111 | 2193 | $context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array( |
@@ -2155,8 +2237,8 @@ discard block |
||
2155 | 2237 | ); |
2156 | 2238 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
2157 | 2239 | { |
2158 | - if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) |
|
2159 | - $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2240 | + if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) { |
|
2241 | + $context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array( |
|
2160 | 2242 | 'type' => 'dir_recursive', |
2161 | 2243 | 'list_contents' => true, |
2162 | 2244 | 'contents' => array( |
@@ -2166,7 +2248,7 @@ discard block |
||
2166 | 2248 | ), |
2167 | 2249 | ), |
2168 | 2250 | ); |
2169 | - else |
|
2251 | + } else |
|
2170 | 2252 | { |
2171 | 2253 | $context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array( |
2172 | 2254 | 'type' => 'dir_recursive', |
@@ -2183,28 +2265,33 @@ discard block |
||
2183 | 2265 | $smcFunc['db_free_result']($request); |
2184 | 2266 | |
2185 | 2267 | // If we're submitting then let's move on to another function to keep things cleaner.. |
2186 | - if (isset($_POST['action_changes'])) |
|
2187 | - return PackagePermissionsAction(); |
|
2268 | + if (isset($_POST['action_changes'])) { |
|
2269 | + return PackagePermissionsAction(); |
|
2270 | + } |
|
2188 | 2271 | |
2189 | 2272 | $context['look_for'] = array(); |
2190 | 2273 | // Are we looking for a particular tree - normally an expansion? |
2191 | - if (!empty($_REQUEST['find'])) |
|
2192 | - $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2274 | + if (!empty($_REQUEST['find'])) { |
|
2275 | + $context['look_for'][] = base64_decode($_REQUEST['find']); |
|
2276 | + } |
|
2193 | 2277 | // Only that tree? |
2194 | 2278 | $context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : ''; |
2195 | - if ($context['only_find']) |
|
2196 | - $context['look_for'][] = $context['only_find']; |
|
2279 | + if ($context['only_find']) { |
|
2280 | + $context['look_for'][] = $context['only_find']; |
|
2281 | + } |
|
2197 | 2282 | |
2198 | 2283 | // Have we got a load of back-catalogue trees to expand from a submit etc? |
2199 | 2284 | if (!empty($_GET['back_look'])) |
2200 | 2285 | { |
2201 | 2286 | $potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true); |
2202 | - foreach ($potententialTrees as $tree) |
|
2203 | - $context['look_for'][] = $tree; |
|
2287 | + foreach ($potententialTrees as $tree) { |
|
2288 | + $context['look_for'][] = $tree; |
|
2289 | + } |
|
2204 | 2290 | } |
2205 | 2291 | // ... maybe posted? |
2206 | - if (!empty($_POST['back_look'])) |
|
2207 | - $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2292 | + if (!empty($_POST['back_look'])) { |
|
2293 | + $context['only_find'] = array_merge($context['only_find'], $_POST['back_look']); |
|
2294 | + } |
|
2208 | 2295 | |
2209 | 2296 | $context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15))); |
2210 | 2297 | |
@@ -2243,9 +2330,9 @@ discard block |
||
2243 | 2330 | 'chmod' => @is_writable($path), |
2244 | 2331 | 'perms' => @fileperms($path), |
2245 | 2332 | ); |
2333 | + } else { |
|
2334 | + unset($context['file_tree'][$path]); |
|
2246 | 2335 | } |
2247 | - else |
|
2248 | - unset($context['file_tree'][$path]); |
|
2249 | 2336 | } |
2250 | 2337 | |
2251 | 2338 | // Is this actually xml? |
@@ -2269,22 +2356,25 @@ discard block |
||
2269 | 2356 | global $context; |
2270 | 2357 | |
2271 | 2358 | $isLikelyPath = false; |
2272 | - foreach ($context['look_for'] as $possiblePath) |
|
2273 | - if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2359 | + foreach ($context['look_for'] as $possiblePath) { |
|
2360 | + if (substr($possiblePath, 0, strlen($path)) == $path) |
|
2274 | 2361 | $isLikelyPath = true; |
2362 | + } |
|
2275 | 2363 | |
2276 | 2364 | // Is this where we stop? |
2277 | - if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) |
|
2278 | - return; |
|
2279 | - elseif ($level > $context['default_level'] && !$isLikelyPath) |
|
2280 | - return; |
|
2365 | + if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) { |
|
2366 | + return; |
|
2367 | + } elseif ($level > $context['default_level'] && !$isLikelyPath) { |
|
2368 | + return; |
|
2369 | + } |
|
2281 | 2370 | |
2282 | 2371 | // Are we actually interested in saving this data? |
2283 | 2372 | $save_data = empty($context['only_find']) || $context['only_find'] == $path; |
2284 | 2373 | |
2285 | 2374 | // @todo Shouldn't happen - but better error message? |
2286 | - if (!is_dir($path)) |
|
2287 | - fatal_lang_error('no_access', false); |
|
2375 | + if (!is_dir($path)) { |
|
2376 | + fatal_lang_error('no_access', false); |
|
2377 | + } |
|
2288 | 2378 | |
2289 | 2379 | // This is where we put stuff we've found for sorting. |
2290 | 2380 | $foundData = array( |
@@ -2299,11 +2389,13 @@ discard block |
||
2299 | 2389 | if (is_file($path . '/' . $entry)) |
2300 | 2390 | { |
2301 | 2391 | // Are we listing PHP files in this directory? |
2302 | - if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') |
|
2303 | - $foundData['files'][$entry] = true; |
|
2392 | + if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') { |
|
2393 | + $foundData['files'][$entry] = true; |
|
2394 | + } |
|
2304 | 2395 | // A file we were looking for. |
2305 | - elseif ($save_data && isset($data['contents'][$entry])) |
|
2306 | - $foundData['files'][$entry] = true; |
|
2396 | + elseif ($save_data && isset($data['contents'][$entry])) { |
|
2397 | + $foundData['files'][$entry] = true; |
|
2398 | + } |
|
2307 | 2399 | } |
2308 | 2400 | // It's a directory - we're interested one way or another, probably... |
2309 | 2401 | elseif ($entry != '.' && $entry != '..') |
@@ -2311,32 +2403,36 @@ discard block |
||
2311 | 2403 | // Going further? |
2312 | 2404 | if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive')))) |
2313 | 2405 | { |
2314 | - if (!isset($data['contents'][$entry])) |
|
2315 | - $foundData['folders'][$entry] = 'dir_recursive'; |
|
2316 | - else |
|
2317 | - $foundData['folders'][$entry] = true; |
|
2406 | + if (!isset($data['contents'][$entry])) { |
|
2407 | + $foundData['folders'][$entry] = 'dir_recursive'; |
|
2408 | + } else { |
|
2409 | + $foundData['folders'][$entry] = true; |
|
2410 | + } |
|
2318 | 2411 | |
2319 | 2412 | // If this wasn't expected inherit the recusiveness... |
2320 | - if (!isset($data['contents'][$entry])) |
|
2321 | - // We need to do this as we will be going all recursive. |
|
2413 | + if (!isset($data['contents'][$entry])) { |
|
2414 | + // We need to do this as we will be going all recursive. |
|
2322 | 2415 | $data['contents'][$entry] = array( |
2323 | 2416 | 'type' => 'dir_recursive', |
2324 | 2417 | ); |
2418 | + } |
|
2325 | 2419 | |
2326 | 2420 | // Actually do the recursive stuff... |
2327 | 2421 | fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1); |
2328 | 2422 | } |
2329 | 2423 | // Maybe it is a folder we are not descending into. |
2330 | - elseif (isset($data['contents'][$entry])) |
|
2331 | - $foundData['folders'][$entry] = true; |
|
2424 | + elseif (isset($data['contents'][$entry])) { |
|
2425 | + $foundData['folders'][$entry] = true; |
|
2426 | + } |
|
2332 | 2427 | // Otherwise we stop here. |
2333 | 2428 | } |
2334 | 2429 | } |
2335 | 2430 | closedir($dh); |
2336 | 2431 | |
2337 | 2432 | // Nothing to see here? |
2338 | - if (!$save_data) |
|
2339 | - return; |
|
2433 | + if (!$save_data) { |
|
2434 | + return; |
|
2435 | + } |
|
2340 | 2436 | |
2341 | 2437 | // Now actually add the data, starting with the folders. |
2342 | 2438 | ksort($foundData['folders']); |
@@ -2348,8 +2444,9 @@ discard block |
||
2348 | 2444 | 'perms' => @fileperms($path . '/' . $folder), |
2349 | 2445 | ), |
2350 | 2446 | ); |
2351 | - if ($type !== true) |
|
2352 | - $additional_data['type'] = $type; |
|
2447 | + if ($type !== true) { |
|
2448 | + $additional_data['type'] = $type; |
|
2449 | + } |
|
2353 | 2450 | |
2354 | 2451 | // If there's an offset ignore any folders in XML mode. |
2355 | 2452 | if (isset($_GET['xml']) && $context['file_offset'] == 0) |
@@ -2368,13 +2465,13 @@ discard block |
||
2368 | 2465 | ), |
2369 | 2466 | 'value' => $folder, |
2370 | 2467 | ); |
2371 | - } |
|
2372 | - elseif (!isset($_GET['xml'])) |
|
2468 | + } elseif (!isset($_GET['xml'])) |
|
2373 | 2469 | { |
2374 | - if (isset($data['contents'][$folder])) |
|
2375 | - $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2376 | - else |
|
2377 | - $data['contents'][$folder] = $additional_data; |
|
2470 | + if (isset($data['contents'][$folder])) { |
|
2471 | + $data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data); |
|
2472 | + } else { |
|
2473 | + $data['contents'][$folder] = $additional_data; |
|
2474 | + } |
|
2378 | 2475 | } |
2379 | 2476 | } |
2380 | 2477 | |
@@ -2386,11 +2483,13 @@ discard block |
||
2386 | 2483 | $counter++; |
2387 | 2484 | |
2388 | 2485 | // Have we reached our offset? |
2389 | - if ($context['file_offset'] > $counter) |
|
2390 | - continue; |
|
2486 | + if ($context['file_offset'] > $counter) { |
|
2487 | + continue; |
|
2488 | + } |
|
2391 | 2489 | // Gone too far? |
2392 | - if ($counter > ($context['file_offset'] + $context['file_limit'])) |
|
2393 | - continue; |
|
2490 | + if ($counter > ($context['file_offset'] + $context['file_limit'])) { |
|
2491 | + continue; |
|
2492 | + } |
|
2394 | 2493 | |
2395 | 2494 | $additional_data = array( |
2396 | 2495 | 'perms' => array( |
@@ -2416,13 +2515,13 @@ discard block |
||
2416 | 2515 | ), |
2417 | 2516 | 'value' => $file, |
2418 | 2517 | ); |
2419 | - } |
|
2420 | - elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2518 | + } elseif ($counter != ($context['file_offset'] + $context['file_limit'])) |
|
2421 | 2519 | { |
2422 | - if (isset($data['contents'][$file])) |
|
2423 | - $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2424 | - else |
|
2425 | - $data['contents'][$file] = $additional_data; |
|
2520 | + if (isset($data['contents'][$file])) { |
|
2521 | + $data['contents'][$file] = array_merge($data['contents'][$file], $additional_data); |
|
2522 | + } else { |
|
2523 | + $data['contents'][$file] = $additional_data; |
|
2524 | + } |
|
2426 | 2525 | } |
2427 | 2526 | } |
2428 | 2527 | } |
@@ -2444,8 +2543,9 @@ discard block |
||
2444 | 2543 | $context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array(); |
2445 | 2544 | |
2446 | 2545 | // Skipping use of FTP? |
2447 | - if (empty($package_ftp)) |
|
2448 | - $context['skip_ftp'] = true; |
|
2546 | + if (empty($package_ftp)) { |
|
2547 | + $context['skip_ftp'] = true; |
|
2548 | + } |
|
2449 | 2549 | |
2450 | 2550 | // We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place. |
2451 | 2551 | if ($context['method'] == 'individual') |
@@ -2455,8 +2555,9 @@ discard block |
||
2455 | 2555 | $context['custom_value'] = (int) $_POST['custom_value']; |
2456 | 2556 | |
2457 | 2557 | // Continuing? |
2458 | - if (isset($_POST['toProcess'])) |
|
2459 | - $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
2558 | + if (isset($_POST['toProcess'])) { |
|
2559 | + $_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true); |
|
2560 | + } |
|
2460 | 2561 | |
2461 | 2562 | if (isset($_POST['permStatus'])) |
2462 | 2563 | { |
@@ -2465,22 +2566,27 @@ discard block |
||
2465 | 2566 | foreach ($_POST['permStatus'] as $path => $status) |
2466 | 2567 | { |
2467 | 2568 | // Nothing to see here? |
2468 | - if ($status == 'no_change') |
|
2469 | - continue; |
|
2569 | + if ($status == 'no_change') { |
|
2570 | + continue; |
|
2571 | + } |
|
2470 | 2572 | $legal = false; |
2471 | - foreach ($legal_roots as $root) |
|
2472 | - if (substr($path, 0, strlen($root)) == $root) |
|
2573 | + foreach ($legal_roots as $root) { |
|
2574 | + if (substr($path, 0, strlen($root)) == $root) |
|
2473 | 2575 | $legal = true; |
2576 | + } |
|
2474 | 2577 | |
2475 | - if (!$legal) |
|
2476 | - continue; |
|
2578 | + if (!$legal) { |
|
2579 | + continue; |
|
2580 | + } |
|
2477 | 2581 | |
2478 | 2582 | // Check it exists. |
2479 | - if (!file_exists($path)) |
|
2480 | - continue; |
|
2583 | + if (!file_exists($path)) { |
|
2584 | + continue; |
|
2585 | + } |
|
2481 | 2586 | |
2482 | - if ($status == 'custom') |
|
2483 | - $validate_custom = true; |
|
2587 | + if ($status == 'custom') { |
|
2588 | + $validate_custom = true; |
|
2589 | + } |
|
2484 | 2590 | |
2485 | 2591 | // Now add it. |
2486 | 2592 | $context['to_process'][$path] = $status; |
@@ -2490,17 +2596,20 @@ discard block |
||
2490 | 2596 | // Make sure the chmod status is valid? |
2491 | 2597 | if ($validate_custom) |
2492 | 2598 | { |
2493 | - if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) |
|
2494 | - fatal_error($txt['chmod_value_invalid']); |
|
2599 | + if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) { |
|
2600 | + fatal_error($txt['chmod_value_invalid']); |
|
2601 | + } |
|
2495 | 2602 | } |
2496 | 2603 | |
2497 | 2604 | // Nothing to do? |
2498 | - if (empty($context['to_process'])) |
|
2499 | - redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2605 | + if (empty($context['to_process'])) { |
|
2606 | + redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']); |
|
2607 | + } |
|
2500 | 2608 | } |
2501 | 2609 | // Should never get here, |
2502 | - else |
|
2503 | - fatal_lang_error('no_access', false); |
|
2610 | + else { |
|
2611 | + fatal_lang_error('no_access', false); |
|
2612 | + } |
|
2504 | 2613 | |
2505 | 2614 | // Setup the custom value. |
2506 | 2615 | $custom_value = octdec('0' . $context['custom_value']); |
@@ -2508,26 +2617,27 @@ discard block |
||
2508 | 2617 | // Start processing items. |
2509 | 2618 | foreach ($context['to_process'] as $path => $status) |
2510 | 2619 | { |
2511 | - if (in_array($status, array('execute', 'writable', 'read'))) |
|
2512 | - package_chmod($path, $status); |
|
2513 | - elseif ($status == 'custom' && !empty($custom_value)) |
|
2620 | + if (in_array($status, array('execute', 'writable', 'read'))) { |
|
2621 | + package_chmod($path, $status); |
|
2622 | + } elseif ($status == 'custom' && !empty($custom_value)) |
|
2514 | 2623 | { |
2515 | 2624 | // Use FTP if we have it. |
2516 | 2625 | if (!empty($package_ftp) && !empty($_SESSION['pack_ftp'])) |
2517 | 2626 | { |
2518 | 2627 | $ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => '')); |
2519 | 2628 | $package_ftp->chmod($ftp_file, $custom_value); |
2629 | + } else { |
|
2630 | + smf_chmod($path, $custom_value); |
|
2520 | 2631 | } |
2521 | - else |
|
2522 | - smf_chmod($path, $custom_value); |
|
2523 | 2632 | } |
2524 | 2633 | |
2525 | 2634 | // This fish is fried... |
2526 | 2635 | unset($context['to_process'][$path]); |
2527 | 2636 | |
2528 | 2637 | // See if we're out of time? |
2529 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2530 | - return false; |
|
2638 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2639 | + return false; |
|
2640 | + } |
|
2531 | 2641 | } |
2532 | 2642 | } |
2533 | 2643 | // If predefined this is a little different. |
@@ -2595,23 +2705,27 @@ discard block |
||
2595 | 2705 | { |
2596 | 2706 | global $context; |
2597 | 2707 | |
2598 | - if (!empty($data['writable_on'])) |
|
2599 | - if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2708 | + if (!empty($data['writable_on'])) { |
|
2709 | + if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive') |
|
2600 | 2710 | $context['special_files'][$path] = 1; |
2711 | + } |
|
2601 | 2712 | |
2602 | - if (!empty($data['contents'])) |
|
2603 | - foreach ($data['contents'] as $name => $contents) |
|
2713 | + if (!empty($data['contents'])) { |
|
2714 | + foreach ($data['contents'] as $name => $contents) |
|
2604 | 2715 | build_special_files__recursive($path . '/' . $name, $contents); |
2716 | + } |
|
2605 | 2717 | } |
2606 | 2718 | |
2607 | - foreach ($context['file_tree'] as $path => $data) |
|
2608 | - build_special_files__recursive($path, $data); |
|
2719 | + foreach ($context['file_tree'] as $path => $data) { |
|
2720 | + build_special_files__recursive($path, $data); |
|
2721 | + } |
|
2609 | 2722 | } |
2610 | 2723 | // Free doesn't need special files. |
2611 | - elseif ($context['predefined_type'] == 'free') |
|
2612 | - $context['special_files'] = array(); |
|
2613 | - else |
|
2614 | - $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2724 | + elseif ($context['predefined_type'] == 'free') { |
|
2725 | + $context['special_files'] = array(); |
|
2726 | + } else { |
|
2727 | + $context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true); |
|
2728 | + } |
|
2615 | 2729 | |
2616 | 2730 | // Now we definitely know where we are, we need to go through again doing the chmod! |
2617 | 2731 | foreach ($context['directory_list'] as $path => $dummy) |
@@ -2656,8 +2770,9 @@ discard block |
||
2656 | 2770 | unset($context['directory_list'][$path]); |
2657 | 2771 | |
2658 | 2772 | // See if we're out of time? |
2659 | - if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) |
|
2660 | - return false; |
|
2773 | + if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) { |
|
2774 | + return false; |
|
2775 | + } |
|
2661 | 2776 | } |
2662 | 2777 | } |
2663 | 2778 |
@@ -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 | * Allow the user to vote. |
@@ -51,8 +52,9 @@ discard block |
||
51 | 52 | 'not_guest' => 0, |
52 | 53 | ) |
53 | 54 | ); |
54 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
55 | - fatal_lang_error('poll_error', false); |
|
55 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
56 | + fatal_lang_error('poll_error', false); |
|
57 | + } |
|
56 | 58 | $row = $smcFunc['db_fetch_assoc']($request); |
57 | 59 | $smcFunc['db_free_result']($request); |
58 | 60 | |
@@ -60,8 +62,9 @@ discard block |
||
60 | 62 | if ($user_info['is_guest']) |
61 | 63 | { |
62 | 64 | // Guest voting disabled? |
63 | - if (!$row['guest_vote']) |
|
64 | - fatal_lang_error('guest_vote_disabled'); |
|
65 | + if (!$row['guest_vote']) { |
|
66 | + fatal_lang_error('guest_vote_disabled'); |
|
67 | + } |
|
65 | 68 | // Guest already voted? |
66 | 69 | elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false) |
67 | 70 | { |
@@ -71,32 +74,36 @@ discard block |
||
71 | 74 | foreach ($guestinfo as $i => $guestvoted) |
72 | 75 | { |
73 | 76 | $guestvoted = explode(',', $guestvoted); |
74 | - if ($guestvoted[0] == $row['id_poll']) |
|
75 | - break; |
|
77 | + if ($guestvoted[0] == $row['id_poll']) { |
|
78 | + break; |
|
79 | + } |
|
76 | 80 | } |
77 | 81 | // Has the poll been reset since guest voted? |
78 | 82 | if ($row['reset_poll'] > $guestvoted[1]) |
79 | 83 | { |
80 | 84 | // Remove the poll info from the cookie to allow guest to vote again |
81 | 85 | unset($guestinfo[$i]); |
82 | - if (!empty($guestinfo)) |
|
83 | - $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
84 | - else |
|
85 | - unset($_COOKIE['guest_poll_vote']); |
|
86 | + if (!empty($guestinfo)) { |
|
87 | + $_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo); |
|
88 | + } else { |
|
89 | + unset($_COOKIE['guest_poll_vote']); |
|
90 | + } |
|
91 | + } else { |
|
92 | + fatal_lang_error('poll_error', false); |
|
86 | 93 | } |
87 | - else |
|
88 | - fatal_lang_error('poll_error', false); |
|
89 | 94 | unset($guestinfo, $guestvoted, $i); |
90 | 95 | } |
91 | 96 | } |
92 | 97 | |
93 | 98 | // Is voting locked or has it expired? |
94 | - if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) |
|
95 | - fatal_lang_error('poll_error', false); |
|
99 | + if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) { |
|
100 | + fatal_lang_error('poll_error', false); |
|
101 | + } |
|
96 | 102 | |
97 | 103 | // If they have already voted and aren't allowed to change their vote - hence they are outta here! |
98 | - if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) |
|
99 | - fatal_lang_error('poll_error', false); |
|
104 | + if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) { |
|
105 | + fatal_lang_error('poll_error', false); |
|
106 | + } |
|
100 | 107 | // Otherwise if they can change their vote yet they haven't sent any options... remove their vote and redirect. |
101 | 108 | elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options'])) |
102 | 109 | { |
@@ -114,8 +121,9 @@ discard block |
||
114 | 121 | 'id_poll' => $row['id_poll'], |
115 | 122 | ) |
116 | 123 | ); |
117 | - while ($choice = $smcFunc['db_fetch_row']($request)) |
|
118 | - $pollOptions[] = $choice[0]; |
|
124 | + while ($choice = $smcFunc['db_fetch_row']($request)) { |
|
125 | + $pollOptions[] = $choice[0]; |
|
126 | + } |
|
119 | 127 | $smcFunc['db_free_result']($request); |
120 | 128 | |
121 | 129 | // Just skip it if they had voted for nothing before. |
@@ -148,19 +156,22 @@ discard block |
||
148 | 156 | } |
149 | 157 | |
150 | 158 | // Redirect back to the topic so the user can vote again! |
151 | - if (empty($_POST['options'])) |
|
152 | - redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
159 | + if (empty($_POST['options'])) { |
|
160 | + redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); |
|
161 | + } |
|
153 | 162 | } |
154 | 163 | |
155 | 164 | checkSession('request'); |
156 | 165 | |
157 | 166 | // Make sure the option(s) are valid. |
158 | - if (empty($_POST['options'])) |
|
159 | - fatal_lang_error('didnt_select_vote', false); |
|
167 | + if (empty($_POST['options'])) { |
|
168 | + fatal_lang_error('didnt_select_vote', false); |
|
169 | + } |
|
160 | 170 | |
161 | 171 | // Too many options checked! |
162 | - if (count($_REQUEST['options']) > $row['max_votes']) |
|
163 | - fatal_lang_error('poll_too_many_votes', false, array($row['max_votes'])); |
|
172 | + if (count($_REQUEST['options']) > $row['max_votes']) { |
|
173 | + fatal_lang_error('poll_too_many_votes', false, array($row['max_votes'])); |
|
174 | + } |
|
164 | 175 | |
165 | 176 | $pollOptions = array(); |
166 | 177 | $inserts = array(); |
@@ -250,24 +261,30 @@ discard block |
||
250 | 261 | list ($memberID, $pollID, $voting_locked) = $smcFunc['db_fetch_row']($request); |
251 | 262 | |
252 | 263 | // If the user _can_ modify the poll.... |
253 | - if (!allowedTo('poll_lock_any')) |
|
254 | - isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any')); |
|
264 | + if (!allowedTo('poll_lock_any')) { |
|
265 | + isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any')); |
|
266 | + } |
|
255 | 267 | |
256 | 268 | // It's been locked by a non-moderator. |
257 | - if ($voting_locked == '1') |
|
258 | - $voting_locked = '0'; |
|
269 | + if ($voting_locked == '1') { |
|
270 | + $voting_locked = '0'; |
|
271 | + } |
|
259 | 272 | // Locked by a moderator, and this is a moderator. |
260 | - elseif ($voting_locked == '2' && allowedTo('moderate_board')) |
|
261 | - $voting_locked = '0'; |
|
273 | + elseif ($voting_locked == '2' && allowedTo('moderate_board')) { |
|
274 | + $voting_locked = '0'; |
|
275 | + } |
|
262 | 276 | // Sorry, a moderator locked it. |
263 | - elseif ($voting_locked == '2' && !allowedTo('moderate_board')) |
|
264 | - fatal_lang_error('locked_by_admin', 'user'); |
|
277 | + elseif ($voting_locked == '2' && !allowedTo('moderate_board')) { |
|
278 | + fatal_lang_error('locked_by_admin', 'user'); |
|
279 | + } |
|
265 | 280 | // A moderator *is* locking it. |
266 | - elseif ($voting_locked == '0' && allowedTo('moderate_board')) |
|
267 | - $voting_locked = '2'; |
|
281 | + elseif ($voting_locked == '0' && allowedTo('moderate_board')) { |
|
282 | + $voting_locked = '2'; |
|
283 | + } |
|
268 | 284 | // Well, it's gonna be locked one way or another otherwise... |
269 | - else |
|
270 | - $voting_locked = '1'; |
|
285 | + else { |
|
286 | + $voting_locked = '1'; |
|
287 | + } |
|
271 | 288 | |
272 | 289 | // Lock! *Poof* - no one can vote. |
273 | 290 | $smcFunc['db_query']('', ' |
@@ -302,8 +319,9 @@ discard block |
||
302 | 319 | { |
303 | 320 | global $txt, $user_info, $context, $topic, $board, $smcFunc, $sourcedir, $scripturl; |
304 | 321 | |
305 | - if (empty($topic)) |
|
306 | - fatal_lang_error('no_access', false); |
|
322 | + if (empty($topic)) { |
|
323 | + fatal_lang_error('no_access', false); |
|
324 | + } |
|
307 | 325 | |
308 | 326 | loadLanguage('Post'); |
309 | 327 | loadTemplate('Poll'); |
@@ -327,24 +345,28 @@ discard block |
||
327 | 345 | ); |
328 | 346 | |
329 | 347 | // Assume the the topic exists, right? |
330 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
331 | - fatal_lang_error('no_board'); |
|
348 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
349 | + fatal_lang_error('no_board'); |
|
350 | + } |
|
332 | 351 | // Get the poll information. |
333 | 352 | $pollinfo = $smcFunc['db_fetch_assoc']($request); |
334 | 353 | $smcFunc['db_free_result']($request); |
335 | 354 | |
336 | 355 | // If we are adding a new poll - make sure that there isn't already a poll there. |
337 | - if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) |
|
338 | - fatal_lang_error('poll_already_exists'); |
|
356 | + if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) { |
|
357 | + fatal_lang_error('poll_already_exists'); |
|
358 | + } |
|
339 | 359 | // Otherwise, if we're editing it, it does exist I assume? |
340 | - elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) |
|
341 | - fatal_lang_error('poll_not_found'); |
|
360 | + elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) { |
|
361 | + fatal_lang_error('poll_not_found'); |
|
362 | + } |
|
342 | 363 | |
343 | 364 | // Can you do this? |
344 | - if ($context['is_edit'] && !allowedTo('poll_edit_any')) |
|
345 | - isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
|
346 | - elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) |
|
347 | - isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any')); |
|
365 | + if ($context['is_edit'] && !allowedTo('poll_edit_any')) { |
|
366 | + isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
|
367 | + } elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) { |
|
368 | + isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any')); |
|
369 | + } |
|
348 | 370 | $context['can_moderate_poll'] = isset($_REQUEST['add']) ? true : allowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any')); |
349 | 371 | |
350 | 372 | // Do we enable guest voting? |
@@ -386,12 +408,14 @@ discard block |
||
386 | 408 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
387 | 409 | { |
388 | 410 | // Get the highest id so we can add more without reusing. |
389 | - if ($row['id_choice'] >= $last_id) |
|
390 | - $last_id = $row['id_choice'] + 1; |
|
411 | + if ($row['id_choice'] >= $last_id) { |
|
412 | + $last_id = $row['id_choice'] + 1; |
|
413 | + } |
|
391 | 414 | |
392 | 415 | // They cleared this by either omitting it or emptying it. |
393 | - if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') |
|
394 | - continue; |
|
416 | + if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') { |
|
417 | + continue; |
|
418 | + } |
|
395 | 419 | |
396 | 420 | censorText($row['label']); |
397 | 421 | |
@@ -409,9 +433,10 @@ discard block |
||
409 | 433 | |
410 | 434 | // Work out how many options we have, so we get the 'is_last' field right... |
411 | 435 | $totalPostOptions = 0; |
412 | - foreach ($_POST['options'] as $id => $label) |
|
413 | - if ($label != '') |
|
436 | + foreach ($_POST['options'] as $id => $label) { |
|
437 | + if ($label != '') |
|
414 | 438 | $totalPostOptions++; |
439 | + } |
|
415 | 440 | |
416 | 441 | $count = 1; |
417 | 442 | // If an option exists, update it. If it is new, add it - but don't reuse ids! |
@@ -420,30 +445,32 @@ discard block |
||
420 | 445 | $label = $smcFunc['htmlspecialchars']($label); |
421 | 446 | censorText($label); |
422 | 447 | |
423 | - if (isset($context['choices'][$id])) |
|
424 | - $context['choices'][$id]['label'] = $label; |
|
425 | - elseif ($label != '') |
|
426 | - $context['choices'][] = array( |
|
448 | + if (isset($context['choices'][$id])) { |
|
449 | + $context['choices'][$id]['label'] = $label; |
|
450 | + } elseif ($label != '') { |
|
451 | + $context['choices'][] = array( |
|
427 | 452 | 'id' => $last_id++, |
428 | 453 | 'number' => $number++, |
429 | 454 | 'label' => $label, |
430 | 455 | 'votes' => -1, |
431 | 456 | 'is_last' => $count++ == $totalPostOptions && $totalPostOptions > 1 ? true : false, |
432 | 457 | ); |
458 | + } |
|
433 | 459 | } |
434 | 460 | |
435 | 461 | // Make sure we have two choices for sure! |
436 | 462 | if ($totalPostOptions < 2) |
437 | 463 | { |
438 | 464 | // Need two? |
439 | - if ($totalPostOptions == 0) |
|
440 | - $context['choices'][] = array( |
|
465 | + if ($totalPostOptions == 0) { |
|
466 | + $context['choices'][] = array( |
|
441 | 467 | 'id' => $last_id++, |
442 | 468 | 'number' => $number++, |
443 | 469 | 'label' => '', |
444 | 470 | 'votes' => -1, |
445 | 471 | 'is_last' => false |
446 | 472 | ); |
473 | + } |
|
447 | 474 | $poll_errors[] = 'poll_few'; |
448 | 475 | } |
449 | 476 | |
@@ -458,12 +485,14 @@ discard block |
||
458 | 485 | |
459 | 486 | $context['last_choice_id'] = $last_id; |
460 | 487 | |
461 | - if ($context['can_moderate_poll']) |
|
462 | - $context['poll']['expiration'] = $_POST['poll_expire']; |
|
488 | + if ($context['can_moderate_poll']) { |
|
489 | + $context['poll']['expiration'] = $_POST['poll_expire']; |
|
490 | + } |
|
463 | 491 | |
464 | 492 | // Check the question/option count for errors. |
465 | - if (trim($_POST['question']) == '' && empty($context['poll_error'])) |
|
466 | - $poll_errors[] = 'no_question'; |
|
493 | + if (trim($_POST['question']) == '' && empty($context['poll_error'])) { |
|
494 | + $poll_errors[] = 'no_question'; |
|
495 | + } |
|
467 | 496 | |
468 | 497 | // No check is needed, since nothing is really posted. |
469 | 498 | checkSubmitOnce('free'); |
@@ -480,8 +509,7 @@ discard block |
||
480 | 509 | $context['poll_error']['messages'][] = $txt['error_' . $poll_error]; |
481 | 510 | } |
482 | 511 | } |
483 | - } |
|
484 | - else |
|
512 | + } else |
|
485 | 513 | { |
486 | 514 | // Basic theme info... |
487 | 515 | $context['poll'] = array( |
@@ -596,18 +624,22 @@ discard block |
||
596 | 624 | global $user_info, $smcFunc, $sourcedir; |
597 | 625 | |
598 | 626 | // Sneaking off, are we? |
599 | - if (empty($_POST)) |
|
600 | - redirectexit('action=editpoll;topic=' . $topic . '.0'); |
|
627 | + if (empty($_POST)) { |
|
628 | + redirectexit('action=editpoll;topic=' . $topic . '.0'); |
|
629 | + } |
|
601 | 630 | |
602 | - if (checkSession('post', '', false) != '') |
|
603 | - $poll_errors[] = 'session_timeout'; |
|
631 | + if (checkSession('post', '', false) != '') { |
|
632 | + $poll_errors[] = 'session_timeout'; |
|
633 | + } |
|
604 | 634 | |
605 | - if (isset($_POST['preview'])) |
|
606 | - return EditPoll(); |
|
635 | + if (isset($_POST['preview'])) { |
|
636 | + return EditPoll(); |
|
637 | + } |
|
607 | 638 | |
608 | 639 | // HACKERS (!!) can't edit :P. |
609 | - if (empty($topic)) |
|
610 | - fatal_lang_error('no_access', false); |
|
640 | + if (empty($topic)) { |
|
641 | + fatal_lang_error('no_access', false); |
|
642 | + } |
|
611 | 643 | |
612 | 644 | // Is this a new poll, or editing an existing? |
613 | 645 | $isEdit = isset($_REQUEST['add']) ? 0 : 1; |
@@ -623,23 +655,27 @@ discard block |
||
623 | 655 | 'current_topic' => $topic, |
624 | 656 | ) |
625 | 657 | ); |
626 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
627 | - fatal_lang_error('no_board'); |
|
658 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
659 | + fatal_lang_error('no_board'); |
|
660 | + } |
|
628 | 661 | $bcinfo = $smcFunc['db_fetch_assoc']($request); |
629 | 662 | $smcFunc['db_free_result']($request); |
630 | 663 | |
631 | 664 | // Check their adding/editing is valid. |
632 | - if (!$isEdit && !empty($bcinfo['id_poll'])) |
|
633 | - fatal_lang_error('poll_already_exists'); |
|
665 | + if (!$isEdit && !empty($bcinfo['id_poll'])) { |
|
666 | + fatal_lang_error('poll_already_exists'); |
|
667 | + } |
|
634 | 668 | // Are we editing a poll which doesn't exist? |
635 | - elseif ($isEdit && empty($bcinfo['id_poll'])) |
|
636 | - fatal_lang_error('poll_not_found'); |
|
669 | + elseif ($isEdit && empty($bcinfo['id_poll'])) { |
|
670 | + fatal_lang_error('poll_not_found'); |
|
671 | + } |
|
637 | 672 | |
638 | 673 | // Check if they have the power to add or edit the poll. |
639 | - if ($isEdit && !allowedTo('poll_edit_any')) |
|
640 | - isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any')); |
|
641 | - elseif (!$isEdit && !allowedTo('poll_add_any')) |
|
642 | - isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any')); |
|
674 | + if ($isEdit && !allowedTo('poll_edit_any')) { |
|
675 | + isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any')); |
|
676 | + } elseif (!$isEdit && !allowedTo('poll_add_any')) { |
|
677 | + isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any')); |
|
678 | + } |
|
643 | 679 | |
644 | 680 | $optionCount = 0; |
645 | 681 | $idCount = 0; |
@@ -652,14 +688,16 @@ discard block |
||
652 | 688 | $idCount = max($idCount, $k); |
653 | 689 | } |
654 | 690 | } |
655 | - if ($optionCount < 2) |
|
656 | - $poll_errors[] = 'poll_few'; |
|
657 | - elseif ($optionCount > 256 || $idCount > 255) |
|
658 | - $poll_errors[] = 'poll_many'; |
|
691 | + if ($optionCount < 2) { |
|
692 | + $poll_errors[] = 'poll_few'; |
|
693 | + } elseif ($optionCount > 256 || $idCount > 255) { |
|
694 | + $poll_errors[] = 'poll_many'; |
|
695 | + } |
|
659 | 696 | |
660 | 697 | // Also - ensure they are not removing the question. |
661 | - if (trim($_POST['question']) == '') |
|
662 | - $poll_errors[] = 'no_question'; |
|
698 | + if (trim($_POST['question']) == '') { |
|
699 | + $poll_errors[] = 'no_question'; |
|
700 | + } |
|
663 | 701 | |
664 | 702 | // Got any errors to report? |
665 | 703 | if (!empty($poll_errors)) |
@@ -695,8 +733,9 @@ discard block |
||
695 | 733 | { |
696 | 734 | require_once($sourcedir . '/Subs-Members.php'); |
697 | 735 | $allowedGroups = groupsAllowedTo('poll_vote', $board); |
698 | - if (!in_array(-1, $allowedGroups['allowed'])) |
|
699 | - $_POST['poll_guest_vote'] = 0; |
|
736 | + if (!in_array(-1, $allowedGroups['allowed'])) { |
|
737 | + $_POST['poll_guest_vote'] = 0; |
|
738 | + } |
|
700 | 739 | } |
701 | 740 | |
702 | 741 | // Ensure that the number options allowed makes sense, and the expiration date is valid. |
@@ -704,17 +743,19 @@ discard block |
||
704 | 743 | { |
705 | 744 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
706 | 745 | |
707 | - if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
708 | - $_POST['poll_hide'] = 1; |
|
709 | - elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) |
|
710 | - $_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24; |
|
711 | - else |
|
712 | - $_POST['poll_expire'] = $bcinfo['expire_time']; |
|
746 | + if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
747 | + $_POST['poll_hide'] = 1; |
|
748 | + } elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) { |
|
749 | + $_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24; |
|
750 | + } else { |
|
751 | + $_POST['poll_expire'] = $bcinfo['expire_time']; |
|
752 | + } |
|
713 | 753 | |
714 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
715 | - $_POST['poll_max_votes'] = 1; |
|
716 | - else |
|
717 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
754 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
755 | + $_POST['poll_max_votes'] = 1; |
|
756 | + } else { |
|
757 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
758 | + } |
|
718 | 759 | } |
719 | 760 | |
720 | 761 | // If we're editing, let's commit the changes. |
@@ -779,8 +820,9 @@ discard block |
||
779 | 820 | ) |
780 | 821 | ); |
781 | 822 | $choices = array(); |
782 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
783 | - $choices[] = $row['id_choice']; |
|
823 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
824 | + $choices[] = $row['id_choice']; |
|
825 | + } |
|
784 | 826 | $smcFunc['db_free_result']($request); |
785 | 827 | |
786 | 828 | $delete_options = array(); |
@@ -793,8 +835,9 @@ discard block |
||
793 | 835 | if (trim($option) == '') |
794 | 836 | { |
795 | 837 | // They want it deleted. Bye. |
796 | - if (in_array($k, $choices)) |
|
797 | - $delete_options[] = $k; |
|
838 | + if (in_array($k, $choices)) { |
|
839 | + $delete_options[] = $k; |
|
840 | + } |
|
798 | 841 | |
799 | 842 | // Skip the rest... |
800 | 843 | continue; |
@@ -804,8 +847,8 @@ discard block |
||
804 | 847 | $option = $smcFunc['htmlspecialchars']($option); |
805 | 848 | |
806 | 849 | // If it's already there, update it. If it's not... add it. |
807 | - if (in_array($k, $choices)) |
|
808 | - $smcFunc['db_query']('', ' |
|
850 | + if (in_array($k, $choices)) { |
|
851 | + $smcFunc['db_query']('', ' |
|
809 | 852 | UPDATE {db_prefix}poll_choices |
810 | 853 | SET label = {string:option_name} |
811 | 854 | WHERE id_poll = {int:id_poll} |
@@ -816,8 +859,8 @@ discard block |
||
816 | 859 | 'option_name' => $option, |
817 | 860 | ) |
818 | 861 | ); |
819 | - else |
|
820 | - $smcFunc['db_insert']('', |
|
862 | + } else { |
|
863 | + $smcFunc['db_insert']('', |
|
821 | 864 | '{db_prefix}poll_choices', |
822 | 865 | array( |
823 | 866 | 'id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255', 'votes' => 'int', |
@@ -827,6 +870,7 @@ discard block |
||
827 | 870 | ), |
828 | 871 | array() |
829 | 872 | ); |
873 | + } |
|
830 | 874 | } |
831 | 875 | |
832 | 876 | // I'm sorry, but... well, no one was choosing you. Poor options, I'll put you out of your misery. |
@@ -892,13 +936,11 @@ discard block |
||
892 | 936 | { |
893 | 937 | // Added a poll |
894 | 938 | logAction('add_poll', array('topic' => $topic)); |
895 | - } |
|
896 | - elseif (isset($_REQUEST['deletevotes'])) |
|
939 | + } elseif (isset($_REQUEST['deletevotes'])) |
|
897 | 940 | { |
898 | 941 | // Reset votes |
899 | 942 | logAction('reset_poll', array('topic' => $topic)); |
900 | - } |
|
901 | - else |
|
943 | + } else |
|
902 | 944 | { |
903 | 945 | // Something else |
904 | 946 | logAction('editpoll', array('topic' => $topic)); |
@@ -921,8 +963,9 @@ discard block |
||
921 | 963 | global $topic, $user_info, $smcFunc; |
922 | 964 | |
923 | 965 | // Make sure the topic is not empty. |
924 | - if (empty($topic)) |
|
925 | - fatal_lang_error('no_access', false); |
|
966 | + if (empty($topic)) { |
|
967 | + fatal_lang_error('no_access', false); |
|
968 | + } |
|
926 | 969 | |
927 | 970 | // Verify the session. |
928 | 971 | checkSession('get'); |
@@ -940,8 +983,9 @@ discard block |
||
940 | 983 | 'current_topic' => $topic, |
941 | 984 | ) |
942 | 985 | ); |
943 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
944 | - fatal_lang_error('no_access', false); |
|
986 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
987 | + fatal_lang_error('no_access', false); |
|
988 | + } |
|
945 | 989 | list ($topicStarter, $pollStarter) = $smcFunc['db_fetch_row']($request); |
946 | 990 | $smcFunc['db_free_result']($request); |
947 | 991 |
@@ -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 | * Get a list of versions that are currently installed on the server. |
@@ -45,8 +46,7 @@ discard block |
||
45 | 46 | $temp2 = $temp->getVersion(); |
46 | 47 | $im_version = $temp2['versionString']; |
47 | 48 | $extension_version = 'Imagick ' . phpversion('Imagick'); |
48 | - } |
|
49 | - else |
|
49 | + } else |
|
50 | 50 | { |
51 | 51 | $im_version = MagickGetVersionString(); |
52 | 52 | $extension_version = 'MagickWand ' . phpversion('MagickWand'); |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | if (in_array('db_server', $checkFor)) |
62 | 62 | { |
63 | 63 | db_extend(); |
64 | - if (!isset($db_connection) || $db_connection === false) |
|
65 | - trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
66 | - else |
|
64 | + if (!isset($db_connection) || $db_connection === false) { |
|
65 | + trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE); |
|
66 | + } else |
|
67 | 67 | { |
68 | 68 | $versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => ''); |
69 | 69 | $versions['db_engine']['version'] = $smcFunc['db_get_engine'](); |
@@ -74,24 +74,31 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | // If we're using memcache we need the server info. |
77 | - if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') |
|
78 | - get_memcached_server(); |
|
77 | + if (empty($memcached) && function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { |
|
78 | + get_memcached_server(); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | // Check to see if we have any accelerators installed... |
81 | - if (in_array('phpa', $checkFor) && isset($_PHPA)) |
|
82 | - $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
83 | - if (in_array('apc', $checkFor) && extension_loaded('apc')) |
|
84 | - $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
85 | - if (in_array('memcache', $checkFor) && function_exists('memcache_set')) |
|
86 | - $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
87 | - if (in_array('xcache', $checkFor) && function_exists('xcache_set')) |
|
88 | - $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
82 | + if (in_array('phpa', $checkFor) && isset($_PHPA)) { |
|
83 | + $versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']); |
|
84 | + } |
|
85 | + if (in_array('apc', $checkFor) && extension_loaded('apc')) { |
|
86 | + $versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc')); |
|
87 | + } |
|
88 | + if (in_array('memcache', $checkFor) && function_exists('memcache_set')) { |
|
89 | + $versions['memcache'] = array('title' => 'Memcached', 'version' => empty($memcached) ? '???' : memcache_get_version($memcached)); |
|
90 | + } |
|
91 | + if (in_array('xcache', $checkFor) && function_exists('xcache_set')) { |
|
92 | + $versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION); |
|
93 | + } |
|
89 | 94 | |
90 | - if (in_array('php', $checkFor)) |
|
91 | - $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
95 | + if (in_array('php', $checkFor)) { |
|
96 | + $versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo'); |
|
97 | + } |
|
92 | 98 | |
93 | - if (in_array('server', $checkFor)) |
|
94 | - $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
99 | + if (in_array('server', $checkFor)) { |
|
100 | + $versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | return $versions; |
97 | 104 | } |
@@ -131,11 +138,13 @@ discard block |
||
131 | 138 | fclose($fp); |
132 | 139 | |
133 | 140 | // The comment looks rougly like... that. |
134 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
135 | - $version_info['file_versions']['SSI.php'] = $match[1]; |
|
141 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
142 | + $version_info['file_versions']['SSI.php'] = $match[1]; |
|
143 | + } |
|
136 | 144 | // Not found! This is bad. |
137 | - else |
|
138 | - $version_info['file_versions']['SSI.php'] = '??'; |
|
145 | + else { |
|
146 | + $version_info['file_versions']['SSI.php'] = '??'; |
|
147 | + } |
|
139 | 148 | } |
140 | 149 | |
141 | 150 | // Do the paid subscriptions handler? |
@@ -146,11 +155,13 @@ discard block |
||
146 | 155 | fclose($fp); |
147 | 156 | |
148 | 157 | // Found it? |
149 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
150 | - $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
158 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
159 | + $version_info['file_versions']['subscriptions.php'] = $match[1]; |
|
160 | + } |
|
151 | 161 | // If we haven't how do we all get paid? |
152 | - else |
|
153 | - $version_info['file_versions']['subscriptions.php'] = '??'; |
|
162 | + else { |
|
163 | + $version_info['file_versions']['subscriptions.php'] = '??'; |
|
164 | + } |
|
154 | 165 | } |
155 | 166 | |
156 | 167 | // Load all the files in the Sources directory, except this file and the redirect. |
@@ -165,11 +176,13 @@ discard block |
||
165 | 176 | fclose($fp); |
166 | 177 | |
167 | 178 | // Look for the version comment in the file header. |
168 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
169 | - $version_info['file_versions'][$entry] = $match[1]; |
|
179 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
180 | + $version_info['file_versions'][$entry] = $match[1]; |
|
181 | + } |
|
170 | 182 | // It wasn't found, but the file was... show a '??'. |
171 | - else |
|
172 | - $version_info['file_versions'][$entry] = '??'; |
|
183 | + else { |
|
184 | + $version_info['file_versions'][$entry] = '??'; |
|
185 | + } |
|
173 | 186 | } |
174 | 187 | } |
175 | 188 | $sources_dir->close(); |
@@ -188,11 +201,13 @@ discard block |
||
188 | 201 | fclose($fp); |
189 | 202 | |
190 | 203 | // Look for the version comment in the file header. |
191 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
192 | - $version_info['tasks_versions'][$entry] = $match[1]; |
|
204 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
205 | + $version_info['tasks_versions'][$entry] = $match[1]; |
|
206 | + } |
|
193 | 207 | // It wasn't found, but the file was... show a '??'. |
194 | - else |
|
195 | - $version_info['tasks_versions'][$entry] = '??'; |
|
208 | + else { |
|
209 | + $version_info['tasks_versions'][$entry] = '??'; |
|
210 | + } |
|
196 | 211 | } |
197 | 212 | } |
198 | 213 | $tasks_dir->close(); |
@@ -200,8 +215,9 @@ discard block |
||
200 | 215 | |
201 | 216 | // Load all the files in the default template directory - and the current theme if applicable. |
202 | 217 | $directories = array('default_template_versions' => $settings['default_theme_dir']); |
203 | - if ($settings['theme_id'] != 1) |
|
204 | - $directories += array('template_versions' => $settings['theme_dir']); |
|
218 | + if ($settings['theme_id'] != 1) { |
|
219 | + $directories += array('template_versions' => $settings['theme_dir']); |
|
220 | + } |
|
205 | 221 | |
206 | 222 | foreach ($directories as $type => $dirname) |
207 | 223 | { |
@@ -216,11 +232,13 @@ discard block |
||
216 | 232 | fclose($fp); |
217 | 233 | |
218 | 234 | // Look for the version comment in the file header. |
219 | - if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) |
|
220 | - $version_info[$type][$entry] = $match[1]; |
|
235 | + if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) { |
|
236 | + $version_info[$type][$entry] = $match[1]; |
|
237 | + } |
|
221 | 238 | // It wasn't found, but the file was... show a '??'. |
222 | - else |
|
223 | - $version_info[$type][$entry] = '??'; |
|
239 | + else { |
|
240 | + $version_info[$type][$entry] = '??'; |
|
241 | + } |
|
224 | 242 | } |
225 | 243 | } |
226 | 244 | $this_dir->close(); |
@@ -241,11 +259,13 @@ discard block |
||
241 | 259 | list ($name, $language) = explode('.', $entry); |
242 | 260 | |
243 | 261 | // Look for the version comment in the file header. |
244 | - if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) |
|
245 | - $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
262 | + if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) { |
|
263 | + $version_info['default_language_versions'][$language][$name] = $match[1]; |
|
264 | + } |
|
246 | 265 | // It wasn't found, but the file was... show a '??'. |
247 | - else |
|
248 | - $version_info['default_language_versions'][$language][$name] = '??'; |
|
266 | + else { |
|
267 | + $version_info['default_language_versions'][$language][$name] = '??'; |
|
268 | + } |
|
249 | 269 | } |
250 | 270 | } |
251 | 271 | $this_dir->close(); |
@@ -260,8 +280,9 @@ discard block |
||
260 | 280 | ksort($version_info['tasks_versions']); |
261 | 281 | |
262 | 282 | // For languages sort each language too. |
263 | - foreach ($version_info['default_language_versions'] as $language => $dummy) |
|
264 | - ksort($version_info['default_language_versions'][$language]); |
|
283 | + foreach ($version_info['default_language_versions'] as $language => $dummy) { |
|
284 | + ksort($version_info['default_language_versions'][$language]); |
|
285 | + } |
|
265 | 286 | } |
266 | 287 | return $version_info; |
267 | 288 | } |
@@ -303,27 +324,31 @@ discard block |
||
303 | 324 | $settingsArray = trim(file_get_contents($boarddir . '/Settings.php')); |
304 | 325 | |
305 | 326 | // Break it up based on \r or \n, and then clean out extra characters. |
306 | - if (strpos($settingsArray, "\n") !== false) |
|
307 | - $settingsArray = explode("\n", $settingsArray); |
|
308 | - elseif (strpos($settingsArray, "\r") !== false) |
|
309 | - $settingsArray = explode("\r", $settingsArray); |
|
310 | - else |
|
311 | - return; |
|
327 | + if (strpos($settingsArray, "\n") !== false) { |
|
328 | + $settingsArray = explode("\n", $settingsArray); |
|
329 | + } elseif (strpos($settingsArray, "\r") !== false) { |
|
330 | + $settingsArray = explode("\r", $settingsArray); |
|
331 | + } else { |
|
332 | + return; |
|
333 | + } |
|
312 | 334 | |
313 | 335 | // Presumably, the file has to have stuff in it for this function to be called :P. |
314 | - if (count($settingsArray) < 10) |
|
315 | - return; |
|
336 | + if (count($settingsArray) < 10) { |
|
337 | + return; |
|
338 | + } |
|
316 | 339 | |
317 | 340 | // remove any /r's that made there way in here |
318 | - foreach ($settingsArray as $k => $dummy) |
|
319 | - $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
341 | + foreach ($settingsArray as $k => $dummy) { |
|
342 | + $settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n"; |
|
343 | + } |
|
320 | 344 | |
321 | 345 | // go line by line and see whats changing |
322 | 346 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
323 | 347 | { |
324 | 348 | // Don't trim or bother with it if it's not a variable. |
325 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
326 | - continue; |
|
349 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
350 | + continue; |
|
351 | + } |
|
327 | 352 | |
328 | 353 | $settingsArray[$i] = trim($settingsArray[$i]) . "\n"; |
329 | 354 | |
@@ -335,8 +360,7 @@ discard block |
||
335 | 360 | { |
336 | 361 | updateDbLastError($val); |
337 | 362 | unset($config_vars[$var]); |
338 | - } |
|
339 | - elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
363 | + } elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
340 | 364 | { |
341 | 365 | $comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#'); |
342 | 366 | $settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n"; |
@@ -347,34 +371,39 @@ discard block |
||
347 | 371 | } |
348 | 372 | |
349 | 373 | // End of the file ... maybe |
350 | - if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') |
|
351 | - $end = $i; |
|
374 | + if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') { |
|
375 | + $end = $i; |
|
376 | + } |
|
352 | 377 | } |
353 | 378 | |
354 | 379 | // This should never happen, but apparently it is happening. |
355 | - if (empty($end) || $end < 10) |
|
356 | - $end = count($settingsArray) - 1; |
|
380 | + if (empty($end) || $end < 10) { |
|
381 | + $end = count($settingsArray) - 1; |
|
382 | + } |
|
357 | 383 | |
358 | 384 | // Still more variables to go? Then lets add them at the end. |
359 | 385 | if (!empty($config_vars)) |
360 | 386 | { |
361 | - if (trim($settingsArray[$end]) == '?' . '>') |
|
362 | - $settingsArray[$end++] = ''; |
|
363 | - else |
|
364 | - $end++; |
|
387 | + if (trim($settingsArray[$end]) == '?' . '>') { |
|
388 | + $settingsArray[$end++] = ''; |
|
389 | + } else { |
|
390 | + $end++; |
|
391 | + } |
|
365 | 392 | |
366 | 393 | // Add in any newly defined vars that were passed |
367 | - foreach ($config_vars as $var => $val) |
|
368 | - $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
394 | + foreach ($config_vars as $var => $val) { |
|
395 | + $settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n"; |
|
396 | + } |
|
369 | 397 | |
370 | 398 | $settingsArray[$end] = '?' . '>'; |
399 | + } else { |
|
400 | + $settingsArray[$end] = trim($settingsArray[$end]); |
|
371 | 401 | } |
372 | - else |
|
373 | - $settingsArray[$end] = trim($settingsArray[$end]); |
|
374 | 402 | |
375 | 403 | // Sanity error checking: the file needs to be at least 12 lines. |
376 | - if (count($settingsArray) < 12) |
|
377 | - return; |
|
404 | + if (count($settingsArray) < 12) { |
|
405 | + return; |
|
406 | + } |
|
378 | 407 | |
379 | 408 | // Try to avoid a few pitfalls: |
380 | 409 | // - like a possible race condition, |
@@ -382,8 +411,9 @@ discard block |
||
382 | 411 | // |
383 | 412 | // Check before you act: if cache is enabled, we can do a simple write test |
384 | 413 | // to validate that we even write things on this filesystem. |
385 | - if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
386 | - $cachedir = $boarddir . '/cache'; |
|
414 | + if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
415 | + $cachedir = $boarddir . '/cache'; |
|
416 | + } |
|
387 | 417 | |
388 | 418 | $test_fp = @fopen($cachedir . '/settings_update.tmp', "w+"); |
389 | 419 | if ($test_fp) |
@@ -418,16 +448,18 @@ discard block |
||
418 | 448 | // Well this is not good at all, lets see if we can save this |
419 | 449 | $context['settings_message'] = 'settings_error'; |
420 | 450 | |
421 | - if (file_exists($boarddir . '/Settings_bak.php')) |
|
422 | - @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
451 | + if (file_exists($boarddir . '/Settings_bak.php')) { |
|
452 | + @copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php'); |
|
453 | + } |
|
423 | 454 | } |
424 | 455 | } |
425 | 456 | |
426 | 457 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
427 | 458 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
428 | - if (function_exists('opcache_invalidate')) |
|
429 | - opcache_invalidate($boarddir . '/Settings.php', true); |
|
430 | -} |
|
459 | + if (function_exists('opcache_invalidate')) { |
|
460 | + opcache_invalidate($boarddir . '/Settings.php', true); |
|
461 | + } |
|
462 | + } |
|
431 | 463 | |
432 | 464 | /** |
433 | 465 | * Saves the time of the last db error for the error log |
@@ -453,8 +485,9 @@ discard block |
||
453 | 485 | global $options, $context, $smcFunc, $settings, $user_info; |
454 | 486 | |
455 | 487 | // This must exist! |
456 | - if (!isset($context['admin_preferences'])) |
|
457 | - return false; |
|
488 | + if (!isset($context['admin_preferences'])) { |
|
489 | + return false; |
|
490 | + } |
|
458 | 491 | |
459 | 492 | // This is what we'll be saving. |
460 | 493 | $options['admin_preferences'] = json_encode($context['admin_preferences']); |
@@ -518,8 +551,9 @@ discard block |
||
518 | 551 | $emails_sent = array(); |
519 | 552 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
520 | 553 | { |
521 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
522 | - continue; |
|
554 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
555 | + continue; |
|
556 | + } |
|
523 | 557 | |
524 | 558 | // Stick their particulars in the replacement data. |
525 | 559 | $replacements['IDMEMBER'] = $row['id_member']; |
@@ -538,11 +572,12 @@ discard block |
||
538 | 572 | $smcFunc['db_free_result']($request); |
539 | 573 | |
540 | 574 | // Any additional users we must email this to? |
541 | - if (!empty($additional_recipients)) |
|
542 | - foreach ($additional_recipients as $recipient) |
|
575 | + if (!empty($additional_recipients)) { |
|
576 | + foreach ($additional_recipients as $recipient) |
|
543 | 577 | { |
544 | 578 | if (in_array($recipient['email'], $emails_sent)) |
545 | 579 | continue; |
580 | + } |
|
546 | 581 | |
547 | 582 | $replacements['IDMEMBER'] = $recipient['id']; |
548 | 583 | $replacements['REALNAME'] = $recipient['name']; |
@@ -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 | * Entry point function, permission checks, admin bars, etc. |
@@ -99,27 +100,27 @@ discard block |
||
99 | 100 | 'function' => function($rowData) use ($scripturl) |
100 | 101 | { |
101 | 102 | // Since the moderator group has no explicit members, no link is needed. |
102 | - if ($rowData['id_group'] == 3) |
|
103 | - $group_name = $rowData['group_name']; |
|
104 | - else |
|
103 | + if ($rowData['id_group'] == 3) { |
|
104 | + $group_name = $rowData['group_name']; |
|
105 | + } else |
|
105 | 106 | { |
106 | 107 | $color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
107 | 108 | |
108 | 109 | if (allowedTo('manage_membergroups')) |
109 | 110 | { |
110 | 111 | $group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
111 | - } |
|
112 | - else |
|
112 | + } else |
|
113 | 113 | { |
114 | 114 | $group_name = sprintf('<a href="%1$s?action=groups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Add a help option for moderator and administrator. |
119 | - if ($rowData['id_group'] == 1) |
|
120 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
121 | - elseif ($rowData['id_group'] == 3) |
|
122 | - $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
119 | + if ($rowData['id_group'] == 1) { |
|
120 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
121 | + } elseif ($rowData['id_group'] == 3) { |
|
122 | + $group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
|
123 | + } |
|
123 | 124 | |
124 | 125 | return $group_name; |
125 | 126 | }, |
@@ -198,8 +199,9 @@ discard block |
||
198 | 199 | $_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; |
199 | 200 | |
200 | 201 | // No browsing of guests, membergroup 0 or moderators. |
201 | - if (in_array($_REQUEST['group'], array(-1, 0, 3))) |
|
202 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
202 | + if (in_array($_REQUEST['group'], array(-1, 0, 3))) { |
|
203 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
204 | + } |
|
203 | 205 | |
204 | 206 | // Load up the group details. |
205 | 207 | $request = $smcFunc['db_query']('', ' |
@@ -214,8 +216,9 @@ discard block |
||
214 | 216 | ) |
215 | 217 | ); |
216 | 218 | // Doesn't exist? |
217 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
218 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
219 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
220 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
221 | + } |
|
219 | 222 | $context['group'] = $smcFunc['db_fetch_assoc']($request); |
220 | 223 | $smcFunc['db_free_result']($request); |
221 | 224 | |
@@ -248,21 +251,25 @@ discard block |
||
248 | 251 | 'name' => $row['real_name'] |
249 | 252 | ); |
250 | 253 | |
251 | - if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) |
|
252 | - $context['group']['can_moderate'] = true; |
|
254 | + if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) { |
|
255 | + $context['group']['can_moderate'] = true; |
|
256 | + } |
|
253 | 257 | } |
254 | 258 | $smcFunc['db_free_result']($request); |
255 | 259 | |
256 | 260 | // If this group is hidden then it can only "exists" if the user can moderate it! |
257 | - if ($context['group']['hidden'] && !$context['group']['can_moderate']) |
|
258 | - fatal_lang_error('membergroup_does_not_exist', false); |
|
261 | + if ($context['group']['hidden'] && !$context['group']['can_moderate']) { |
|
262 | + fatal_lang_error('membergroup_does_not_exist', false); |
|
263 | + } |
|
259 | 264 | |
260 | 265 | // You can only assign membership if you are the moderator and/or can manage groups! |
261 | - if (!$context['group']['can_moderate']) |
|
262 | - $context['group']['assignable'] = 0; |
|
266 | + if (!$context['group']['can_moderate']) { |
|
267 | + $context['group']['assignable'] = 0; |
|
268 | + } |
|
263 | 269 | // Non-admins cannot assign admins. |
264 | - elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) |
|
265 | - $context['group']['assignable'] = 0; |
|
270 | + elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) { |
|
271 | + $context['group']['assignable'] = 0; |
|
272 | + } |
|
266 | 273 | |
267 | 274 | // Removing member from group? |
268 | 275 | if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable']) |
@@ -271,8 +278,9 @@ discard block |
||
271 | 278 | validateToken('mod-mgm'); |
272 | 279 | |
273 | 280 | // Make sure we're dealing with integers only. |
274 | - foreach ($_REQUEST['rem'] as $key => $group) |
|
275 | - $_REQUEST['rem'][$key] = (int) $group; |
|
281 | + foreach ($_REQUEST['rem'] as $key => $group) { |
|
282 | + $_REQUEST['rem'][$key] = (int) $group; |
|
283 | + } |
|
276 | 284 | |
277 | 285 | require_once($sourcedir . '/Subs-Membergroups.php'); |
278 | 286 | removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true); |
@@ -295,16 +303,18 @@ discard block |
||
295 | 303 | { |
296 | 304 | $member_names[$index] = trim($smcFunc['strtolower']($member_names[$index])); |
297 | 305 | |
298 | - if (strlen($member_names[$index]) == 0) |
|
299 | - unset($member_names[$index]); |
|
306 | + if (strlen($member_names[$index]) == 0) { |
|
307 | + unset($member_names[$index]); |
|
308 | + } |
|
300 | 309 | } |
301 | 310 | |
302 | 311 | // Any passed by ID? |
303 | 312 | $member_ids = array(); |
304 | - if (!empty($_REQUEST['member_add'])) |
|
305 | - foreach ($_REQUEST['member_add'] as $id) |
|
313 | + if (!empty($_REQUEST['member_add'])) { |
|
314 | + foreach ($_REQUEST['member_add'] as $id) |
|
306 | 315 | if ($id > 0) |
307 | 316 | $member_ids[] = (int) $id; |
317 | + } |
|
308 | 318 | |
309 | 319 | // Construct the query pelements. |
310 | 320 | if (!empty($member_ids)) |
@@ -332,8 +342,9 @@ discard block |
||
332 | 342 | 'id_group' => $_REQUEST['group'], |
333 | 343 | )) |
334 | 344 | ); |
335 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
336 | - $members[] = $row['id_member']; |
|
345 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
346 | + $members[] = $row['id_member']; |
|
347 | + } |
|
337 | 348 | $smcFunc['db_free_result']($request); |
338 | 349 | } |
339 | 350 | |
@@ -372,10 +383,11 @@ discard block |
||
372 | 383 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
373 | 384 | |
374 | 385 | // The where on the query is interesting. Non-moderators should only see people who are in this group as primary. |
375 | - if ($context['group']['can_moderate']) |
|
376 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
377 | - else |
|
378 | - $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
386 | + if ($context['group']['can_moderate']) { |
|
387 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
|
388 | + } else { |
|
389 | + $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
|
390 | + } |
|
379 | 391 | |
380 | 392 | // Count members of the group. |
381 | 393 | $request = $smcFunc['db_query']('', ' |
@@ -416,8 +428,9 @@ discard block |
||
416 | 428 | $last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']); |
417 | 429 | |
418 | 430 | // Italicize the online note if they aren't activated. |
419 | - if ($row['is_activated'] % 10 != 1) |
|
420 | - $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
431 | + if ($row['is_activated'] % 10 != 1) { |
|
432 | + $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
|
433 | + } |
|
421 | 434 | |
422 | 435 | $context['members'][] = array( |
423 | 436 | 'id' => $row['id_member'], |
@@ -437,9 +450,10 @@ discard block |
||
437 | 450 | $context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name']; |
438 | 451 | createToken('mod-mgm'); |
439 | 452 | |
440 | - if ($context['group']['assignable']) |
|
441 | - loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
442 | -} |
|
453 | + if ($context['group']['assignable']) { |
|
454 | + loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest'); |
|
455 | + } |
|
456 | + } |
|
443 | 457 | |
444 | 458 | /** |
445 | 459 | * Show and manage all group requests. |
@@ -453,16 +467,18 @@ discard block |
||
453 | 467 | $context['sub_template'] = 'show_list'; |
454 | 468 | |
455 | 469 | // Verify we can be here. |
456 | - if ($user_info['mod_cache']['gq'] == '0=1') |
|
457 | - isAllowedTo('manage_membergroups'); |
|
470 | + if ($user_info['mod_cache']['gq'] == '0=1') { |
|
471 | + isAllowedTo('manage_membergroups'); |
|
472 | + } |
|
458 | 473 | |
459 | 474 | // Normally, we act normally... |
460 | 475 | $where = ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']); |
461 | 476 | |
462 | - if (isset($_GET['closed'])) |
|
463 | - $where .= ' AND lgr.status != {int:status_open}'; |
|
464 | - else |
|
465 | - $where .= ' AND lgr.status = {int:status_open}'; |
|
477 | + if (isset($_GET['closed'])) { |
|
478 | + $where .= ' AND lgr.status != {int:status_open}'; |
|
479 | + } else { |
|
480 | + $where .= ' AND lgr.status = {int:status_open}'; |
|
481 | + } |
|
466 | 482 | |
467 | 483 | $where_parameters = array( |
468 | 484 | 'status_open' => 0, |
@@ -475,8 +491,9 @@ discard block |
||
475 | 491 | validateToken('mod-gr'); |
476 | 492 | |
477 | 493 | // Clean the values. |
478 | - foreach ($_POST['groupr'] as $k => $request) |
|
479 | - $_POST['groupr'][$k] = (int) $request; |
|
494 | + foreach ($_POST['groupr'] as $k => $request) { |
|
495 | + $_POST['groupr'][$k] = (int) $request; |
|
496 | + } |
|
480 | 497 | |
481 | 498 | $log_changes = array(); |
482 | 499 | |
@@ -513,8 +530,8 @@ discard block |
||
513 | 530 | $request_list = array(); |
514 | 531 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
515 | 532 | { |
516 | - if (!isset($log_changes[$row['id_request']])) |
|
517 | - $log_changes[$row['id_request']] = array( |
|
533 | + if (!isset($log_changes[$row['id_request']])) { |
|
534 | + $log_changes[$row['id_request']] = array( |
|
518 | 535 | 'id_request' => $row['id_request'], |
519 | 536 | 'status' => $_POST['req_action'] == 'approve' ? 1 : 2, // 1 = approved, 2 = rejected |
520 | 537 | 'id_member_acted' => $user_info['id'], |
@@ -522,6 +539,7 @@ discard block |
||
522 | 539 | 'time_acted' => time(), |
523 | 540 | 'act_reason' => $_POST['req_action'] != 'approve' && !empty($_POST['groupreason']) && !empty($_POST['groupreason'][$row['id_request']]) ? $smcFunc['htmlspecialchars']($_POST['groupreason'][$row['id_request']], ENT_QUOTES) : '', |
524 | 541 | ); |
542 | + } |
|
525 | 543 | $request_list[] = $row['id_request']; |
526 | 544 | } |
527 | 545 | $smcFunc['db_free_result']($request); |
@@ -744,21 +762,24 @@ discard block |
||
744 | 762 | $group_requests = array(); |
745 | 763 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
746 | 764 | { |
747 | - if (empty($row['reason'])) |
|
748 | - $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
749 | - else |
|
750 | - $reason = censorText($row['reason']); |
|
765 | + if (empty($row['reason'])) { |
|
766 | + $reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
|
767 | + } else { |
|
768 | + $reason = censorText($row['reason']); |
|
769 | + } |
|
751 | 770 | |
752 | 771 | if (isset($_GET['closed'])) |
753 | 772 | { |
754 | - if ($row['status'] == 1) |
|
755 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
756 | - elseif ($row['status'] == 2) |
|
757 | - $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
773 | + if ($row['status'] == 1) { |
|
774 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
|
775 | + } elseif ($row['status'] == 2) { |
|
776 | + $reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
|
777 | + } |
|
758 | 778 | |
759 | 779 | $reason .= ' (' . timeformat($row['time_acted']) . ')'; |
760 | - if (!empty($row['act_reason'])) |
|
761 | - $reason .= '<br><br>' . censorText($row['act_reason']); |
|
780 | + if (!empty($row['act_reason'])) { |
|
781 | + $reason .= '<br><br>' . censorText($row['act_reason']); |
|
782 | + } |
|
762 | 783 | } |
763 | 784 | |
764 | 785 | $group_requests[] = array( |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | ); |
92 | 93 | |
93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
94 | - if (empty($modSettings['messageIcons_enable'])) |
|
95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
97 | + } |
|
96 | 98 | if (empty($modSettings['smiley_enable'])) |
97 | 99 | { |
98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
126 | 128 | |
127 | 129 | $smiley_context = array(); |
128 | - foreach ($smiley_sets as $i => $set) |
|
129 | - $smiley_context[$set] = $set_names[$i]; |
|
130 | + foreach ($smiley_sets as $i => $set) { |
|
131 | + $smiley_context[$set] = $set_names[$i]; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | // All the settings for the page... |
132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
147 | 150 | |
148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
149 | 152 | |
150 | - if ($return_config) |
|
151 | - return $config_vars; |
|
153 | + if ($return_config) { |
|
154 | + return $config_vars; |
|
155 | + } |
|
152 | 156 | |
153 | 157 | // Setup the basics of the settings template. |
154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
208 | 212 | { |
209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
211 | - unset($set_paths[$id], $set_names[$id]); |
|
214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
215 | + unset($set_paths[$id], $set_names[$id]); |
|
216 | + } |
|
212 | 217 | } |
213 | 218 | |
214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
222 | 227 | )); |
223 | 228 | } |
224 | 229 | // Add a new smiley set. |
225 | - elseif (!empty($_POST['add'])) |
|
226 | - $context['sub_action'] = 'modifyset'; |
|
230 | + elseif (!empty($_POST['add'])) { |
|
231 | + $context['sub_action'] = 'modifyset'; |
|
232 | + } |
|
227 | 233 | // Create or modify a smiley set. |
228 | 234 | elseif (isset($_POST['set'])) |
229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
233 | 239 | // Create a new smiley set. |
234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
235 | 241 | { |
236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
237 | - fatal_lang_error('smiley_set_already_exists'); |
|
242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
243 | + fatal_lang_error('smiley_set_already_exists'); |
|
244 | + } |
|
238 | 245 | |
239 | 246 | updateSettings(array( |
240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
246 | 253 | else |
247 | 254 | { |
248 | 255 | // Make sure the smiley set exists. |
249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
250 | - fatal_lang_error('smiley_set_not_found'); |
|
256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
257 | + fatal_lang_error('smiley_set_not_found'); |
|
258 | + } |
|
251 | 259 | |
252 | 260 | // Make sure the path is not yet used by another smileyset. |
253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
263 | + } |
|
255 | 264 | |
256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
263 | 272 | } |
264 | 273 | |
265 | 274 | // The user might have checked to also import smileys. |
266 | - if (!empty($_POST['smiley_sets_import'])) |
|
267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
277 | + } |
|
268 | 278 | } |
269 | 279 | cache_put_data('parsing_smileys', null, 480); |
270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
273 | 283 | // Load all available smileysets... |
274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
277 | - $context['smiley_sets'][$i] = array( |
|
286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
287 | + $context['smiley_sets'][$i] = array( |
|
278 | 288 | 'id' => $i, |
279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
282 | 292 | ); |
293 | + } |
|
283 | 294 | |
284 | 295 | // Importing any smileys from an existing set? |
285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
290 | 301 | $_GET['set'] = (int) $_GET['set']; |
291 | 302 | |
292 | 303 | // Sanity check - then import. |
293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
306 | + } |
|
295 | 307 | |
296 | 308 | // Force the process to continue. |
297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
301 | 313 | if ($context['sub_action'] == 'modifyset') |
302 | 314 | { |
303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
305 | - $context['current_set'] = array( |
|
316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
317 | + $context['current_set'] = array( |
|
306 | 318 | 'id' => '-1', |
307 | 319 | 'path' => '', |
308 | 320 | 'name' => '', |
309 | 321 | 'selected' => false, |
310 | 322 | 'is_new' => true, |
311 | 323 | ); |
312 | - else |
|
324 | + } else |
|
313 | 325 | { |
314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
322 | 334 | while ($entry = $dir->read()) |
323 | 335 | { |
324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
325 | - $smileys[strtolower($entry)] = $entry; |
|
336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
337 | + $smileys[strtolower($entry)] = $entry; |
|
338 | + } |
|
326 | 339 | } |
327 | 340 | $dir->close(); |
328 | 341 | |
329 | - if (empty($smileys)) |
|
330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
342 | + if (empty($smileys)) { |
|
343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
344 | + } |
|
331 | 345 | |
332 | 346 | // Exclude the smileys that are already in the database. |
333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
338 | 352 | 'smiley_list' => $smileys, |
339 | 353 | ) |
340 | 354 | ); |
341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
343 | 357 | unset($smileys[strtolower($row['filename'])]); |
358 | + } |
|
344 | 359 | $smcFunc['db_free_result']($request); |
345 | 360 | |
346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
355 | 370 | $dir = dir($modSettings['smileys_dir']); |
356 | 371 | while ($entry = $dir->read()) |
357 | 372 | { |
358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
359 | - $context['smiley_set_dirs'][] = array( |
|
373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
374 | + $context['smiley_set_dirs'][] = array( |
|
360 | 375 | 'id' => $entry, |
361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
363 | 378 | 'current' => $entry == $context['current_set']['path'], |
364 | 379 | ); |
380 | + } |
|
365 | 381 | } |
366 | 382 | $dir->close(); |
367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
371 | 387 | createToken('admin-mss', 'request'); |
372 | 388 | |
373 | 389 | // In case we need to import smileys, we need to add the token in now. |
374 | - if (isset($context['current_set']['import_url'])) |
|
375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
390 | + if (isset($context['current_set']['import_url'])) { |
|
391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
392 | + } |
|
376 | 393 | |
377 | 394 | $listOptions = array( |
378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
510 | 527 | $cols['name'][] = $set_names[$i]; |
511 | 528 | } |
512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
513 | - if (substr($sort, 0, 4) === 'name') |
|
514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
515 | - elseif (substr($sort, 0, 4) === 'path') |
|
516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
517 | - else |
|
518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
530 | + if (substr($sort, 0, 4) === 'name') { |
|
531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
534 | + } else { |
|
535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
536 | + } |
|
519 | 537 | |
520 | 538 | $smiley_sets = array(); |
521 | - foreach ($cols['id'] as $i => $id) |
|
522 | - $smiley_sets[] = array( |
|
539 | + foreach ($cols['id'] as $i => $id) { |
|
540 | + $smiley_sets[] = array( |
|
523 | 541 | 'id' => $id, |
524 | 542 | 'path' => $cols['path'][$i], |
525 | 543 | 'name' => $cols['name'][$i], |
526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
527 | 545 | ); |
546 | + } |
|
528 | 547 | |
529 | 548 | return $smiley_sets; |
530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
557 | - $context['smiley_sets'][$i] = array( |
|
575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
576 | + $context['smiley_sets'][$i] = array( |
|
558 | 577 | 'id' => $i, |
559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
562 | 581 | ); |
582 | + } |
|
563 | 583 | |
564 | 584 | // Submitting a form? |
565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
576 | 596 | |
577 | 597 | // Make sure some code was entered. |
578 | - if (empty($_POST['smiley_code'])) |
|
579 | - fatal_lang_error('smiley_has_no_code'); |
|
598 | + if (empty($_POST['smiley_code'])) { |
|
599 | + fatal_lang_error('smiley_has_no_code'); |
|
600 | + } |
|
580 | 601 | |
581 | 602 | // Check whether the new code has duplicates. It should be unique. |
582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
589 | 610 | ) |
590 | 611 | ); |
591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
592 | - fatal_lang_error('smiley_not_unique'); |
|
612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
613 | + fatal_lang_error('smiley_not_unique'); |
|
614 | + } |
|
593 | 615 | $smcFunc['db_free_result']($request); |
594 | 616 | |
595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
598 | 620 | $writeErrors = array(); |
599 | 621 | foreach ($context['smiley_sets'] as $set) |
600 | 622 | { |
601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
602 | - $writeErrors[] = $set['path']; |
|
623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
624 | + $writeErrors[] = $set['path']; |
|
625 | + } |
|
626 | + } |
|
627 | + if (!empty($writeErrors)) { |
|
628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
603 | 629 | } |
604 | - if (!empty($writeErrors)) |
|
605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
606 | 630 | } |
607 | 631 | |
608 | 632 | // Uploading just one smiley for all of them? |
609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
610 | 634 | { |
611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
612 | - fatal_lang_error('smileys_upload_error'); |
|
635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
636 | + fatal_lang_error('smileys_upload_error'); |
|
637 | + } |
|
613 | 638 | |
614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
616 | 641 | |
617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
645 | + } |
|
620 | 646 | |
621 | 647 | // We only need the filename... |
622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
623 | 649 | |
624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
653 | + } |
|
627 | 654 | |
628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
629 | 656 | $i = 0; |
630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
632 | - $i++; |
|
658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
659 | + $i++; |
|
660 | + } |
|
633 | 661 | |
634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
645 | 673 | |
646 | 674 | // The file is already there! Don't overwrite it! |
647 | - if (file_exists($currentPath)) |
|
648 | - continue; |
|
675 | + if (file_exists($currentPath)) { |
|
676 | + continue; |
|
677 | + } |
|
649 | 678 | |
650 | 679 | // Okay, so copy the first one we made to here. |
651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
662 | 691 | $newName = ''; |
663 | 692 | foreach ($_FILES as $name => $data) |
664 | 693 | { |
665 | - if ($_FILES[$name]['name'] == '') |
|
666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
694 | + if ($_FILES[$name]['name'] == '') { |
|
695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
696 | + } |
|
667 | 697 | |
668 | - if (empty($newName)) |
|
669 | - $newName = basename($_FILES[$name]['name']); |
|
670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
671 | - fatal_lang_error('smileys_upload_error_name'); |
|
698 | + if (empty($newName)) { |
|
699 | + $newName = basename($_FILES[$name]['name']); |
|
700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
701 | + fatal_lang_error('smileys_upload_error_name'); |
|
702 | + } |
|
672 | 703 | } |
673 | 704 | |
674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
678 | 709 | |
679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
680 | - continue; |
|
710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
711 | + continue; |
|
712 | + } |
|
681 | 713 | |
682 | 714 | // Got one... |
683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
684 | - fatal_lang_error('smileys_upload_error'); |
|
715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
716 | + fatal_lang_error('smileys_upload_error'); |
|
717 | + } |
|
685 | 718 | |
686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
688 | 721 | |
689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
725 | + } |
|
692 | 726 | |
693 | 727 | // We only need the filename... |
694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
695 | 729 | |
696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
733 | + } |
|
699 | 734 | |
700 | 735 | // If the file exists - ignore it. |
701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
702 | - if (file_exists($smileyLocation)) |
|
703 | - continue; |
|
737 | + if (file_exists($smileyLocation)) { |
|
738 | + continue; |
|
739 | + } |
|
704 | 740 | |
705 | 741 | // Finally - move the image! |
706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
712 | 748 | } |
713 | 749 | |
714 | 750 | // Also make sure a filename was given. |
715 | - if (empty($_POST['smiley_filename'])) |
|
716 | - fatal_lang_error('smiley_has_no_filename'); |
|
751 | + if (empty($_POST['smiley_filename'])) { |
|
752 | + fatal_lang_error('smiley_has_no_filename'); |
|
753 | + } |
|
717 | 754 | |
718 | 755 | // Find the position on the right. |
719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
733 | 770 | $smcFunc['db_free_result']($request); |
734 | 771 | |
735 | - if (empty($smiley_order)) |
|
736 | - $smiley_order = '0'; |
|
772 | + if (empty($smiley_order)) { |
|
773 | + $smiley_order = '0'; |
|
774 | + } |
|
737 | 775 | } |
738 | 776 | $smcFunc['db_insert']('', |
739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
761 | 799 | { |
762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
763 | 801 | { |
764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
765 | - continue; |
|
802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
803 | + continue; |
|
804 | + } |
|
766 | 805 | |
767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
768 | 807 | while ($entry = $dir->read()) |
769 | 808 | { |
770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
771 | - $context['filenames'][strtolower($entry)] = array( |
|
809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
810 | + $context['filenames'][strtolower($entry)] = array( |
|
772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
773 | 812 | 'selected' => false, |
774 | 813 | ); |
814 | + } |
|
775 | 815 | } |
776 | 816 | $dir->close(); |
777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
809 | 849 | // Changing the selected smileys? |
810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
811 | 851 | { |
812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
854 | + } |
|
814 | 855 | |
815 | - if ($_POST['smiley_action'] == 'delete') |
|
816 | - $smcFunc['db_query']('', ' |
|
856 | + if ($_POST['smiley_action'] == 'delete') { |
|
857 | + $smcFunc['db_query']('', ' |
|
817 | 858 | DELETE FROM {db_prefix}smileys |
818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
819 | 860 | array( |
820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
821 | 862 | ) |
822 | 863 | ); |
864 | + } |
|
823 | 865 | // Changing the status of the smiley? |
824 | 866 | else |
825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
829 | 871 | 'hidden' => 1, |
830 | 872 | 'popup' => 2 |
831 | 873 | ); |
832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
833 | - $smcFunc['db_query']('', ' |
|
874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
875 | + $smcFunc['db_query']('', ' |
|
834 | 876 | UPDATE {db_prefix}smileys |
835 | 877 | SET hidden = {int:display_type} |
836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
840 | 882 | ) |
841 | 883 | ); |
884 | + } |
|
842 | 885 | } |
843 | 886 | } |
844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
865 | 908 | |
866 | 909 | // Make sure some code was entered. |
867 | - if (empty($_POST['smiley_code'])) |
|
868 | - fatal_lang_error('smiley_has_no_code'); |
|
910 | + if (empty($_POST['smiley_code'])) { |
|
911 | + fatal_lang_error('smiley_has_no_code'); |
|
912 | + } |
|
869 | 913 | |
870 | 914 | // Also make sure a filename was given. |
871 | - if (empty($_POST['smiley_filename'])) |
|
872 | - fatal_lang_error('smiley_has_no_filename'); |
|
915 | + if (empty($_POST['smiley_filename'])) { |
|
916 | + fatal_lang_error('smiley_has_no_filename'); |
|
917 | + } |
|
873 | 918 | |
874 | 919 | // Check whether the new code has duplicates. It should be unique. |
875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
884 | 929 | ) |
885 | 930 | ); |
886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
887 | - fatal_lang_error('smiley_not_unique'); |
|
931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
932 | + fatal_lang_error('smiley_not_unique'); |
|
933 | + } |
|
888 | 934 | $smcFunc['db_free_result']($request); |
889 | 935 | |
890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
913 | 959 | // Load all known smiley sets. |
914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
917 | - $context['smiley_sets'][$i] = array( |
|
962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
963 | + $context['smiley_sets'][$i] = array( |
|
918 | 964 | 'id' => $i, |
919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
922 | 968 | ); |
969 | + } |
|
923 | 970 | |
924 | 971 | // Prepare overview of all (custom) smileys. |
925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
935 | 982 | // Create a list of options for selecting smiley sets. |
936 | 983 | $smileyset_option_list = ' |
937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
939 | - $smileyset_option_list .= ' |
|
985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
986 | + $smileyset_option_list .= ' |
|
940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
988 | + } |
|
941 | 989 | $smileyset_option_list .= ' |
942 | 990 | </select>'; |
943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
999 | 1047 | 'data' => array( |
1000 | 1048 | 'function' => function ($rowData) use ($txt) |
1001 | 1049 | { |
1002 | - if (empty($rowData['hidden'])) |
|
1003 | - return $txt['smileys_location_form']; |
|
1004 | - elseif ($rowData['hidden'] == 1) |
|
1005 | - return $txt['smileys_location_hidden']; |
|
1006 | - else |
|
1007 | - return $txt['smileys_location_popup']; |
|
1050 | + if (empty($rowData['hidden'])) { |
|
1051 | + return $txt['smileys_location_form']; |
|
1052 | + } elseif ($rowData['hidden'] == 1) { |
|
1053 | + return $txt['smileys_location_hidden']; |
|
1054 | + } else { |
|
1055 | + return $txt['smileys_location_popup']; |
|
1056 | + } |
|
1008 | 1057 | }, |
1009 | 1058 | ), |
1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
1019 | 1068 | 'data' => array( |
1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
1021 | 1070 | { |
1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1073 | + } |
|
1024 | 1074 | |
1025 | 1075 | // Check if there are smileys missing in some sets. |
1026 | 1076 | $missing_sets = array(); |
1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
1080 | + } |
|
1030 | 1081 | |
1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
1032 | 1083 | |
1033 | - if (!empty($missing_sets)) |
|
1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1084 | + if (!empty($missing_sets)) { |
|
1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1086 | + } |
|
1035 | 1087 | |
1036 | 1088 | return $description; |
1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
1151 | - $context['smiley_sets'][$i] = array( |
|
1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
1203 | + $context['smiley_sets'][$i] = array( |
|
1152 | 1204 | 'id' => $i, |
1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
1156 | 1208 | ); |
1209 | + } |
|
1157 | 1210 | |
1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
1163 | 1216 | { |
1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
1165 | 1218 | { |
1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
1167 | - continue; |
|
1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
1220 | + continue; |
|
1221 | + } |
|
1168 | 1222 | |
1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
1170 | 1224 | while ($entry = $dir->read()) |
1171 | 1225 | { |
1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1173 | - $context['filenames'][strtolower($entry)] = array( |
|
1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1227 | + $context['filenames'][strtolower($entry)] = array( |
|
1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
1175 | 1229 | 'selected' => false, |
1176 | 1230 | ); |
1231 | + } |
|
1177 | 1232 | } |
1178 | 1233 | $dir->close(); |
1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
1189 | 1244 | ) |
1190 | 1245 | ); |
1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1192 | - fatal_lang_error('smiley_not_found'); |
|
1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1247 | + fatal_lang_error('smiley_not_found'); |
|
1248 | + } |
|
1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
1194 | 1250 | $smcFunc['db_free_result']($request); |
1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
1199 | 1255 | |
1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1258 | + } |
|
1202 | 1259 | } |
1203 | 1260 | } |
1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
1223 | 1280 | ) |
1224 | 1281 | ); |
1225 | 1282 | $smileys = array(); |
1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1227 | - $smileys[] = $row; |
|
1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1284 | + $smileys[] = $row; |
|
1285 | + } |
|
1228 | 1286 | $smcFunc['db_free_result']($request); |
1229 | 1287 | |
1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
1266 | 1324 | |
1267 | - if (empty($_GET['source'])) |
|
1268 | - fatal_lang_error('smiley_not_found'); |
|
1325 | + if (empty($_GET['source'])) { |
|
1326 | + fatal_lang_error('smiley_not_found'); |
|
1327 | + } |
|
1269 | 1328 | |
1270 | 1329 | if (!empty($_GET['after'])) |
1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
1281 | 1340 | 'after_smiley' => $_GET['after'], |
1282 | 1341 | ) |
1283 | 1342 | ); |
1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1285 | - fatal_lang_error('smiley_not_found'); |
|
1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1344 | + fatal_lang_error('smiley_not_found'); |
|
1345 | + } |
|
1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
1287 | 1347 | $smcFunc['db_free_result']($request); |
1288 | - } |
|
1289 | - else |
|
1348 | + } else |
|
1290 | 1349 | { |
1291 | 1350 | $smiley_row = (int) $_GET['row']; |
1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
1361 | 1420 | |
1362 | 1421 | // Make sure all rows are sequential. |
1363 | - foreach (array_keys($context['smileys']) as $location) |
|
1364 | - $context['smileys'][$location] = array( |
|
1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
1423 | + $context['smileys'][$location] = array( |
|
1365 | 1424 | 'id' => $location, |
1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
1370 | 1429 | ); |
1430 | + } |
|
1371 | 1431 | |
1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
1393 | 1453 | } |
1394 | 1454 | // Make sure the smiley order is always sequential. |
1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
1396 | - if ($order_id != $smiley['order']) |
|
1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
1456 | + if ($order_id != $smiley['order']) |
|
1397 | 1457 | $smcFunc['db_query']('', ' |
1398 | 1458 | UPDATE {db_prefix}smileys |
1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
1403 | 1463 | 'current_smiley' => $smiley['id'], |
1404 | 1464 | ) |
1405 | 1465 | ); |
1466 | + } |
|
1406 | 1467 | } |
1407 | 1468 | } |
1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
1436 | 1497 | |
1437 | 1498 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
1438 | 1499 | // @ TODO: Our current xml files serve http links. Allowing both for now until we serve https. |
1439 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
1440 | - fatal_lang_error('not_on_simplemachines'); |
|
1500 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
1501 | + fatal_lang_error('not_on_simplemachines'); |
|
1502 | + } |
|
1441 | 1503 | |
1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
1443 | 1505 | |
1444 | - if (file_exists($destination)) |
|
1445 | - fatal_lang_error('package_upload_error_exists'); |
|
1506 | + if (file_exists($destination)) { |
|
1507 | + fatal_lang_error('package_upload_error_exists'); |
|
1508 | + } |
|
1446 | 1509 | |
1447 | 1510 | // Let's copy it to the Packages directory |
1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
1449 | 1512 | $testing = true; |
1450 | - } |
|
1451 | - elseif (isset($_REQUEST['package'])) |
|
1513 | + } elseif (isset($_REQUEST['package'])) |
|
1452 | 1514 | { |
1453 | 1515 | $base_name = basename($_REQUEST['package']); |
1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1457,12 +1519,14 @@ discard block |
||
1457 | 1519 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
1458 | 1520 | } |
1459 | 1521 | |
1460 | - if (empty($destination) || !file_exists($destination)) |
|
1461 | - fatal_lang_error('package_no_file', false); |
|
1522 | + if (empty($destination) || !file_exists($destination)) { |
|
1523 | + fatal_lang_error('package_no_file', false); |
|
1524 | + } |
|
1462 | 1525 | |
1463 | 1526 | // Make sure temp directory exists and is empty. |
1464 | - if (file_exists($packagesdir . '/temp')) |
|
1465 | - deltree($packagesdir . '/temp', false); |
|
1527 | + if (file_exists($packagesdir . '/temp')) { |
|
1528 | + deltree($packagesdir . '/temp', false); |
|
1529 | + } |
|
1466 | 1530 | |
1467 | 1531 | if (!mktree($packagesdir . '/temp', 0755)) |
1468 | 1532 | { |
@@ -1474,31 +1538,37 @@ discard block |
||
1474 | 1538 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
1475 | 1539 | |
1476 | 1540 | deltree($packagesdir . '/temp', false); |
1477 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
1478 | - fatal_lang_error('package_cant_download', false); |
|
1541 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
1542 | + fatal_lang_error('package_cant_download', false); |
|
1543 | + } |
|
1479 | 1544 | } |
1480 | 1545 | } |
1481 | 1546 | |
1482 | 1547 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
1483 | - if (!$extracted) |
|
1484 | - fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1485 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1486 | - foreach ($extracted as $file) |
|
1548 | + if (!$extracted) { |
|
1549 | + fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1550 | + } |
|
1551 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1552 | + foreach ($extracted as $file) |
|
1487 | 1553 | if (basename($file['filename']) == 'package-info.xml') |
1488 | 1554 | { |
1489 | 1555 | $base_path = dirname($file['filename']) . '/'; |
1556 | + } |
|
1490 | 1557 | break; |
1491 | 1558 | } |
1492 | 1559 | |
1493 | - if (!isset($base_path)) |
|
1494 | - $base_path = ''; |
|
1560 | + if (!isset($base_path)) { |
|
1561 | + $base_path = ''; |
|
1562 | + } |
|
1495 | 1563 | |
1496 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
1497 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
1564 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
1565 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
1566 | + } |
|
1498 | 1567 | |
1499 | 1568 | $smileyInfo = getPackageInfo($context['filename']); |
1500 | - if (!is_array($smileyInfo)) |
|
1501 | - fatal_lang_error($smileyInfo); |
|
1569 | + if (!is_array($smileyInfo)) { |
|
1570 | + fatal_lang_error($smileyInfo); |
|
1571 | + } |
|
1502 | 1572 | |
1503 | 1573 | // See if it is installed? |
1504 | 1574 | $request = $smcFunc['db_query']('', ' |
@@ -1514,8 +1584,9 @@ discard block |
||
1514 | 1584 | ) |
1515 | 1585 | ); |
1516 | 1586 | |
1517 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1518 | - fatal_lang_error('package_installed_warning1'); |
|
1587 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1588 | + fatal_lang_error('package_installed_warning1'); |
|
1589 | + } |
|
1519 | 1590 | |
1520 | 1591 | // Everything is fine, now it's time to do something |
1521 | 1592 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1530,23 +1601,23 @@ discard block |
||
1530 | 1601 | if ($action['type'] == 'readme' || $action['type'] == 'license') |
1531 | 1602 | { |
1532 | 1603 | $type = 'package_' . $action['type']; |
1533 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
1534 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1535 | - elseif (file_exists($action['filename'])) |
|
1536 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1604 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
1605 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1606 | + } elseif (file_exists($action['filename'])) { |
|
1607 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1608 | + } |
|
1537 | 1609 | |
1538 | 1610 | if (!empty($action['parse_bbc'])) |
1539 | 1611 | { |
1540 | 1612 | require_once($sourcedir . '/Subs-Post.php'); |
1541 | 1613 | preparsecode($context[$type]); |
1542 | 1614 | $context[$type] = parse_bbc($context[$type]); |
1615 | + } else { |
|
1616 | + $context[$type] = nl2br($context[$type]); |
|
1543 | 1617 | } |
1544 | - else |
|
1545 | - $context[$type] = nl2br($context[$type]); |
|
1546 | 1618 | |
1547 | 1619 | continue; |
1548 | - } |
|
1549 | - elseif ($action['type'] == 'require-dir') |
|
1620 | + } elseif ($action['type'] == 'require-dir') |
|
1550 | 1621 | { |
1551 | 1622 | // Do this one... |
1552 | 1623 | $thisAction = array( |
@@ -1565,12 +1636,12 @@ discard block |
||
1565 | 1636 | ); |
1566 | 1637 | } |
1567 | 1638 | // @todo None given? |
1568 | - if (empty($thisAction['description'])) |
|
1569 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1639 | + if (empty($thisAction['description'])) { |
|
1640 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1641 | + } |
|
1570 | 1642 | |
1571 | 1643 | $context['actions'][] = $thisAction; |
1572 | - } |
|
1573 | - elseif ($action['type'] == 'credits') |
|
1644 | + } elseif ($action['type'] == 'credits') |
|
1574 | 1645 | { |
1575 | 1646 | // Time to build the billboard |
1576 | 1647 | $credits_tag = array( |
@@ -1630,12 +1701,14 @@ discard block |
||
1630 | 1701 | cache_put_data('posting_smileys', null, 480); |
1631 | 1702 | } |
1632 | 1703 | |
1633 | - if (file_exists($packagesdir . '/temp')) |
|
1634 | - deltree($packagesdir . '/temp'); |
|
1704 | + if (file_exists($packagesdir . '/temp')) { |
|
1705 | + deltree($packagesdir . '/temp'); |
|
1706 | + } |
|
1635 | 1707 | |
1636 | - if (!$testing) |
|
1637 | - redirectexit('action=admin;area=smileys'); |
|
1638 | -} |
|
1708 | + if (!$testing) { |
|
1709 | + redirectexit('action=admin;area=smileys'); |
|
1710 | + } |
|
1711 | + } |
|
1639 | 1712 | |
1640 | 1713 | /** |
1641 | 1714 | * A function to import new smileys from an existing directory into the database. |
@@ -1646,15 +1719,17 @@ discard block |
||
1646 | 1719 | { |
1647 | 1720 | global $modSettings, $smcFunc; |
1648 | 1721 | |
1649 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
1650 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
1722 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
1723 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
1724 | + } |
|
1651 | 1725 | |
1652 | 1726 | $smileys = array(); |
1653 | 1727 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
1654 | 1728 | while ($entry = $dir->read()) |
1655 | 1729 | { |
1656 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1657 | - $smileys[strtolower($entry)] = $entry; |
|
1730 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1731 | + $smileys[strtolower($entry)] = $entry; |
|
1732 | + } |
|
1658 | 1733 | } |
1659 | 1734 | $dir->close(); |
1660 | 1735 | |
@@ -1667,9 +1742,10 @@ discard block |
||
1667 | 1742 | 'smiley_list' => $smileys, |
1668 | 1743 | ) |
1669 | 1744 | ); |
1670 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1671 | - if (isset($smileys[strtolower($row['filename'])])) |
|
1745 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1746 | + if (isset($smileys[strtolower($row['filename'])])) |
|
1672 | 1747 | unset($smileys[strtolower($row['filename'])]); |
1748 | + } |
|
1673 | 1749 | $smcFunc['db_free_result']($request); |
1674 | 1750 | |
1675 | 1751 | $request = $smcFunc['db_query']('', ' |
@@ -1686,9 +1762,10 @@ discard block |
||
1686 | 1762 | $smcFunc['db_free_result']($request); |
1687 | 1763 | |
1688 | 1764 | $new_smileys = array(); |
1689 | - foreach ($smileys as $smiley) |
|
1690 | - if (strlen($smiley) <= 48) |
|
1765 | + foreach ($smileys as $smiley) { |
|
1766 | + if (strlen($smiley) <= 48) |
|
1691 | 1767 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
1768 | + } |
|
1692 | 1769 | |
1693 | 1770 | if (!empty($new_smileys)) |
1694 | 1771 | { |
@@ -1753,8 +1830,9 @@ discard block |
||
1753 | 1830 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
1754 | 1831 | { |
1755 | 1832 | $deleteIcons = array(); |
1756 | - foreach ($_POST['checked_icons'] as $icon) |
|
1757 | - $deleteIcons[] = (int) $icon; |
|
1833 | + foreach ($_POST['checked_icons'] as $icon) { |
|
1834 | + $deleteIcons[] = (int) $icon; |
|
1835 | + } |
|
1758 | 1836 | |
1759 | 1837 | // Do the actual delete! |
1760 | 1838 | $smcFunc['db_query']('', ' |
@@ -1771,35 +1849,41 @@ discard block |
||
1771 | 1849 | $_GET['icon'] = (int) $_GET['icon']; |
1772 | 1850 | |
1773 | 1851 | // Do some preperation with the data... like check the icon exists *somewhere* |
1774 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
1775 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1776 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
1777 | - fatal_lang_error('icon_not_found'); |
|
1852 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
1853 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1854 | + } |
|
1855 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
1856 | + fatal_lang_error('icon_not_found'); |
|
1857 | + } |
|
1778 | 1858 | // There is a 16 character limit on message icons... |
1779 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
1780 | - fatal_lang_error('icon_name_too_long'); |
|
1781 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
1782 | - fatal_lang_error('icon_after_itself'); |
|
1859 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
1860 | + fatal_lang_error('icon_name_too_long'); |
|
1861 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
1862 | + fatal_lang_error('icon_after_itself'); |
|
1863 | + } |
|
1783 | 1864 | |
1784 | 1865 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
1785 | 1866 | if ($_GET['icon'] != 0) |
1786 | 1867 | { |
1787 | 1868 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
1788 | - foreach ($context['icons'] as $id => $data) |
|
1789 | - if ($data['true_order'] > $oldOrder) |
|
1869 | + foreach ($context['icons'] as $id => $data) { |
|
1870 | + if ($data['true_order'] > $oldOrder) |
|
1790 | 1871 | $context['icons'][$id]['true_order']--; |
1872 | + } |
|
1791 | 1873 | } |
1792 | 1874 | |
1793 | 1875 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
1794 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
1795 | - $_GET['icon'] = 1; |
|
1876 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
1877 | + $_GET['icon'] = 1; |
|
1878 | + } |
|
1796 | 1879 | |
1797 | 1880 | // Get the new order. |
1798 | 1881 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
1799 | 1882 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
1800 | - foreach ($context['icons'] as $id => $data) |
|
1801 | - if ($data['true_order'] >= $newOrder) |
|
1883 | + foreach ($context['icons'] as $id => $data) { |
|
1884 | + if ($data['true_order'] >= $newOrder) |
|
1802 | 1885 | $context['icons'][$id]['true_order']++; |
1886 | + } |
|
1803 | 1887 | |
1804 | 1888 | // Finally set the current icon's position! |
1805 | 1889 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1817,8 +1901,7 @@ discard block |
||
1817 | 1901 | if ($id != 0) |
1818 | 1902 | { |
1819 | 1903 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1820 | - } |
|
1821 | - else |
|
1904 | + } else |
|
1822 | 1905 | { |
1823 | 1906 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1824 | 1907 | } |
@@ -1843,8 +1926,9 @@ discard block |
||
1843 | 1926 | } |
1844 | 1927 | |
1845 | 1928 | // Unless we're adding a new thing, we'll escape |
1846 | - if (!isset($_POST['add'])) |
|
1847 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1929 | + if (!isset($_POST['add'])) { |
|
1930 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1931 | + } |
|
1848 | 1932 | } |
1849 | 1933 | |
1850 | 1934 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1954,8 +2038,9 @@ discard block |
||
1954 | 2038 | $context['new_icon'] = !isset($_GET['icon']); |
1955 | 2039 | |
1956 | 2040 | // Get the properties of the current icon from the icon list. |
1957 | - if (!$context['new_icon']) |
|
1958 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2041 | + if (!$context['new_icon']) { |
|
2042 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2043 | + } |
|
1959 | 2044 | |
1960 | 2045 | // Get a list of boards needed for assigning this icon to a specific board. |
1961 | 2046 | $boardListOptions = array( |
@@ -1989,8 +2074,9 @@ discard block |
||
1989 | 2074 | ); |
1990 | 2075 | |
1991 | 2076 | $message_icons = array(); |
1992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1993 | - $message_icons[] = $row; |
|
2077 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2078 | + $message_icons[] = $row; |
|
2079 | + } |
|
1994 | 2080 | $smcFunc['db_free_result']($request); |
1995 | 2081 | |
1996 | 2082 | return $message_icons; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Outputs xml data representing recent information or a profile. |
@@ -37,8 +38,9 @@ discard block |
||
37 | 38 | global $query_this_board, $smcFunc, $forum_version, $settings; |
38 | 39 | |
39 | 40 | // If it's not enabled, die. |
40 | - if (empty($modSettings['xmlnews_enable'])) |
|
41 | - obExit(false); |
|
41 | + if (empty($modSettings['xmlnews_enable'])) { |
|
42 | + obExit(false); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | loadLanguage('Stats'); |
44 | 46 | |
@@ -64,8 +66,9 @@ discard block |
||
64 | 66 | if (!empty($_REQUEST['c']) && empty($board)) |
65 | 67 | { |
66 | 68 | $_REQUEST['c'] = explode(',', $_REQUEST['c']); |
67 | - foreach ($_REQUEST['c'] as $i => $c) |
|
68 | - $_REQUEST['c'][$i] = (int) $c; |
|
69 | + foreach ($_REQUEST['c'] as $i => $c) { |
|
70 | + $_REQUEST['c'][$i] = (int) $c; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | if (count($_REQUEST['c']) == 1) |
71 | 74 | { |
@@ -101,18 +104,20 @@ discard block |
||
101 | 104 | } |
102 | 105 | $smcFunc['db_free_result']($request); |
103 | 106 | |
104 | - if (!empty($boards)) |
|
105 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
107 | + if (!empty($boards)) { |
|
108 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
109 | + } |
|
106 | 110 | |
107 | 111 | // Try to limit the number of messages we look through. |
108 | - if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) |
|
109 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
110 | - } |
|
111 | - elseif (!empty($_REQUEST['boards'])) |
|
112 | + if ($total_cat_posts > 100 && $total_cat_posts > $modSettings['totalMessages'] / 15) { |
|
113 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 400 - $_GET['limit'] * 5); |
|
114 | + } |
|
115 | + } elseif (!empty($_REQUEST['boards'])) |
|
112 | 116 | { |
113 | 117 | $_REQUEST['boards'] = explode(',', $_REQUEST['boards']); |
114 | - foreach ($_REQUEST['boards'] as $i => $b) |
|
115 | - $_REQUEST['boards'][$i] = (int) $b; |
|
118 | + foreach ($_REQUEST['boards'] as $i => $b) { |
|
119 | + $_REQUEST['boards'][$i] = (int) $b; |
|
120 | + } |
|
116 | 121 | |
117 | 122 | $request = $smcFunc['db_query']('', ' |
118 | 123 | SELECT b.id_board, b.num_posts, b.name |
@@ -128,29 +133,32 @@ discard block |
||
128 | 133 | |
129 | 134 | // Either the board specified doesn't exist or you have no access. |
130 | 135 | $num_boards = $smcFunc['db_num_rows']($request); |
131 | - if ($num_boards == 0) |
|
132 | - fatal_lang_error('no_board'); |
|
136 | + if ($num_boards == 0) { |
|
137 | + fatal_lang_error('no_board'); |
|
138 | + } |
|
133 | 139 | |
134 | 140 | $total_posts = 0; |
135 | 141 | $boards = array(); |
136 | 142 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
137 | 143 | { |
138 | - if ($num_boards == 1) |
|
139 | - $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
144 | + if ($num_boards == 1) { |
|
145 | + $feed_meta['title'] = ' - ' . strip_tags($row['name']); |
|
146 | + } |
|
140 | 147 | |
141 | 148 | $boards[] = $row['id_board']; |
142 | 149 | $total_posts += $row['num_posts']; |
143 | 150 | } |
144 | 151 | $smcFunc['db_free_result']($request); |
145 | 152 | |
146 | - if (!empty($boards)) |
|
147 | - $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
153 | + if (!empty($boards)) { |
|
154 | + $query_this_board = 'b.id_board IN (' . implode(', ', $boards) . ')'; |
|
155 | + } |
|
148 | 156 | |
149 | 157 | // The more boards, the more we're going to look through... |
150 | - if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) |
|
151 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
152 | - } |
|
153 | - elseif (!empty($board)) |
|
158 | + if ($total_posts > 100 && $total_posts > $modSettings['totalMessages'] / 12) { |
|
159 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 500 - $_GET['limit'] * 5); |
|
160 | + } |
|
161 | + } elseif (!empty($board)) |
|
154 | 162 | { |
155 | 163 | $request = $smcFunc['db_query']('', ' |
156 | 164 | SELECT num_posts |
@@ -170,10 +178,10 @@ discard block |
||
170 | 178 | $query_this_board = 'b.id_board = ' . $board; |
171 | 179 | |
172 | 180 | // Try to look through just a few messages, if at all possible. |
173 | - if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) |
|
174 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
175 | - } |
|
176 | - else |
|
181 | + if ($total_posts > 80 && $total_posts > $modSettings['totalMessages'] / 10) { |
|
182 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= ' . max(0, $modSettings['maxMsgID'] - 600 - $_GET['limit'] * 5); |
|
183 | + } |
|
184 | + } else |
|
177 | 185 | { |
178 | 186 | $query_this_board = '{query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? ' |
179 | 187 | AND b.id_board != ' . $modSettings['recycle_board'] : ''); |
@@ -196,30 +204,35 @@ discard block |
||
196 | 204 | // Easy adding of sub actions |
197 | 205 | call_integration_hook('integrate_xmlfeeds', array(&$subActions)); |
198 | 206 | |
199 | - if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) |
|
200 | - $_GET['sa'] = 'recent'; |
|
207 | + if (empty($_GET['sa']) || !isset($subActions[$_GET['sa']])) { |
|
208 | + $_GET['sa'] = 'recent'; |
|
209 | + } |
|
201 | 210 | |
202 | 211 | // We only want some information, not all of it. |
203 | 212 | $cachekey = array($xml_format, $_GET['action'], $_GET['limit'], $_GET['sa']); |
204 | - foreach (array('board', 'boards', 'c') as $var) |
|
205 | - if (isset($_REQUEST[$var])) |
|
213 | + foreach (array('board', 'boards', 'c') as $var) { |
|
214 | + if (isset($_REQUEST[$var])) |
|
206 | 215 | $cachekey[] = $_REQUEST[$var]; |
216 | + } |
|
207 | 217 | $cachekey = md5(json_encode($cachekey) . (!empty($query_this_board) ? $query_this_board : '')); |
208 | 218 | $cache_t = microtime(); |
209 | 219 | |
210 | 220 | // Get the associative array representing the xml. |
211 | - if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) |
|
212 | - $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
221 | + if (!empty($modSettings['cache_enable']) && (!$user_info['is_guest'] || $modSettings['cache_enable'] >= 3)) { |
|
222 | + $xml_data = cache_get_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, 240); |
|
223 | + } |
|
213 | 224 | if (empty($xml_data)) |
214 | 225 | { |
215 | 226 | $call = call_helper($subActions[$_GET['sa']][0], true); |
216 | 227 | |
217 | - if (!empty($call)) |
|
218 | - $xml_data = call_user_func($call, $xml_format); |
|
228 | + if (!empty($call)) { |
|
229 | + $xml_data = call_user_func($call, $xml_format); |
|
230 | + } |
|
219 | 231 | |
220 | 232 | if (!empty($modSettings['cache_enable']) && (($user_info['is_guest'] && $modSettings['cache_enable'] >= 3) |
221 | - || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) |
|
222 | - cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
233 | + || (!$user_info['is_guest'] && (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.2)))) { |
|
234 | + cache_put_data('xmlfeed-' . $xml_format . ':' . ($user_info['is_guest'] ? '' : $user_info['id'] . '-') . $cachekey, $xml_data, 240); |
|
235 | + } |
|
223 | 236 | } |
224 | 237 | |
225 | 238 | $feed_meta['title'] = $smcFunc['htmlspecialchars'](strip_tags($context['forum_name'])) . (isset($feed_meta['title']) ? $feed_meta['title'] : ''); |
@@ -259,43 +272,49 @@ discard block |
||
259 | 272 | call_integration_hook('integrate_xml_data', array(&$xml_data, &$feed_meta, &$namespaces, &$extraFeedTags, &$forceCdataKeys, &$nsKeys, $xml_format, $_GET['sa'])); |
260 | 273 | |
261 | 274 | // These can't be empty |
262 | - foreach (array('title', 'desc', 'source') as $mkey) |
|
263 | - $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
275 | + foreach (array('title', 'desc', 'source') as $mkey) { |
|
276 | + $feed_meta[$mkey] = !empty($feed_meta[$mkey]) ? $feed_meta[$mkey] : $orig_feed_meta[$mkey]; |
|
277 | + } |
|
264 | 278 | |
265 | 279 | // Sanitize basic feed metadata values |
266 | - foreach ($feed_meta as $mkey => $mvalue) |
|
267 | - $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
280 | + foreach ($feed_meta as $mkey => $mvalue) { |
|
281 | + $feed_meta[$mkey] = cdata_parse(strip_tags(fix_possible_url($feed_meta[$mkey]))); |
|
282 | + } |
|
268 | 283 | |
269 | 284 | $ns_string = ''; |
270 | 285 | if (!empty($namespaces[$xml_format])) |
271 | 286 | { |
272 | - foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) |
|
273 | - $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
287 | + foreach ($namespaces[$xml_format] as $nsprefix => $nsurl) { |
|
288 | + $ns_string .= ' xmlns' . ($nsprefix !== '' ? ':' : '') . $nsprefix . '="' . $nsurl . '"'; |
|
289 | + } |
|
274 | 290 | } |
275 | 291 | |
276 | 292 | $extraFeedTags_string = ''; |
277 | 293 | if (!empty($extraFeedTags[$xml_format])) |
278 | 294 | { |
279 | 295 | $indent = "\t" . ($xml_format !== 'atom' ? "\t" : ''); |
280 | - foreach ($extraFeedTags[$xml_format] as $extraTag) |
|
281 | - $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
296 | + foreach ($extraFeedTags[$xml_format] as $extraTag) { |
|
297 | + $extraFeedTags_string .= "\n" . $indent . $extraTag; |
|
298 | + } |
|
282 | 299 | } |
283 | 300 | |
284 | 301 | // This is an xml file.... |
285 | 302 | ob_end_clean(); |
286 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
287 | - @ob_start('ob_gzhandler'); |
|
288 | - else |
|
289 | - ob_start(); |
|
303 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
304 | + @ob_start('ob_gzhandler'); |
|
305 | + } else { |
|
306 | + ob_start(); |
|
307 | + } |
|
290 | 308 | |
291 | - if ($xml_format == 'smf' || isset($_REQUEST['debug'])) |
|
292 | - header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
293 | - elseif ($xml_format == 'rss' || $xml_format == 'rss2') |
|
294 | - header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
295 | - elseif ($xml_format == 'atom') |
|
296 | - header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
297 | - elseif ($xml_format == 'rdf') |
|
298 | - header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
309 | + if ($xml_format == 'smf' || isset($_REQUEST['debug'])) { |
|
310 | + header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
311 | + } elseif ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
312 | + header('Content-Type: application/rss+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
313 | + } elseif ($xml_format == 'atom') { |
|
314 | + header('Content-Type: application/atom+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
315 | + } elseif ($xml_format == 'rdf') { |
|
316 | + header('Content-Type: ' . (isBrowser('ie') ? 'text/xml' : 'application/rdf+xml') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
317 | + } |
|
299 | 318 | |
300 | 319 | // First, output the xml header. |
301 | 320 | echo '<?xml version="1.0" encoding="', $context['character_set'], '"?' . '>'; |
@@ -303,10 +322,11 @@ discard block |
||
303 | 322 | // Are we outputting an rss feed or one with more information? |
304 | 323 | if ($xml_format == 'rss' || $xml_format == 'rss2') |
305 | 324 | { |
306 | - if ($xml_format == 'rss2') |
|
307 | - foreach ($_REQUEST as $var => $val) |
|
325 | + if ($xml_format == 'rss2') { |
|
326 | + foreach ($_REQUEST as $var => $val) |
|
308 | 327 | if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
309 | 328 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
329 | + } |
|
310 | 330 | |
311 | 331 | // Start with an RSS 2.0 header. |
312 | 332 | echo ' |
@@ -327,9 +347,10 @@ discard block |
||
327 | 347 | <language>' . $feed_meta['language'] . '</language>' : ''; |
328 | 348 | |
329 | 349 | // RSS2 calls for this. |
330 | - if ($xml_format == 'rss2') |
|
331 | - echo ' |
|
350 | + if ($xml_format == 'rss2') { |
|
351 | + echo ' |
|
332 | 352 | <atom:link rel="self" type="application/rss+xml" href="', $scripturl, !empty($url_parts) ? '?' . implode(';', $url_parts) : '', '" />'; |
353 | + } |
|
333 | 354 | |
334 | 355 | echo $extraFeedTags_string; |
335 | 356 | |
@@ -340,12 +361,12 @@ discard block |
||
340 | 361 | echo ' |
341 | 362 | </channel> |
342 | 363 | </rss>'; |
343 | - } |
|
344 | - elseif ($xml_format == 'atom') |
|
364 | + } elseif ($xml_format == 'atom') |
|
345 | 365 | { |
346 | - foreach ($_REQUEST as $var => $val) |
|
347 | - if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
366 | + foreach ($_REQUEST as $var => $val) { |
|
367 | + if (in_array($var, array('action', 'sa', 'type', 'board', 'boards', 'c', 'u', 'limit'))) |
|
348 | 368 | $url_parts[] = $var . '=' . (is_array($val) ? implode(',', $val) : $val); |
369 | + } |
|
349 | 370 | |
350 | 371 | echo ' |
351 | 372 | <feed', $ns_string, !empty($feed_meta['language']) ? ' xml:lang="' . $feed_meta['language'] . '"' : '', '> |
@@ -371,8 +392,7 @@ discard block |
||
371 | 392 | |
372 | 393 | echo ' |
373 | 394 | </feed>'; |
374 | - } |
|
375 | - elseif ($xml_format == 'rdf') |
|
395 | + } elseif ($xml_format == 'rdf') |
|
376 | 396 | { |
377 | 397 | echo ' |
378 | 398 | <rdf:RDF', $ns_string, '> |
@@ -437,13 +457,15 @@ discard block |
||
437 | 457 | { |
438 | 458 | global $modSettings, $context, $scripturl; |
439 | 459 | |
440 | - if (substr($val, 0, strlen($scripturl)) != $scripturl) |
|
441 | - return $val; |
|
460 | + if (substr($val, 0, strlen($scripturl)) != $scripturl) { |
|
461 | + return $val; |
|
462 | + } |
|
442 | 463 | |
443 | 464 | call_integration_hook('integrate_fix_url', array(&$val)); |
444 | 465 | |
445 | - if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) |
|
446 | - return $val; |
|
466 | + if (empty($modSettings['queryless_urls']) || ($context['server']['is_cgi'] && ini_get('cgi.fix_pathinfo') == 0 && @get_cfg_var('cgi.fix_pathinfo') == 0) || (!$context['server']['is_apache'] && !$context['server']['is_lighttpd'])) { |
|
467 | + return $val; |
|
468 | + } |
|
447 | 469 | |
448 | 470 | $val = preg_replace_callback('~\b' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+)(#[^"]*)?$~', function($m) use ($scripturl) |
449 | 471 | { |
@@ -466,8 +488,9 @@ discard block |
||
466 | 488 | global $smcFunc; |
467 | 489 | |
468 | 490 | // Do we even need to do this? |
469 | - if (strpbrk($data, '<>&') == false && $force !== true) |
|
470 | - return $data; |
|
491 | + if (strpbrk($data, '<>&') == false && $force !== true) { |
|
492 | + return $data; |
|
493 | + } |
|
471 | 494 | |
472 | 495 | $cdata = '<, |
478 | 501 | $smcFunc['strpos']($data, ']', $pos), |
479 | 502 | ); |
480 | - if ($ns != '') |
|
481 | - $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
503 | + if ($ns != '') { |
|
504 | + $positions[] = $smcFunc['strpos']($data, '<', $pos); |
|
505 | + } |
|
482 | 506 | foreach ($positions as $k => $dummy) |
483 | 507 | { |
484 | - if ($dummy === false) |
|
485 | - unset($positions[$k]); |
|
508 | + if ($dummy === false) { |
|
509 | + unset($positions[$k]); |
|
510 | + } |
|
486 | 511 | } |
487 | 512 | |
488 | 513 | $old = $pos; |
489 | 514 | $pos = empty($positions) ? $n : min($positions); |
490 | 515 | |
491 | - if ($pos - $old > 0) |
|
492 | - $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
493 | - if ($pos >= $n) |
|
494 | - break; |
|
516 | + if ($pos - $old > 0) { |
|
517 | + $cdata .= $smcFunc['substr']($data, $old, $pos - $old); |
|
518 | + } |
|
519 | + if ($pos >= $n) { |
|
520 | + break; |
|
521 | + } |
|
495 | 522 | |
496 | 523 | if ($smcFunc['substr']($data, $pos, 1) == '<') |
497 | 524 | { |
498 | 525 | $pos2 = $smcFunc['strpos']($data, '>', $pos); |
499 | - if ($pos2 === false) |
|
500 | - $pos2 = $n; |
|
501 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '/') |
|
502 | - $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
503 | - else |
|
504 | - $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == '/') { |
|
530 | + $cdata .= ']]></' . $ns . ':' . $smcFunc['substr']($data, $pos + 2, $pos2 - $pos - 1) . '<![CDATA['; |
|
531 | + } else { |
|
532 | + $cdata .= ']]><' . $ns . ':' . $smcFunc['substr']($data, $pos + 1, $pos2 - $pos) . '< == ']') |
|
535 | + } elseif ($smcFunc['substr']($data, $pos, 1) == ']') |
|
508 | 536 | { |
509 | 537 | $cdata .= ']]>]< == '&') |
|
539 | + } elseif ($smcFunc['substr']($data, $pos, 1) == '&') |
|
513 | 540 | { |
514 | 541 | $pos2 = $smcFunc['strpos']($data, ';', $pos); |
515 | - if ($pos2 === false) |
|
516 | - $pos2 = $n; |
|
542 | + if ($pos2 === false) { |
|
543 | + $pos2 = $n; |
|
544 | + } |
|
517 | 545 | $ent = $smcFunc['substr']($data, $pos + 1, $pos2 - $pos - 1); |
518 | 546 | |
519 | - if ($smcFunc['substr']($data, $pos + 1, 1) == '#') |
|
520 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
521 | - elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) |
|
522 | - $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '< == '#') { |
|
548 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
549 | + } elseif (in_array($ent, array('amp', 'lt', 'gt', 'quot'))) { |
|
550 | + $cdata .= ']]>' . $smcFunc['substr']($data, $pos, $pos2 - $pos + 1) . '<![CDATA['; |
|
551 | + } |
|
523 | 552 | |
524 | 553 | $pos = $pos2 + 1; |
525 | 554 | } |
@@ -558,8 +587,9 @@ discard block |
||
558 | 587 | 'gender', |
559 | 588 | 'blurb', |
560 | 589 | ); |
561 | - if ($xml_format != 'atom') |
|
562 | - $keysToCdata[] = 'category'; |
|
590 | + if ($xml_format != 'atom') { |
|
591 | + $keysToCdata[] = 'category'; |
|
592 | + } |
|
563 | 593 | |
564 | 594 | if (!empty($forceCdataKeys)) |
565 | 595 | { |
@@ -576,8 +606,9 @@ discard block |
||
576 | 606 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
577 | 607 | |
578 | 608 | // Skip it, it's been set to null. |
579 | - if ($key === null || ($val === null && $attrs === null)) |
|
580 | - continue; |
|
609 | + if ($key === null || ($val === null && $attrs === null)) { |
|
610 | + continue; |
|
611 | + } |
|
581 | 612 | |
582 | 613 | $forceCdata = in_array($key, $forceCdataKeys); |
583 | 614 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -590,16 +621,16 @@ discard block |
||
590 | 621 | |
591 | 622 | if (!empty($attrs)) |
592 | 623 | { |
593 | - foreach ($attrs as $attr_key => $attr_value) |
|
594 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
624 | + foreach ($attrs as $attr_key => $attr_value) { |
|
625 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
626 | + } |
|
595 | 627 | } |
596 | 628 | |
597 | 629 | // If it's empty, simply output an empty element. |
598 | 630 | if (empty($val)) |
599 | 631 | { |
600 | 632 | echo ' />'; |
601 | - } |
|
602 | - else |
|
633 | + } else |
|
603 | 634 | { |
604 | 635 | echo '>'; |
605 | 636 | |
@@ -611,11 +642,13 @@ discard block |
||
611 | 642 | echo "\n", str_repeat("\t", $i); |
612 | 643 | } |
613 | 644 | // A string with returns in it.... show this as a multiline element. |
614 | - elseif (strpos($val, "\n") !== false) |
|
615 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
645 | + elseif (strpos($val, "\n") !== false) { |
|
646 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
647 | + } |
|
616 | 648 | // A simple string. |
617 | - else |
|
618 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
649 | + else { |
|
650 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
651 | + } |
|
619 | 652 | |
620 | 653 | // Ending tag. |
621 | 654 | echo '</', $key, '>'; |
@@ -635,8 +668,9 @@ discard block |
||
635 | 668 | { |
636 | 669 | global $scripturl, $smcFunc; |
637 | 670 | |
638 | - if (!allowedTo('view_mlist')) |
|
639 | - return array(); |
|
671 | + if (!allowedTo('view_mlist')) { |
|
672 | + return array(); |
|
673 | + } |
|
640 | 674 | |
641 | 675 | // Find the most recent members. |
642 | 676 | $request = $smcFunc['db_query']('', ' |
@@ -655,8 +689,8 @@ discard block |
||
655 | 689 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
656 | 690 | |
657 | 691 | // Make the data look rss-ish. |
658 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
659 | - $data[] = array( |
|
692 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
693 | + $data[] = array( |
|
660 | 694 | 'tag' => 'item', |
661 | 695 | 'content' => array( |
662 | 696 | array( |
@@ -684,8 +718,8 @@ discard block |
||
684 | 718 | ), |
685 | 719 | ), |
686 | 720 | ); |
687 | - elseif ($xml_format == 'rdf') |
|
688 | - $data[] = array( |
|
721 | + } elseif ($xml_format == 'rdf') { |
|
722 | + $data[] = array( |
|
689 | 723 | 'tag' => 'item', |
690 | 724 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
691 | 725 | 'content' => array( |
@@ -703,8 +737,8 @@ discard block |
||
703 | 737 | ), |
704 | 738 | ), |
705 | 739 | ); |
706 | - elseif ($xml_format == 'atom') |
|
707 | - $data[] = array( |
|
740 | + } elseif ($xml_format == 'atom') { |
|
741 | + $data[] = array( |
|
708 | 742 | 'tag' => 'entry', |
709 | 743 | 'content' => array( |
710 | 744 | array( |
@@ -733,9 +767,10 @@ discard block |
||
733 | 767 | ), |
734 | 768 | ), |
735 | 769 | ); |
770 | + } |
|
736 | 771 | // More logical format for the data, but harder to apply. |
737 | - else |
|
738 | - $data[] = array( |
|
772 | + else { |
|
773 | + $data[] = array( |
|
739 | 774 | 'tag' => 'member', |
740 | 775 | 'content' => array( |
741 | 776 | array( |
@@ -756,6 +791,7 @@ discard block |
||
756 | 791 | ), |
757 | 792 | ), |
758 | 793 | ); |
794 | + } |
|
759 | 795 | } |
760 | 796 | $smcFunc['db_free_result']($request); |
761 | 797 | |
@@ -816,22 +852,24 @@ discard block |
||
816 | 852 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
817 | 853 | { |
818 | 854 | $smcFunc['db_free_result']($request); |
819 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
820 | - unset($context['optimize_msg']['lowest']); |
|
821 | - else |
|
822 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
855 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
856 | + unset($context['optimize_msg']['lowest']); |
|
857 | + } else { |
|
858 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
859 | + } |
|
823 | 860 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
824 | 861 | $loops++; |
862 | + } else { |
|
863 | + $done = true; |
|
825 | 864 | } |
826 | - else |
|
827 | - $done = true; |
|
828 | 865 | } |
829 | 866 | $data = array(); |
830 | 867 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
831 | 868 | { |
832 | 869 | // Limit the length of the message, if the option is set. |
833 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
834 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
870 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
871 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
872 | + } |
|
835 | 873 | |
836 | 874 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
837 | 875 | |
@@ -858,8 +896,9 @@ discard block |
||
858 | 896 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
859 | 897 | { |
860 | 898 | // Include approved attachments only |
861 | - if ($attach['approved']) |
|
862 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
899 | + if ($attach['approved']) { |
|
900 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
901 | + } |
|
863 | 902 | } |
864 | 903 | $smcFunc['db_free_result']($attach_request); |
865 | 904 | |
@@ -867,16 +906,17 @@ discard block |
||
867 | 906 | if (!empty($loaded_attachments)) |
868 | 907 | { |
869 | 908 | uasort($loaded_attachments, function($a, $b) { |
870 | - if ($a['filesize'] == $b['filesize']) |
|
871 | - return 0; |
|
909 | + if ($a['filesize'] == $b['filesize']) { |
|
910 | + return 0; |
|
911 | + } |
|
872 | 912 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
873 | 913 | }); |
914 | + } else { |
|
915 | + $loaded_attachments = null; |
|
874 | 916 | } |
875 | - else |
|
876 | - $loaded_attachments = null; |
|
917 | + } else { |
|
918 | + $loaded_attachments = null; |
|
877 | 919 | } |
878 | - else |
|
879 | - $loaded_attachments = null; |
|
880 | 920 | |
881 | 921 | // Create a GUID for this topic using the tag URI scheme |
882 | 922 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -893,9 +933,9 @@ discard block |
||
893 | 933 | 'length' => $attachment['filesize'], |
894 | 934 | 'type' => $attachment['mime_type'], |
895 | 935 | ); |
936 | + } else { |
|
937 | + $enclosure = null; |
|
896 | 938 | } |
897 | - else |
|
898 | - $enclosure = null; |
|
899 | 939 | |
900 | 940 | $data[] = array( |
901 | 941 | 'tag' => 'item', |
@@ -941,8 +981,7 @@ discard block |
||
941 | 981 | ), |
942 | 982 | ), |
943 | 983 | ); |
944 | - } |
|
945 | - elseif ($xml_format == 'rdf') |
|
984 | + } elseif ($xml_format == 'rdf') |
|
946 | 985 | { |
947 | 986 | $data[] = array( |
948 | 987 | 'tag' => 'item', |
@@ -966,8 +1005,7 @@ discard block |
||
966 | 1005 | ), |
967 | 1006 | ), |
968 | 1007 | ); |
969 | - } |
|
970 | - elseif ($xml_format == 'atom') |
|
1008 | + } elseif ($xml_format == 'atom') |
|
971 | 1009 | { |
972 | 1010 | // Only one attachment allowed |
973 | 1011 | if (!empty($loaded_attachments)) |
@@ -979,9 +1017,9 @@ discard block |
||
979 | 1017 | 'length' => $attachment['filesize'], |
980 | 1018 | 'type' => $attachment['mime_type'], |
981 | 1019 | ); |
1020 | + } else { |
|
1021 | + $enclosure = null; |
|
982 | 1022 | } |
983 | - else |
|
984 | - $enclosure = null; |
|
985 | 1023 | |
986 | 1024 | $data[] = array( |
987 | 1025 | 'tag' => 'entry', |
@@ -1081,9 +1119,9 @@ discard block |
||
1081 | 1119 | ) |
1082 | 1120 | ); |
1083 | 1121 | } |
1122 | + } else { |
|
1123 | + $attachments = null; |
|
1084 | 1124 | } |
1085 | - else |
|
1086 | - $attachments = null; |
|
1087 | 1125 | |
1088 | 1126 | $data[] = array( |
1089 | 1127 | 'tag' => 'article', |
@@ -1201,22 +1239,25 @@ discard block |
||
1201 | 1239 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
1202 | 1240 | { |
1203 | 1241 | $smcFunc['db_free_result']($request); |
1204 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
1205 | - unset($context['optimize_msg']['lowest']); |
|
1206 | - else |
|
1207 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1242 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
1243 | + unset($context['optimize_msg']['lowest']); |
|
1244 | + } else { |
|
1245 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
1246 | + } |
|
1208 | 1247 | $loops++; |
1248 | + } else { |
|
1249 | + $done = true; |
|
1209 | 1250 | } |
1210 | - else |
|
1211 | - $done = true; |
|
1212 | 1251 | } |
1213 | 1252 | $messages = array(); |
1214 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1215 | - $messages[] = $row['id_msg']; |
|
1253 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1254 | + $messages[] = $row['id_msg']; |
|
1255 | + } |
|
1216 | 1256 | $smcFunc['db_free_result']($request); |
1217 | 1257 | |
1218 | - if (empty($messages)) |
|
1219 | - return array(); |
|
1258 | + if (empty($messages)) { |
|
1259 | + return array(); |
|
1260 | + } |
|
1220 | 1261 | |
1221 | 1262 | // Find the most recent posts this user can see. |
1222 | 1263 | $request = $smcFunc['db_query']('', ' |
@@ -1246,8 +1287,9 @@ discard block |
||
1246 | 1287 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1247 | 1288 | { |
1248 | 1289 | // Limit the length of the message, if the option is set. |
1249 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
1250 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1290 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
1291 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
1292 | + } |
|
1251 | 1293 | |
1252 | 1294 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
1253 | 1295 | |
@@ -1274,8 +1316,9 @@ discard block |
||
1274 | 1316 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
1275 | 1317 | { |
1276 | 1318 | // Include approved attachments only |
1277 | - if ($attach['approved']) |
|
1278 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1319 | + if ($attach['approved']) { |
|
1320 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
1321 | + } |
|
1279 | 1322 | } |
1280 | 1323 | $smcFunc['db_free_result']($attach_request); |
1281 | 1324 | |
@@ -1283,16 +1326,17 @@ discard block |
||
1283 | 1326 | if (!empty($loaded_attachments)) |
1284 | 1327 | { |
1285 | 1328 | uasort($loaded_attachments, function($a, $b) { |
1286 | - if ($a['filesize'] == $b['filesize']) |
|
1287 | - return 0; |
|
1329 | + if ($a['filesize'] == $b['filesize']) { |
|
1330 | + return 0; |
|
1331 | + } |
|
1288 | 1332 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1289 | 1333 | }); |
1334 | + } else { |
|
1335 | + $loaded_attachments = null; |
|
1290 | 1336 | } |
1291 | - else |
|
1292 | - $loaded_attachments = null; |
|
1337 | + } else { |
|
1338 | + $loaded_attachments = null; |
|
1293 | 1339 | } |
1294 | - else |
|
1295 | - $loaded_attachments = null; |
|
1296 | 1340 | |
1297 | 1341 | // Create a GUID for this post using the tag URI scheme |
1298 | 1342 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1309,9 +1353,9 @@ discard block |
||
1309 | 1353 | 'length' => $attachment['filesize'], |
1310 | 1354 | 'type' => $attachment['mime_type'], |
1311 | 1355 | ); |
1356 | + } else { |
|
1357 | + $enclosure = null; |
|
1312 | 1358 | } |
1313 | - else |
|
1314 | - $enclosure = null; |
|
1315 | 1359 | |
1316 | 1360 | $data[] = array( |
1317 | 1361 | 'tag' => 'item', |
@@ -1357,8 +1401,7 @@ discard block |
||
1357 | 1401 | ), |
1358 | 1402 | ), |
1359 | 1403 | ); |
1360 | - } |
|
1361 | - elseif ($xml_format == 'rdf') |
|
1404 | + } elseif ($xml_format == 'rdf') |
|
1362 | 1405 | { |
1363 | 1406 | $data[] = array( |
1364 | 1407 | 'tag' => 'item', |
@@ -1382,8 +1425,7 @@ discard block |
||
1382 | 1425 | ), |
1383 | 1426 | ), |
1384 | 1427 | ); |
1385 | - } |
|
1386 | - elseif ($xml_format == 'atom') |
|
1428 | + } elseif ($xml_format == 'atom') |
|
1387 | 1429 | { |
1388 | 1430 | // Only one attachment allowed |
1389 | 1431 | if (!empty($loaded_attachments)) |
@@ -1395,9 +1437,9 @@ discard block |
||
1395 | 1437 | 'length' => $attachment['filesize'], |
1396 | 1438 | 'type' => $attachment['mime_type'], |
1397 | 1439 | ); |
1440 | + } else { |
|
1441 | + $enclosure = null; |
|
1398 | 1442 | } |
1399 | - else |
|
1400 | - $enclosure = null; |
|
1401 | 1443 | |
1402 | 1444 | $data[] = array( |
1403 | 1445 | 'tag' => 'entry', |
@@ -1497,9 +1539,9 @@ discard block |
||
1497 | 1539 | ) |
1498 | 1540 | ); |
1499 | 1541 | } |
1542 | + } else { |
|
1543 | + $attachments = null; |
|
1500 | 1544 | } |
1501 | - else |
|
1502 | - $attachments = null; |
|
1503 | 1545 | |
1504 | 1546 | $data[] = array( |
1505 | 1547 | 'tag' => 'recent-post', |
@@ -1618,14 +1660,16 @@ discard block |
||
1618 | 1660 | global $scripturl, $memberContext, $user_profile, $user_info; |
1619 | 1661 | |
1620 | 1662 | // You must input a valid user.... |
1621 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
1622 | - return array(); |
|
1663 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
1664 | + return array(); |
|
1665 | + } |
|
1623 | 1666 | |
1624 | 1667 | // Make sure the id is a number and not "I like trying to hack the database". |
1625 | 1668 | $_GET['u'] = (int) $_GET['u']; |
1626 | 1669 | // Load the member's contextual information! |
1627 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
1628 | - return array(); |
|
1670 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
1671 | + return array(); |
|
1672 | + } |
|
1629 | 1673 | |
1630 | 1674 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
1631 | 1675 | $profile = &$memberContext[$_GET['u']]; |
@@ -1667,8 +1711,7 @@ discard block |
||
1667 | 1711 | ), |
1668 | 1712 | ) |
1669 | 1713 | ); |
1670 | - } |
|
1671 | - elseif ($xml_format == 'rdf') |
|
1714 | + } elseif ($xml_format == 'rdf') |
|
1672 | 1715 | { |
1673 | 1716 | $data[] = array( |
1674 | 1717 | 'tag' => 'item', |
@@ -1692,8 +1735,7 @@ discard block |
||
1692 | 1735 | ), |
1693 | 1736 | ) |
1694 | 1737 | ); |
1695 | - } |
|
1696 | - elseif ($xml_format == 'atom') |
|
1738 | + } elseif ($xml_format == 'atom') |
|
1697 | 1739 | { |
1698 | 1740 | $data[] = array( |
1699 | 1741 | 'tag' => 'entry', |
@@ -1746,8 +1788,7 @@ discard block |
||
1746 | 1788 | ), |
1747 | 1789 | ) |
1748 | 1790 | ); |
1749 | - } |
|
1750 | - else |
|
1791 | + } else |
|
1751 | 1792 | { |
1752 | 1793 | $data = array( |
1753 | 1794 | array( |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Add the file functions to the $smcFunc array. |
@@ -52,8 +53,9 @@ discard block |
||
52 | 53 | 'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
53 | 54 | 'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
54 | 55 | 'themes', 'topics'); |
55 | - foreach ($reservedTables as $k => $table_name) |
|
56 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
56 | + foreach ($reservedTables as $k => $table_name) { |
|
57 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
58 | + } |
|
57 | 59 | |
58 | 60 | // We in turn may need the extra stuff. |
59 | 61 | db_extend('extra'); |
@@ -105,8 +107,9 @@ discard block |
||
105 | 107 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
106 | 108 | |
107 | 109 | // First - no way do we touch SMF tables. |
108 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
109 | - return false; |
|
110 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
111 | + return false; |
|
112 | + } |
|
110 | 113 | |
111 | 114 | // Log that we'll want to remove this on uninstall. |
112 | 115 | $db_package_log[] = array('remove_table', $table_name); |
@@ -116,16 +119,18 @@ discard block |
||
116 | 119 | if (in_array($full_table_name, $tables)) |
117 | 120 | { |
118 | 121 | // This is a sad day... drop the table? If not, return false (error) by default. |
119 | - if ($if_exists == 'overwrite') |
|
120 | - $smcFunc['db_drop_table']($table_name); |
|
121 | - else |
|
122 | - return $if_exists == 'ignore'; |
|
122 | + if ($if_exists == 'overwrite') { |
|
123 | + $smcFunc['db_drop_table']($table_name); |
|
124 | + } else { |
|
125 | + return $if_exists == 'ignore'; |
|
126 | + } |
|
123 | 127 | } |
124 | 128 | |
125 | 129 | // Righty - let's do the damn thing! |
126 | 130 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
127 | - foreach ($columns as $column) |
|
128 | - $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
131 | + foreach ($columns as $column) { |
|
132 | + $table_query .= "\n\t" . smf_db_create_query_column($column) . ','; |
|
133 | + } |
|
129 | 134 | |
130 | 135 | // Loop through the indexes next... |
131 | 136 | foreach ($indexes as $index) |
@@ -133,19 +138,21 @@ discard block |
||
133 | 138 | $columns = implode(',', $index['columns']); |
134 | 139 | |
135 | 140 | // Is it the primary? |
136 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
137 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
138 | - else |
|
141 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
142 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
143 | + } else |
|
139 | 144 | { |
140 | - if (empty($index['name'])) |
|
141 | - $index['name'] = implode('_', $index['columns']); |
|
145 | + if (empty($index['name'])) { |
|
146 | + $index['name'] = implode('_', $index['columns']); |
|
147 | + } |
|
142 | 148 | $table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),'; |
143 | 149 | } |
144 | 150 | } |
145 | 151 | |
146 | 152 | // No trailing commas! |
147 | - if (substr($table_query, -1) == ',') |
|
148 | - $table_query = substr($table_query, 0, -1); |
|
153 | + if (substr($table_query, -1) == ',') { |
|
154 | + $table_query = substr($table_query, 0, -1); |
|
155 | + } |
|
149 | 156 | |
150 | 157 | // Which engine do we want here? |
151 | 158 | if (empty($engines)) |
@@ -155,8 +162,9 @@ discard block |
||
155 | 162 | |
156 | 163 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
157 | 164 | { |
158 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
159 | - $engines[] = $row['Engine']; |
|
165 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
166 | + $engines[] = $row['Engine']; |
|
167 | + } |
|
160 | 168 | } |
161 | 169 | |
162 | 170 | $smcFunc['db_free_result']($get_engines); |
@@ -170,8 +178,9 @@ discard block |
||
170 | 178 | } |
171 | 179 | |
172 | 180 | $table_query .= ') ENGINE=' . $parameters['engine']; |
173 | - if (!empty($db_character_set) && $db_character_set == 'utf8') |
|
174 | - $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
181 | + if (!empty($db_character_set) && $db_character_set == 'utf8') { |
|
182 | + $table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
183 | + } |
|
175 | 184 | |
176 | 185 | // Create the table! |
177 | 186 | $smcFunc['db_query']('', $table_query, |
@@ -203,8 +212,9 @@ discard block |
||
203 | 212 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
204 | 213 | |
205 | 214 | // God no - dropping one of these = bad. |
206 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
207 | - return false; |
|
215 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
216 | + return false; |
|
217 | + } |
|
208 | 218 | |
209 | 219 | // Does it exist? |
210 | 220 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -245,14 +255,16 @@ discard block |
||
245 | 255 | |
246 | 256 | // Does it exist - if so don't add it again! |
247 | 257 | $columns = $smcFunc['db_list_columns']($table_name, false); |
248 | - foreach ($columns as $column) |
|
249 | - if ($column == $column_info['name']) |
|
258 | + foreach ($columns as $column) { |
|
259 | + if ($column == $column_info['name']) |
|
250 | 260 | { |
251 | 261 | // If we're going to overwrite then use change column. |
252 | 262 | if ($if_exists == 'update') |
253 | 263 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
254 | - else |
|
255 | - return false; |
|
264 | + } |
|
265 | + else { |
|
266 | + return false; |
|
267 | + } |
|
256 | 268 | } |
257 | 269 | |
258 | 270 | // Get the specifics... |
@@ -288,8 +300,8 @@ discard block |
||
288 | 300 | |
289 | 301 | // Does it exist? |
290 | 302 | $columns = $smcFunc['db_list_columns']($table_name, true); |
291 | - foreach ($columns as $column) |
|
292 | - if ($column['name'] == $column_name) |
|
303 | + foreach ($columns as $column) { |
|
304 | + if ($column['name'] == $column_name) |
|
293 | 305 | { |
294 | 306 | $smcFunc['db_query']('', ' |
295 | 307 | ALTER TABLE ' . $table_name . ' |
@@ -298,6 +310,7 @@ discard block |
||
298 | 310 | 'security_override' => true, |
299 | 311 | ) |
300 | 312 | ); |
313 | + } |
|
301 | 314 | |
302 | 315 | return true; |
303 | 316 | } |
@@ -323,37 +336,47 @@ discard block |
||
323 | 336 | // Check it does exist! |
324 | 337 | $columns = $smcFunc['db_list_columns']($table_name, true); |
325 | 338 | $old_info = null; |
326 | - foreach ($columns as $column) |
|
327 | - if ($column['name'] == $old_column) |
|
339 | + foreach ($columns as $column) { |
|
340 | + if ($column['name'] == $old_column) |
|
328 | 341 | $old_info = $column; |
342 | + } |
|
329 | 343 | |
330 | 344 | // Nothing? |
331 | - if ($old_info == null) |
|
332 | - return false; |
|
345 | + if ($old_info == null) { |
|
346 | + return false; |
|
347 | + } |
|
333 | 348 | |
334 | 349 | // Get the right bits. |
335 | - if (!isset($column_info['name'])) |
|
336 | - $column_info['name'] = $old_column; |
|
337 | - if (!isset($column_info['default'])) |
|
338 | - $column_info['default'] = $old_info['default']; |
|
339 | - if (!isset($column_info['null'])) |
|
340 | - $column_info['null'] = $old_info['null']; |
|
341 | - if (!isset($column_info['auto'])) |
|
342 | - $column_info['auto'] = $old_info['auto']; |
|
343 | - if (!isset($column_info['type'])) |
|
344 | - $column_info['type'] = $old_info['type']; |
|
345 | - if (!isset($column_info['size']) || !is_numeric($column_info['size'])) |
|
346 | - $column_info['size'] = $old_info['size']; |
|
347 | - if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) |
|
348 | - $column_info['unsigned'] = ''; |
|
350 | + if (!isset($column_info['name'])) { |
|
351 | + $column_info['name'] = $old_column; |
|
352 | + } |
|
353 | + if (!isset($column_info['default'])) { |
|
354 | + $column_info['default'] = $old_info['default']; |
|
355 | + } |
|
356 | + if (!isset($column_info['null'])) { |
|
357 | + $column_info['null'] = $old_info['null']; |
|
358 | + } |
|
359 | + if (!isset($column_info['auto'])) { |
|
360 | + $column_info['auto'] = $old_info['auto']; |
|
361 | + } |
|
362 | + if (!isset($column_info['type'])) { |
|
363 | + $column_info['type'] = $old_info['type']; |
|
364 | + } |
|
365 | + if (!isset($column_info['size']) || !is_numeric($column_info['size'])) { |
|
366 | + $column_info['size'] = $old_info['size']; |
|
367 | + } |
|
368 | + if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) { |
|
369 | + $column_info['unsigned'] = ''; |
|
370 | + } |
|
349 | 371 | |
350 | 372 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
351 | 373 | |
352 | 374 | // Allow for unsigned integers (mysql only) |
353 | 375 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : ''; |
354 | 376 | |
355 | - if ($size !== null) |
|
356 | - $type = $type . '(' . $size . ')'; |
|
377 | + if ($size !== null) { |
|
378 | + $type = $type . '(' . $size . ')'; |
|
379 | + } |
|
357 | 380 | |
358 | 381 | $smcFunc['db_query']('', ' |
359 | 382 | ALTER TABLE ' . $table_name . ' |
@@ -383,18 +406,20 @@ discard block |
||
383 | 406 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
384 | 407 | |
385 | 408 | // No columns = no index. |
386 | - if (empty($index_info['columns'])) |
|
387 | - return false; |
|
409 | + if (empty($index_info['columns'])) { |
|
410 | + return false; |
|
411 | + } |
|
388 | 412 | $columns = implode(',', $index_info['columns']); |
389 | 413 | |
390 | 414 | // No name - make it up! |
391 | 415 | if (empty($index_info['name'])) |
392 | 416 | { |
393 | 417 | // No need for primary. |
394 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
395 | - $index_info['name'] = ''; |
|
396 | - else |
|
397 | - $index_info['name'] = implode('_', $index_info['columns']); |
|
418 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
419 | + $index_info['name'] = ''; |
|
420 | + } else { |
|
421 | + $index_info['name'] = implode('_', $index_info['columns']); |
|
422 | + } |
|
398 | 423 | } |
399 | 424 | |
400 | 425 | // Log that we are going to want to remove this! |
@@ -408,10 +433,11 @@ discard block |
||
408 | 433 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
409 | 434 | { |
410 | 435 | // If we want to overwrite simply remove the current one then continue. |
411 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
412 | - return false; |
|
413 | - else |
|
414 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
436 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
437 | + return false; |
|
438 | + } else { |
|
439 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
440 | + } |
|
415 | 441 | } |
416 | 442 | } |
417 | 443 | |
@@ -425,8 +451,7 @@ discard block |
||
425 | 451 | 'security_override' => true, |
426 | 452 | ) |
427 | 453 | ); |
428 | - } |
|
429 | - else |
|
454 | + } else |
|
430 | 455 | { |
431 | 456 | $smcFunc['db_query']('', ' |
432 | 457 | ALTER TABLE ' . $table_name . ' |
@@ -510,8 +535,7 @@ discard block |
||
510 | 535 | $types = array( |
511 | 536 | 'inet' => 'varbinary', |
512 | 537 | ); |
513 | - } |
|
514 | - else |
|
538 | + } else |
|
515 | 539 | { |
516 | 540 | $types = array( |
517 | 541 | 'varbinary' => 'inet', |
@@ -525,16 +549,15 @@ discard block |
||
525 | 549 | { |
526 | 550 | $type_size = 16; |
527 | 551 | $type_name = 'varbinary'; |
528 | - } |
|
529 | - elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
552 | + } elseif ($type_name == 'varbinary' && $reverse && $type_size == 16) |
|
530 | 553 | { |
531 | 554 | $type_name = 'inet'; |
532 | 555 | $type_size = null; |
556 | + } elseif ($type_name == 'varbinary') { |
|
557 | + $type_name = 'varbinary'; |
|
558 | + } else { |
|
559 | + $type_name = $types[$type_name]; |
|
533 | 560 | } |
534 | - elseif ($type_name == 'varbinary') |
|
535 | - $type_name = 'varbinary'; |
|
536 | - else |
|
537 | - $type_name = $types[$type_name]; |
|
538 | 561 | } |
539 | 562 | |
540 | 563 | return array($type_name, $type_size); |
@@ -601,8 +624,7 @@ discard block |
||
601 | 624 | if (!$detail) |
602 | 625 | { |
603 | 626 | $columns[] = $row['Field']; |
604 | - } |
|
605 | - else |
|
627 | + } else |
|
606 | 628 | { |
607 | 629 | // Is there an auto_increment? |
608 | 630 | $auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false; |
@@ -612,10 +634,10 @@ discard block |
||
612 | 634 | { |
613 | 635 | $type = $matches[1]; |
614 | 636 | $size = $matches[2]; |
615 | - if (!empty($matches[3]) && $matches[3] == 'unsigned') |
|
616 | - $unsigned = true; |
|
617 | - } |
|
618 | - else |
|
637 | + if (!empty($matches[3]) && $matches[3] == 'unsigned') { |
|
638 | + $unsigned = true; |
|
639 | + } |
|
640 | + } else |
|
619 | 641 | { |
620 | 642 | $type = $row['Type']; |
621 | 643 | $size = null; |
@@ -666,19 +688,20 @@ discard block |
||
666 | 688 | $indexes = array(); |
667 | 689 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
668 | 690 | { |
669 | - if (!$detail) |
|
670 | - $indexes[] = $row['Key_name']; |
|
671 | - else |
|
691 | + if (!$detail) { |
|
692 | + $indexes[] = $row['Key_name']; |
|
693 | + } else |
|
672 | 694 | { |
673 | 695 | // What is the type? |
674 | - if ($row['Key_name'] == 'PRIMARY') |
|
675 | - $type = 'primary'; |
|
676 | - elseif (empty($row['Non_unique'])) |
|
677 | - $type = 'unique'; |
|
678 | - elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') |
|
679 | - $type = 'fulltext'; |
|
680 | - else |
|
681 | - $type = 'index'; |
|
696 | + if ($row['Key_name'] == 'PRIMARY') { |
|
697 | + $type = 'primary'; |
|
698 | + } elseif (empty($row['Non_unique'])) { |
|
699 | + $type = 'unique'; |
|
700 | + } elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') { |
|
701 | + $type = 'fulltext'; |
|
702 | + } else { |
|
703 | + $type = 'index'; |
|
704 | + } |
|
682 | 705 | |
683 | 706 | // This is the first column we've seen? |
684 | 707 | if (empty($indexes[$row['Key_name']])) |
@@ -691,10 +714,11 @@ discard block |
||
691 | 714 | } |
692 | 715 | |
693 | 716 | // Is it a partial index? |
694 | - if (!empty($row['Sub_part'])) |
|
695 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
696 | - else |
|
697 | - $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
717 | + if (!empty($row['Sub_part'])) { |
|
718 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')'; |
|
719 | + } else { |
|
720 | + $indexes[$row['Key_name']]['columns'][] = $row['Column_name']; |
|
721 | + } |
|
698 | 722 | } |
699 | 723 | } |
700 | 724 | $smcFunc['db_free_result']($result); |
@@ -716,11 +740,11 @@ discard block |
||
716 | 740 | if (!empty($column['auto'])) |
717 | 741 | { |
718 | 742 | $default = 'auto_increment'; |
743 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
744 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
745 | + } else { |
|
746 | + $default = ''; |
|
719 | 747 | } |
720 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
721 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
722 | - else |
|
723 | - $default = ''; |
|
724 | 748 | |
725 | 749 | // Sort out the size... and stuff... |
726 | 750 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
@@ -729,8 +753,9 @@ discard block |
||
729 | 753 | // Allow unsigned integers (mysql only) |
730 | 754 | $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; |
731 | 755 | |
732 | - if ($size !== null) |
|
733 | - $type = $type . '(' . $size . ')'; |
|
756 | + if ($size !== null) { |
|
757 | + $type = $type . '(' . $size . ')'; |
|
758 | + } |
|
734 | 759 | |
735 | 760 | // Now just put it together! |
736 | 761 | return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; |