@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * Display a list of upcoming events, birthdays, and holidays. |
| 69 | 69 | * |
| 70 | 70 | * @param string $grid_name The grid name |
| 71 | - * @return void|bool Returns false if the grid doesn't exist. |
|
| 71 | + * @return false|null Returns false if the grid doesn't exist. |
|
| 72 | 72 | */ |
| 73 | 73 | function template_show_upcoming_list($grid_name) |
| 74 | 74 | { |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @param string $grid_name The grid name |
| 240 | 240 | * @param bool $is_mini Is this a mini grid? |
| 241 | - * @return void|bool Returns false if the grid doesn't exist. |
|
| 241 | + * @return false|null Returns false if the grid doesn't exist. |
|
| 242 | 242 | */ |
| 243 | 243 | function template_show_month_grid($grid_name, $is_mini = false) |
| 244 | 244 | { |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | * Shows a weekly grid |
| 524 | 524 | * |
| 525 | 525 | * @param string $grid_name The name of the grid |
| 526 | - * @return void|bool Returns false if the grid doesn't exist |
|
| 526 | + * @return false|null Returns false if the grid doesn't exist |
|
| 527 | 527 | */ |
| 528 | 528 | function template_show_week_grid($grid_name) |
| 529 | 529 | { |
@@ -437,9 +437,9 @@ discard block |
||
| 437 | 437 | { |
| 438 | 438 | // Sort events by start time (all day events will be listed first) |
| 439 | 439 | uasort($day['events'], function($a, $b) { |
| 440 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 441 | - return 0; |
|
| 442 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
| 440 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 441 | + return 0; |
|
| 442 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
| 443 | 443 | }); |
| 444 | 444 | |
| 445 | 445 | echo ' |
@@ -619,9 +619,9 @@ discard block |
||
| 619 | 619 | { |
| 620 | 620 | // Sort events by start time (all day events will be listed first) |
| 621 | 621 | uasort($day['events'], function($a, $b) { |
| 622 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 623 | - return 0; |
|
| 624 | - return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
| 622 | + if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 623 | + return 0; |
|
| 624 | + return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
|
| 625 | 625 | }); |
| 626 | 626 | |
| 627 | 627 | foreach ($day['events'] as $event) |
@@ -40,16 +40,14 @@ discard block |
||
| 40 | 40 | ', template_show_upcoming_list('main'), ' |
| 41 | 41 | </div> |
| 42 | 42 | '; |
| 43 | - } |
|
| 44 | - elseif ($context['calendar_view'] == 'viewweek') |
|
| 43 | + } elseif ($context['calendar_view'] == 'viewweek') |
|
| 45 | 44 | { |
| 46 | 45 | echo ' |
| 47 | 46 | <div id="main_grid"> |
| 48 | 47 | ', template_show_week_grid('main'), ' |
| 49 | 48 | </div> |
| 50 | 49 | '; |
| 51 | - } |
|
| 52 | - else |
|
| 50 | + } else |
|
| 53 | 51 | { |
| 54 | 52 | echo ' |
| 55 | 53 | <div id="main_grid"> |
@@ -75,8 +73,9 @@ discard block |
||
| 75 | 73 | global $context, $scripturl, $txt; |
| 76 | 74 | |
| 77 | 75 | // Bail out if we have nothing to work with |
| 78 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 79 | - return false; |
|
| 76 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 80 | 79 | |
| 81 | 80 | // Protect programmer sanity |
| 82 | 81 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -113,11 +112,13 @@ discard block |
||
| 113 | 112 | <li class="windowbg"> |
| 114 | 113 | <b class="event_title">', $event['link'], '</b>'; |
| 115 | 114 | |
| 116 | - if ($event['can_edit']) |
|
| 117 | - echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
| 115 | + if ($event['can_edit']) { |
|
| 116 | + echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if ($event['can_export']) |
|
| 120 | - echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
| 119 | + if ($event['can_export']) { |
|
| 120 | + echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
| 121 | + } |
|
| 121 | 122 | |
| 122 | 123 | echo ' |
| 123 | 124 | <br>'; |
@@ -125,14 +126,14 @@ discard block |
||
| 125 | 126 | if (!empty($event['allday'])) |
| 126 | 127 | { |
| 127 | 128 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' – <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : ''; |
| 128 | - } |
|
| 129 | - else |
|
| 129 | + } else |
|
| 130 | 130 | { |
| 131 | 131 | // Display event info relative to user's local timezone |
| 132 | 132 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
| 133 | 133 | |
| 134 | - if ($event['start_date_local'] != $event['end_date_local']) |
|
| 135 | - echo trim($event['end_date_local']) . ', '; |
|
| 134 | + if ($event['start_date_local'] != $event['end_date_local']) { |
|
| 135 | + echo trim($event['end_date_local']) . ', '; |
|
| 136 | + } |
|
| 136 | 137 | |
| 137 | 138 | echo trim($event['end_time_local']); |
| 138 | 139 | |
@@ -141,23 +142,27 @@ discard block |
||
| 141 | 142 | { |
| 142 | 143 | echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">'; |
| 143 | 144 | |
| 144 | - if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) |
|
| 145 | - echo trim($event['start_date_orig']), ', '; |
|
| 145 | + if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) { |
|
| 146 | + echo trim($event['start_date_orig']), ', '; |
|
| 147 | + } |
|
| 146 | 148 | |
| 147 | 149 | echo trim($event['start_time_orig']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
| 148 | 150 | |
| 149 | - if ($event['start_date_orig'] != $event['end_date_orig']) |
|
| 150 | - echo trim($event['end_date_orig']) . ', '; |
|
| 151 | + if ($event['start_date_orig'] != $event['end_date_orig']) { |
|
| 152 | + echo trim($event['end_date_orig']) . ', '; |
|
| 153 | + } |
|
| 151 | 154 | |
| 152 | 155 | echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)'; |
| 153 | 156 | } |
| 154 | 157 | // Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion |
| 155 | - else |
|
| 156 | - echo ' ', $event['tz_abbrev'], '</time>'; |
|
| 158 | + else { |
|
| 159 | + echo ' ', $event['tz_abbrev'], '</time>'; |
|
| 160 | + } |
|
| 157 | 161 | } |
| 158 | 162 | |
| 159 | - if (!empty($event['location'])) |
|
| 160 | - echo '<br>', $event['location']; |
|
| 163 | + if (!empty($event['location'])) { |
|
| 164 | + echo '<br>', $event['location']; |
|
| 165 | + } |
|
| 161 | 166 | |
| 162 | 167 | echo ' |
| 163 | 168 | </li>'; |
@@ -189,8 +194,9 @@ discard block |
||
| 189 | 194 | |
| 190 | 195 | $birthdays = array(); |
| 191 | 196 | |
| 192 | - foreach ($date as $member) |
|
| 193 | - $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
| 197 | + foreach ($date as $member) { |
|
| 198 | + $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
| 199 | + } |
|
| 194 | 200 | |
| 195 | 201 | echo implode(', ', $birthdays); |
| 196 | 202 | |
@@ -221,8 +227,9 @@ discard block |
||
| 221 | 227 | $date_local = $date['date_local']; |
| 222 | 228 | unset($date['date_local']); |
| 223 | 229 | |
| 224 | - foreach ($date as $holiday) |
|
| 225 | - $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
| 230 | + foreach ($date as $holiday) { |
|
| 231 | + $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
| 232 | + } |
|
| 226 | 233 | } |
| 227 | 234 | |
| 228 | 235 | echo implode(', ', $holidays); |
@@ -245,17 +252,19 @@ discard block |
||
| 245 | 252 | global $context, $txt, $scripturl, $modSettings; |
| 246 | 253 | |
| 247 | 254 | // If the grid doesn't exist, no point in proceeding. |
| 248 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 249 | - return false; |
|
| 255 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 250 | 258 | |
| 251 | 259 | // A handy little pointer variable. |
| 252 | 260 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
| 253 | 261 | |
| 254 | 262 | // Some conditions for whether or not we should show the week links *here*. |
| 255 | - if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) |
|
| 256 | - $show_week_links = true; |
|
| 257 | - else |
|
| 258 | - $show_week_links = false; |
|
| 263 | + if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) { |
|
| 264 | + $show_week_links = true; |
|
| 265 | + } else { |
|
| 266 | + $show_week_links = false; |
|
| 267 | + } |
|
| 259 | 268 | |
| 260 | 269 | // Assuming that we've not disabled it, show the title block! |
| 261 | 270 | if (empty($calendar_data['disable_title'])) |
@@ -294,8 +303,9 @@ discard block |
||
| 294 | 303 | } |
| 295 | 304 | |
| 296 | 305 | // Show the controls on main grids |
| 297 | - if ($is_mini === false) |
|
| 298 | - template_calendar_top($calendar_data); |
|
| 306 | + if ($is_mini === false) { |
|
| 307 | + template_calendar_top($calendar_data); |
|
| 308 | + } |
|
| 299 | 309 | |
| 300 | 310 | // Finally, the main calendar table. |
| 301 | 311 | echo '<table class="calendar_table">'; |
@@ -306,8 +316,9 @@ discard block |
||
| 306 | 316 | echo '<tr>'; |
| 307 | 317 | |
| 308 | 318 | // If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared! |
| 309 | - if ($show_week_links === true) |
|
| 310 | - echo '<th> </th>'; |
|
| 319 | + if ($show_week_links === true) { |
|
| 320 | + echo '<th> </th>'; |
|
| 321 | + } |
|
| 311 | 322 | |
| 312 | 323 | // Now, loop through each actual day of the week. |
| 313 | 324 | foreach ($calendar_data['week_days'] as $day) |
@@ -354,27 +365,29 @@ discard block |
||
| 354 | 365 | // Additional classes are given for events, holidays, and birthdays. |
| 355 | 366 | if (!empty($day['events']) && !empty($calendar_data['highlight']['events'])) |
| 356 | 367 | { |
| 357 | - if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) |
|
| 358 | - $classes[] = 'events'; |
|
| 359 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) |
|
| 360 | - $classes[] = 'events'; |
|
| 368 | + if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) { |
|
| 369 | + $classes[] = 'events'; |
|
| 370 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) { |
|
| 371 | + $classes[] = 'events'; |
|
| 372 | + } |
|
| 361 | 373 | } |
| 362 | 374 | if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays'])) |
| 363 | 375 | { |
| 364 | - if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) |
|
| 365 | - $classes[] = 'holidays'; |
|
| 366 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) |
|
| 367 | - $classes[] = 'holidays'; |
|
| 376 | + if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) { |
|
| 377 | + $classes[] = 'holidays'; |
|
| 378 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) { |
|
| 379 | + $classes[] = 'holidays'; |
|
| 380 | + } |
|
| 368 | 381 | } |
| 369 | 382 | if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays'])) |
| 370 | 383 | { |
| 371 | - if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) |
|
| 372 | - $classes[] = 'birthdays'; |
|
| 373 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) |
|
| 374 | - $classes[] = 'birthdays'; |
|
| 384 | + if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) { |
|
| 385 | + $classes[] = 'birthdays'; |
|
| 386 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) { |
|
| 387 | + $classes[] = 'birthdays'; |
|
| 388 | + } |
|
| 375 | 389 | } |
| 376 | - } |
|
| 377 | - else |
|
| 390 | + } else |
|
| 378 | 391 | { |
| 379 | 392 | // Default Classes (either compact or comfortable and disabled). |
| 380 | 393 | $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable'; |
@@ -392,19 +405,21 @@ discard block |
||
| 392 | 405 | $title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : ''; |
| 393 | 406 | |
| 394 | 407 | // The actual day number - be it a link, or just plain old text! |
| 395 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
| 396 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
| 397 | - elseif ($is_mini) |
|
| 398 | - echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
| 399 | - else |
|
| 400 | - echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
| 408 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
| 409 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
| 410 | + } elseif ($is_mini) { |
|
| 411 | + echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
| 412 | + } else { |
|
| 413 | + echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
| 414 | + } |
|
| 401 | 415 | |
| 402 | 416 | // A lot of stuff, we're not showing on mini-calendars to conserve space. |
| 403 | 417 | if ($is_mini === false) |
| 404 | 418 | { |
| 405 | 419 | // Holidays are always fun, let's show them! |
| 406 | - if (!empty($day['holidays'])) |
|
| 407 | - echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
| 420 | + if (!empty($day['holidays'])) { |
|
| 421 | + echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
| 422 | + } |
|
| 408 | 423 | |
| 409 | 424 | // Happy Birthday Dear, Member! |
| 410 | 425 | if (!empty($day['birthdays'])) |
@@ -422,14 +437,16 @@ discard block |
||
| 422 | 437 | echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', '; |
| 423 | 438 | |
| 424 | 439 | // 9...10! Let's stop there. |
| 425 | - if ($birthday_count == 10 && $use_js_hide) |
|
| 426 | - // !!TODO - Inline CSS and JavaScript should be moved. |
|
| 440 | + if ($birthday_count == 10 && $use_js_hide) { |
|
| 441 | + // !!TODO - Inline CSS and JavaScript should be moved. |
|
| 427 | 442 | echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, '; |
| 443 | + } |
|
| 428 | 444 | |
| 429 | 445 | ++$birthday_count; |
| 430 | 446 | } |
| 431 | - if ($use_js_hide) |
|
| 432 | - echo '</span>'; |
|
| 447 | + if ($use_js_hide) { |
|
| 448 | + echo '</span>'; |
|
| 449 | + } |
|
| 433 | 450 | |
| 434 | 451 | echo '</div>'; |
| 435 | 452 | } |
@@ -439,8 +456,9 @@ discard block |
||
| 439 | 456 | { |
| 440 | 457 | // Sort events by start time (all day events will be listed first) |
| 441 | 458 | uasort($day['events'], function($a, $b) { |
| 442 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 443 | - return 0; |
|
| 459 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
| 460 | + return 0; |
|
| 461 | + } |
|
| 444 | 462 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
| 445 | 463 | }); |
| 446 | 464 | |
@@ -456,17 +474,19 @@ discard block |
||
| 456 | 474 | |
| 457 | 475 | echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
| 458 | 476 | |
| 459 | - if (!empty($event['start_time_local']) && $event['starts_today'] == true) |
|
| 460 | - echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
| 461 | - elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) |
|
| 462 | - echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
| 463 | - elseif (!empty($event['allday'])) |
|
| 464 | - echo $txt['calendar_allday']; |
|
| 477 | + if (!empty($event['start_time_local']) && $event['starts_today'] == true) { |
|
| 478 | + echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
| 479 | + } elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) { |
|
| 480 | + echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
| 481 | + } elseif (!empty($event['allday'])) { |
|
| 482 | + echo $txt['calendar_allday']; |
|
| 483 | + } |
|
| 465 | 484 | |
| 466 | 485 | echo '</span>'; |
| 467 | 486 | |
| 468 | - if (!empty($event['location'])) |
|
| 469 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
| 487 | + if (!empty($event['location'])) { |
|
| 488 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
| 489 | + } |
|
| 470 | 490 | |
| 471 | 491 | if ($event['can_edit'] || $event['can_export']) |
| 472 | 492 | { |
@@ -503,10 +523,11 @@ discard block |
||
| 503 | 523 | // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days! |
| 504 | 524 | elseif ($is_mini === false) |
| 505 | 525 | { |
| 506 | - if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) |
|
| 507 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
| 508 | - elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) |
|
| 509 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
| 526 | + if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) { |
|
| 527 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
| 528 | + } elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) { |
|
| 529 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
| 530 | + } |
|
| 510 | 531 | } |
| 511 | 532 | |
| 512 | 533 | // Close this day and increase var count. |
@@ -532,8 +553,9 @@ discard block |
||
| 532 | 553 | global $context, $txt, $scripturl, $modSettings; |
| 533 | 554 | |
| 534 | 555 | // We might have no reason to proceed, if the variable isn't there. |
| 535 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 536 | - return false; |
|
| 556 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 557 | + return false; |
|
| 558 | + } |
|
| 537 | 559 | |
| 538 | 560 | // Handy pointer. |
| 539 | 561 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -568,8 +590,9 @@ discard block |
||
| 568 | 590 | } |
| 569 | 591 | |
| 570 | 592 | // The Month Title + Week Number... |
| 571 | - if (!empty($calendar_data['week_title'])) |
|
| 572 | - echo $calendar_data['week_title']; |
|
| 593 | + if (!empty($calendar_data['week_title'])) { |
|
| 594 | + echo $calendar_data['week_title']; |
|
| 595 | + } |
|
| 573 | 596 | |
| 574 | 597 | echo ' |
| 575 | 598 | </h3> |
@@ -608,10 +631,11 @@ discard block |
||
| 608 | 631 | <tr class="days_wrapper"> |
| 609 | 632 | <td class="', implode(' ', $classes), ' act_day">'; |
| 610 | 633 | // Should the day number be a link? |
| 611 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
| 612 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
| 613 | - else |
|
| 614 | - echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
| 634 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
| 635 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
| 636 | + } else { |
|
| 637 | + echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
| 638 | + } |
|
| 615 | 639 | |
| 616 | 640 | echo '</td> |
| 617 | 641 | <td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">'; |
@@ -620,8 +644,9 @@ discard block |
||
| 620 | 644 | { |
| 621 | 645 | // Sort events by start time (all day events will be listed first) |
| 622 | 646 | uasort($day['events'], function($a, $b) { |
| 623 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 624 | - return 0; |
|
| 647 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
| 648 | + return 0; |
|
| 649 | + } |
|
| 625 | 650 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
| 626 | 651 | }); |
| 627 | 652 | |
@@ -633,15 +658,17 @@ discard block |
||
| 633 | 658 | |
| 634 | 659 | echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
| 635 | 660 | |
| 636 | - if (!empty($event['start_time_local'])) |
|
| 637 | - echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
| 638 | - else |
|
| 639 | - echo $txt['calendar_allday']; |
|
| 661 | + if (!empty($event['start_time_local'])) { |
|
| 662 | + echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
| 663 | + } else { |
|
| 664 | + echo $txt['calendar_allday']; |
|
| 665 | + } |
|
| 640 | 666 | |
| 641 | 667 | echo '</span>'; |
| 642 | 668 | |
| 643 | - if (!empty($event['location'])) |
|
| 644 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
| 669 | + if (!empty($event['location'])) { |
|
| 670 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
| 671 | + } |
|
| 645 | 672 | |
| 646 | 673 | if (!empty($event_icons_needed)) |
| 647 | 674 | { |
@@ -678,8 +705,7 @@ discard block |
||
| 678 | 705 | </div> |
| 679 | 706 | <br class="clear">'; |
| 680 | 707 | } |
| 681 | - } |
|
| 682 | - else |
|
| 708 | + } else |
|
| 683 | 709 | { |
| 684 | 710 | if (!empty($context['can_post'])) |
| 685 | 711 | { |
@@ -692,8 +718,9 @@ discard block |
||
| 692 | 718 | echo '</td> |
| 693 | 719 | <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">'; |
| 694 | 720 | // Show any holidays! |
| 695 | - if (!empty($day['holidays'])) |
|
| 696 | - echo implode('<br>', $day['holidays']); |
|
| 721 | + if (!empty($day['holidays'])) { |
|
| 722 | + echo implode('<br>', $day['holidays']); |
|
| 723 | + } |
|
| 697 | 724 | |
| 698 | 725 | echo '</td> |
| 699 | 726 | <td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">'; |
@@ -751,8 +778,7 @@ discard block |
||
| 751 | 778 | <input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date"> |
| 752 | 779 | <input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '"> |
| 753 | 780 | </form>'; |
| 754 | - } |
|
| 755 | - else |
|
| 781 | + } else |
|
| 756 | 782 | { |
| 757 | 783 | echo' |
| 758 | 784 | <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '"> |
@@ -794,8 +820,9 @@ discard block |
||
| 794 | 820 | echo ' |
| 795 | 821 | <form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">'; |
| 796 | 822 | |
| 797 | - if (!empty($context['event']['new'])) |
|
| 798 | - echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
| 823 | + if (!empty($context['event']['new'])) { |
|
| 824 | + echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
| 825 | + } |
|
| 799 | 826 | |
| 800 | 827 | // Start the main table. |
| 801 | 828 | echo ' |
@@ -845,9 +872,10 @@ discard block |
||
| 845 | 872 | { |
| 846 | 873 | echo ' |
| 847 | 874 | <optgroup label="', $category['name'], '">'; |
| 848 | - foreach ($category['boards'] as $board) |
|
| 849 | - echo ' |
|
| 875 | + foreach ($category['boards'] as $board) { |
|
| 876 | + echo ' |
|
| 850 | 877 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>'; |
| 878 | + } |
|
| 851 | 879 | echo ' |
| 852 | 880 | </optgroup>'; |
| 853 | 881 | } |
@@ -883,9 +911,10 @@ discard block |
||
| 883 | 911 | <span class="label">', $txt['calendar_timezone'], '</span> |
| 884 | 912 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
| 885 | 913 | |
| 886 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
| 887 | - echo ' |
|
| 914 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
| 915 | + echo ' |
|
| 888 | 916 | <option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
| 917 | + } |
|
| 889 | 918 | |
| 890 | 919 | echo ' |
| 891 | 920 | </select> |
@@ -900,9 +929,10 @@ discard block |
||
| 900 | 929 | echo ' |
| 901 | 930 | <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">'; |
| 902 | 931 | // Delete button? |
| 903 | - if (empty($context['event']['new'])) |
|
| 904 | - echo ' |
|
| 932 | + if (empty($context['event']['new'])) { |
|
| 933 | + echo ' |
|
| 905 | 934 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">'; |
| 935 | + } |
|
| 906 | 936 | |
| 907 | 937 | echo ' |
| 908 | 938 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -946,9 +976,10 @@ discard block |
||
| 946 | 976 | |
| 947 | 977 | foreach ($context['clockicons'] as $t => $v) |
| 948 | 978 | { |
| 949 | - foreach ($v as $i) |
|
| 950 | - echo ' |
|
| 979 | + foreach ($v as $i) { |
|
| 980 | + echo ' |
|
| 951 | 981 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 982 | + } |
|
| 952 | 983 | } |
| 953 | 984 | |
| 954 | 985 | echo ' |
@@ -973,13 +1004,14 @@ discard block |
||
| 973 | 1004 | |
| 974 | 1005 | foreach ($context['clockicons'] as $t => $v) |
| 975 | 1006 | { |
| 976 | - foreach ($v as $i) |
|
| 977 | - echo ' |
|
| 1007 | + foreach ($v as $i) { |
|
| 1008 | + echo ' |
|
| 978 | 1009 | if (', $t, ' >= ', $i, ') |
| 979 | 1010 | { |
| 980 | 1011 | turnon.push("', $t, '_', $i, '"); |
| 981 | 1012 | ', $t, ' -= ', $i, '; |
| 982 | 1013 | }'; |
| 1014 | + } |
|
| 983 | 1015 | } |
| 984 | 1016 | |
| 985 | 1017 | echo ' |
@@ -1043,9 +1075,10 @@ discard block |
||
| 1043 | 1075 | |
| 1044 | 1076 | foreach ($context['clockicons'] as $t => $v) |
| 1045 | 1077 | { |
| 1046 | - foreach ($v as $i) |
|
| 1047 | - echo ' |
|
| 1078 | + foreach ($v as $i) { |
|
| 1079 | + echo ' |
|
| 1048 | 1080 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 1081 | + } |
|
| 1049 | 1082 | } |
| 1050 | 1083 | |
| 1051 | 1084 | echo ' |
@@ -1062,13 +1095,14 @@ discard block |
||
| 1062 | 1095 | |
| 1063 | 1096 | foreach ($context['clockicons'] as $t => $v) |
| 1064 | 1097 | { |
| 1065 | - foreach ($v as $i) |
|
| 1066 | - echo ' |
|
| 1098 | + foreach ($v as $i) { |
|
| 1099 | + echo ' |
|
| 1067 | 1100 | if (', $t, ' >= ', $i, ') |
| 1068 | 1101 | { |
| 1069 | 1102 | turnon.push("', $t, '_', $i, '"); |
| 1070 | 1103 | ', $t, ' -= ', $i, '; |
| 1071 | 1104 | }'; |
| 1105 | + } |
|
| 1072 | 1106 | } |
| 1073 | 1107 | |
| 1074 | 1108 | echo ' |
@@ -1127,9 +1161,10 @@ discard block |
||
| 1127 | 1161 | |
| 1128 | 1162 | foreach ($context['clockicons'] as $t => $v) |
| 1129 | 1163 | { |
| 1130 | - foreach ($v as $i) |
|
| 1131 | - echo ' |
|
| 1164 | + foreach ($v as $i) { |
|
| 1165 | + echo ' |
|
| 1132 | 1166 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 1167 | + } |
|
| 1133 | 1168 | } |
| 1134 | 1169 | |
| 1135 | 1170 | echo ' |
@@ -1150,13 +1185,14 @@ discard block |
||
| 1150 | 1185 | |
| 1151 | 1186 | foreach ($context['clockicons'] as $t => $v) |
| 1152 | 1187 | { |
| 1153 | - foreach ($v as $i) |
|
| 1154 | - echo ' |
|
| 1188 | + foreach ($v as $i) { |
|
| 1189 | + echo ' |
|
| 1155 | 1190 | if (', $t, ' >= ', $i, ') |
| 1156 | 1191 | { |
| 1157 | 1192 | turnon.push("', $t, '_', $i, '"); |
| 1158 | 1193 | ', $t, ' -= ', $i, '; |
| 1159 | 1194 | }'; |
| 1195 | + } |
|
| 1160 | 1196 | } |
| 1161 | 1197 | |
| 1162 | 1198 | echo ' |
@@ -388,6 +388,9 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Used to direct the user to another location. |
| 391 | +/** |
|
| 392 | + * @param string $location |
|
| 393 | + */ |
|
| 391 | 394 | function redirectLocation($location, $addForm = true) |
| 392 | 395 | { |
| 393 | 396 | global $upgradeurl, $upcontext, $command_line; |
@@ -1560,6 +1563,9 @@ discard block |
||
| 1560 | 1563 | return addslashes(preg_replace(array('~^\.([/\\\]|$)~', '~[/]+~', '~[\\\]+~', '~[/\\\]$~'), array($install_path . '$1', '/', '\\', ''), $path)); |
| 1561 | 1564 | } |
| 1562 | 1565 | |
| 1566 | +/** |
|
| 1567 | + * @param string $filename |
|
| 1568 | + */ |
|
| 1563 | 1569 | function parse_sql($filename) |
| 1564 | 1570 | { |
| 1565 | 1571 | global $db_prefix, $db_collation, $boarddir, $boardurl, $command_line, $file_steps, $step_progress, $custom_warning; |
@@ -1594,6 +1600,10 @@ discard block |
||
| 1594 | 1600 | |
| 1595 | 1601 | // Our custom error handler - does nothing but does stop public errors from XML! |
| 1596 | 1602 | set_error_handler( |
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * @param string $errno |
|
| 1606 | + */ |
|
| 1597 | 1607 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
| 1598 | 1608 | { |
| 1599 | 1609 | if ($support_js) |
@@ -1840,6 +1850,9 @@ discard block |
||
| 1840 | 1850 | return true; |
| 1841 | 1851 | } |
| 1842 | 1852 | |
| 1853 | +/** |
|
| 1854 | + * @param string $string |
|
| 1855 | + */ |
|
| 1843 | 1856 | function upgrade_query($string, $unbuffered = false) |
| 1844 | 1857 | { |
| 1845 | 1858 | global $db_connection, $db_server, $db_user, $db_passwd, $db_type, $command_line, $upcontext, $upgradeurl, $modSettings; |
@@ -4495,7 +4508,7 @@ discard block |
||
| 4495 | 4508 | * @param int $setSize The amount of entries after which to update the database. |
| 4496 | 4509 | * |
| 4497 | 4510 | * newCol needs to be a varbinary(16) null able field |
| 4498 | - * @return bool |
|
| 4511 | + * @return boolean|null |
|
| 4499 | 4512 | */ |
| 4500 | 4513 | function MySQLConvertOldIp($targetTable, $oldCol, $newCol, $limit = 50000, $setSize = 100) |
| 4501 | 4514 | { |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | |
| 83 | 83 | // The helper is crucial. Include it first thing. |
| 84 | 84 | if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
| 85 | - die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
| 85 | + die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
|
| 86 | 86 | |
| 87 | 87 | require_once($upgrade_path . '/upgrade-helper.php'); |
| 88 | 88 | |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | |
| 1611 | 1611 | // Our custom error handler - does nothing but does stop public errors from XML! |
| 1612 | 1612 | set_error_handler( |
| 1613 | - function ($errno, $errstr, $errfile, $errline) use ($support_js) |
|
| 1613 | + function($errno, $errstr, $errfile, $errline) use ($support_js) |
|
| 1614 | 1614 | { |
| 1615 | 1615 | if ($support_js) |
| 1616 | 1616 | return true; |
@@ -2595,94 +2595,94 @@ discard block |
||
| 2595 | 2595 | // Translation table for the character sets not native for MySQL. |
| 2596 | 2596 | $translation_tables = array( |
| 2597 | 2597 | 'windows-1255' => array( |
| 2598 | - '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
| 2599 | - '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
| 2600 | - '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
| 2601 | - '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
| 2602 | - '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
| 2603 | - '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
| 2604 | - '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792', |
|
| 2605 | - '0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF', |
|
| 2606 | - '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
| 2607 | - '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
| 2608 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2609 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2610 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2611 | - '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
| 2612 | - '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
| 2613 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2614 | - '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
| 2615 | - '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
| 2616 | - '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
| 2617 | - '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
| 2618 | - '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
| 2619 | - '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
| 2620 | - '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
| 2621 | - '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
| 2622 | - '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
| 2623 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2624 | - '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
| 2625 | - '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2626 | - '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
| 2627 | - '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
| 2628 | - '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
| 2629 | - '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
| 2630 | - '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
| 2631 | - '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
| 2632 | - '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
| 2633 | - '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
| 2634 | - '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
| 2635 | - '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
| 2636 | - '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
| 2637 | - '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
| 2638 | - '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
| 2639 | - '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
| 2598 | + '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
| 2599 | + '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
| 2600 | + '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
| 2601 | + '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
| 2602 | + '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
| 2603 | + '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
| 2604 | + '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792', |
|
| 2605 | + '0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF', |
|
| 2606 | + '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
| 2607 | + '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
| 2608 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2609 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2610 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2611 | + '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
| 2612 | + '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
| 2613 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2614 | + '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
| 2615 | + '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
| 2616 | + '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
| 2617 | + '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
| 2618 | + '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
| 2619 | + '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
| 2620 | + '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
| 2621 | + '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
| 2622 | + '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
| 2623 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2624 | + '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
| 2625 | + '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2626 | + '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
| 2627 | + '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
| 2628 | + '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
| 2629 | + '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
| 2630 | + '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
| 2631 | + '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
| 2632 | + '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
| 2633 | + '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
| 2634 | + '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
| 2635 | + '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
| 2636 | + '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
| 2637 | + '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
| 2638 | + '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
| 2639 | + '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
| 2640 | 2640 | '0xFA' => '0xD7AA', |
| 2641 | 2641 | ), |
| 2642 | 2642 | 'windows-1253' => array( |
| 2643 | - '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
| 2644 | - '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
| 2645 | - '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
| 2646 | - '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
| 2647 | - '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
| 2648 | - '0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E', |
|
| 2649 | - '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
| 2650 | - '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
| 2651 | - '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
| 2652 | - '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
| 2653 | - '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
| 2654 | - '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
| 2655 | - '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
| 2656 | - '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
| 2657 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2658 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2659 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2660 | - '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
| 2661 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2662 | - '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
| 2663 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2664 | - '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
| 2665 | - '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
| 2666 | - '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
| 2667 | - '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2668 | - '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
| 2669 | - '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
| 2670 | - '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
| 2671 | - '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
| 2672 | - '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
| 2673 | - '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
| 2674 | - '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
| 2675 | - '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
| 2676 | - '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
| 2677 | - '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
| 2678 | - '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
| 2679 | - '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
| 2680 | - '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
| 2681 | - '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
| 2682 | - '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
| 2683 | - '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
| 2684 | - '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
| 2685 | - '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', |
|
| 2643 | + '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
| 2644 | + '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
| 2645 | + '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
| 2646 | + '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
| 2647 | + '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
| 2648 | + '0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E', |
|
| 2649 | + '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
| 2650 | + '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
| 2651 | + '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
| 2652 | + '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
| 2653 | + '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
| 2654 | + '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
| 2655 | + '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
| 2656 | + '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
| 2657 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2658 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2659 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2660 | + '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
| 2661 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2662 | + '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
| 2663 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2664 | + '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
| 2665 | + '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
| 2666 | + '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
| 2667 | + '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2668 | + '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
| 2669 | + '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
| 2670 | + '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
| 2671 | + '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
| 2672 | + '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
| 2673 | + '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
| 2674 | + '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
| 2675 | + '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
| 2676 | + '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
| 2677 | + '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
| 2678 | + '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
| 2679 | + '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
| 2680 | + '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
| 2681 | + '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
| 2682 | + '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
| 2683 | + '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
| 2684 | + '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
| 2685 | + '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', |
|
| 2686 | 2686 | ), |
| 2687 | 2687 | ); |
| 2688 | 2688 | |
@@ -3781,7 +3781,7 @@ discard block |
||
| 3781 | 3781 | <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post"> |
| 3782 | 3782 | <input type="hidden" name="backup_done" id="backup_done" value="0"> |
| 3783 | 3783 | <strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong> |
| 3784 | - <div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;"> |
|
| 3784 | + <div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;"> |
|
| 3785 | 3785 | <span id="debuginfo"></span> |
| 3786 | 3786 | </div>'; |
| 3787 | 3787 | |
@@ -4282,7 +4282,7 @@ discard block |
||
| 4282 | 4282 | <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post"> |
| 4283 | 4283 | <input type="hidden" name="utf8_done" id="utf8_done" value="0"> |
| 4284 | 4284 | <strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong> |
| 4285 | - <div id="debug_section" style="height: ', ($is_debug ? '97' : '12') , 'px; overflow: auto;"> |
|
| 4285 | + <div id="debug_section" style="height: ', ($is_debug ? '97' : '12'), 'px; overflow: auto;"> |
|
| 4286 | 4286 | <span id="debuginfo"></span> |
| 4287 | 4287 | </div>'; |
| 4288 | 4288 | |
@@ -4383,7 +4383,7 @@ discard block |
||
| 4383 | 4383 | <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post"> |
| 4384 | 4384 | <input type="hidden" name="json_done" id="json_done" value="0"> |
| 4385 | 4385 | <strong>Completed <span id="tab_done">', $upcontext['cur_table_num'], '</span> out of ', $upcontext['table_count'], ' tables.</strong> |
| 4386 | - <div id="debug_section" style="height: ', ($is_debug ? '115' : '12') , 'px; overflow: auto;"> |
|
| 4386 | + <div id="debug_section" style="height: ', ($is_debug ? '115' : '12'), 'px; overflow: auto;"> |
|
| 4387 | 4387 | <span id="debuginfo"></span> |
| 4388 | 4388 | </div>'; |
| 4389 | 4389 | |
@@ -75,8 +75,9 @@ discard block |
||
| 75 | 75 | $upcontext['inactive_timeout'] = 10; |
| 76 | 76 | |
| 77 | 77 | // The helper is crucial. Include it first thing. |
| 78 | -if (!file_exists($upgrade_path . '/upgrade-helper.php')) |
|
| 78 | +if (!file_exists($upgrade_path . '/upgrade-helper.php')) { |
|
| 79 | 79 | die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.'); |
| 80 | +} |
|
| 80 | 81 | |
| 81 | 82 | require_once($upgrade_path . '/upgrade-helper.php'); |
| 82 | 83 | |
@@ -100,11 +101,14 @@ discard block |
||
| 100 | 101 | ini_set('default_socket_timeout', 900); |
| 101 | 102 | } |
| 102 | 103 | // Clean the upgrade path if this is from the client. |
| 103 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
| 104 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
| 104 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
| 105 | + for ($i = 1; |
|
| 106 | +} |
|
| 107 | +$i < $_SERVER['argc']; $i++) |
|
| 105 | 108 | { |
| 106 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
| 107 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 109 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
| 110 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 111 | + } |
|
| 108 | 112 | } |
| 109 | 113 | |
| 110 | 114 | // Are we from the client? |
@@ -112,16 +116,17 @@ discard block |
||
| 112 | 116 | { |
| 113 | 117 | $command_line = true; |
| 114 | 118 | $disable_security = true; |
| 115 | -} |
|
| 116 | -else |
|
| 119 | +} else { |
|
| 117 | 120 | $command_line = false; |
| 121 | +} |
|
| 118 | 122 | |
| 119 | 123 | // Load this now just because we can. |
| 120 | 124 | require_once($upgrade_path . '/Settings.php'); |
| 121 | 125 | |
| 122 | 126 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
| 123 | -if (isset($language)) |
|
| 127 | +if (isset($language)) { |
|
| 124 | 128 | $language = str_ireplace('-utf8', '', $language); |
| 129 | +} |
|
| 125 | 130 | |
| 126 | 131 | // Are we logged in? |
| 127 | 132 | if (isset($upgradeData)) |
@@ -129,10 +134,12 @@ discard block |
||
| 129 | 134 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
| 130 | 135 | |
| 131 | 136 | // Check for sensible values. |
| 132 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
| 133 | - $upcontext['user']['started'] = time(); |
|
| 134 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
| 135 | - $upcontext['user']['updated'] = 0; |
|
| 137 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
| 138 | + $upcontext['user']['started'] = time(); |
|
| 139 | + } |
|
| 140 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
| 141 | + $upcontext['user']['updated'] = 0; |
|
| 142 | + } |
|
| 136 | 143 | |
| 137 | 144 | $upcontext['started'] = $upcontext['user']['started']; |
| 138 | 145 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -190,8 +197,9 @@ discard block |
||
| 190 | 197 | 'db_error_skip' => true, |
| 191 | 198 | ) |
| 192 | 199 | ); |
| 193 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 194 | - $modSettings[$row['variable']] = $row['value']; |
|
| 200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 201 | + $modSettings[$row['variable']] = $row['value']; |
|
| 202 | + } |
|
| 195 | 203 | $smcFunc['db_free_result']($request); |
| 196 | 204 | } |
| 197 | 205 | |
@@ -201,10 +209,12 @@ discard block |
||
| 201 | 209 | $modSettings['theme_url'] = 'Themes/default'; |
| 202 | 210 | $modSettings['images_url'] = 'Themes/default/images'; |
| 203 | 211 | } |
| 204 | -if (!isset($settings['default_theme_url'])) |
|
| 212 | +if (!isset($settings['default_theme_url'])) { |
|
| 205 | 213 | $settings['default_theme_url'] = $modSettings['theme_url']; |
| 206 | -if (!isset($settings['default_theme_dir'])) |
|
| 214 | +} |
|
| 215 | +if (!isset($settings['default_theme_dir'])) { |
|
| 207 | 216 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
| 217 | +} |
|
| 208 | 218 | |
| 209 | 219 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
| 210 | 220 | // Default title... |
@@ -222,13 +232,15 @@ discard block |
||
| 222 | 232 | $support_js = $upcontext['upgrade_status']['js']; |
| 223 | 233 | |
| 224 | 234 | // Only set this if the upgrader status says so. |
| 225 | - if (empty($is_debug)) |
|
| 226 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 235 | + if (empty($is_debug)) { |
|
| 236 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 237 | + } |
|
| 227 | 238 | |
| 228 | 239 | // Load the language. |
| 229 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 230 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 231 | -} |
|
| 240 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 241 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 242 | + } |
|
| 243 | + } |
|
| 232 | 244 | // Set the defaults. |
| 233 | 245 | else |
| 234 | 246 | { |
@@ -246,15 +258,18 @@ discard block |
||
| 246 | 258 | } |
| 247 | 259 | |
| 248 | 260 | // If this isn't the first stage see whether they are logging in and resuming. |
| 249 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
| 261 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
| 250 | 262 | checkLogin(); |
| 263 | +} |
|
| 251 | 264 | |
| 252 | -if ($command_line) |
|
| 265 | +if ($command_line) { |
|
| 253 | 266 | cmdStep0(); |
| 267 | +} |
|
| 254 | 268 | |
| 255 | 269 | // Don't error if we're using xml. |
| 256 | -if (isset($_GET['xml'])) |
|
| 270 | +if (isset($_GET['xml'])) { |
|
| 257 | 271 | $upcontext['return_error'] = true; |
| 272 | +} |
|
| 258 | 273 | |
| 259 | 274 | // Loop through all the steps doing each one as required. |
| 260 | 275 | $upcontext['overall_percent'] = 0; |
@@ -275,9 +290,9 @@ discard block |
||
| 275 | 290 | } |
| 276 | 291 | |
| 277 | 292 | // Call the step and if it returns false that means pause! |
| 278 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 279 | - break; |
|
| 280 | - elseif (function_exists($step[2])) { |
|
| 293 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 294 | + break; |
|
| 295 | + } elseif (function_exists($step[2])) { |
|
| 281 | 296 | //Start each new step with this unset, so the 'normal' template is called first |
| 282 | 297 | unset($_GET['xml']); |
| 283 | 298 | //Clear out warnings at the start of each step |
@@ -323,17 +338,18 @@ discard block |
||
| 323 | 338 | // This should not happen my dear... HELP ME DEVELOPERS!! |
| 324 | 339 | if (!empty($command_line)) |
| 325 | 340 | { |
| 326 | - if (function_exists('debug_print_backtrace')) |
|
| 327 | - debug_print_backtrace(); |
|
| 341 | + if (function_exists('debug_print_backtrace')) { |
|
| 342 | + debug_print_backtrace(); |
|
| 343 | + } |
|
| 328 | 344 | |
| 329 | 345 | echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.'; |
| 330 | 346 | flush(); |
| 331 | 347 | die(); |
| 332 | 348 | } |
| 333 | 349 | |
| 334 | - if (!isset($_GET['xml'])) |
|
| 335 | - template_upgrade_above(); |
|
| 336 | - else |
|
| 350 | + if (!isset($_GET['xml'])) { |
|
| 351 | + template_upgrade_above(); |
|
| 352 | + } else |
|
| 337 | 353 | { |
| 338 | 354 | header('Content-Type: text/xml; charset=UTF-8'); |
| 339 | 355 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -355,25 +371,29 @@ discard block |
||
| 355 | 371 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
| 356 | 372 | |
| 357 | 373 | // Custom stuff to pass back? |
| 358 | - if (!empty($upcontext['query_string'])) |
|
| 359 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 374 | + if (!empty($upcontext['query_string'])) { |
|
| 375 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 376 | + } |
|
| 360 | 377 | |
| 361 | 378 | // Call the appropriate subtemplate |
| 362 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
| 363 | - call_user_func('template_' . $upcontext['sub_template']); |
|
| 364 | - else |
|
| 365 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 379 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
| 380 | + call_user_func('template_' . $upcontext['sub_template']); |
|
| 381 | + } else { |
|
| 382 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 383 | + } |
|
| 366 | 384 | } |
| 367 | 385 | |
| 368 | 386 | // Was there an error? |
| 369 | - if (!empty($upcontext['forced_error_message'])) |
|
| 370 | - echo $upcontext['forced_error_message']; |
|
| 387 | + if (!empty($upcontext['forced_error_message'])) { |
|
| 388 | + echo $upcontext['forced_error_message']; |
|
| 389 | + } |
|
| 371 | 390 | |
| 372 | 391 | // Show the footer. |
| 373 | - if (!isset($_GET['xml'])) |
|
| 374 | - template_upgrade_below(); |
|
| 375 | - else |
|
| 376 | - template_xml_below(); |
|
| 392 | + if (!isset($_GET['xml'])) { |
|
| 393 | + template_upgrade_below(); |
|
| 394 | + } else { |
|
| 395 | + template_xml_below(); |
|
| 396 | + } |
|
| 377 | 397 | } |
| 378 | 398 | |
| 379 | 399 | |
@@ -385,15 +405,19 @@ discard block |
||
| 385 | 405 | $seconds = intval($active % 60); |
| 386 | 406 | |
| 387 | 407 | $totalTime = ''; |
| 388 | - if ($hours > 0) |
|
| 389 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 390 | - if ($minutes > 0) |
|
| 391 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 392 | - if ($seconds > 0) |
|
| 393 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 408 | + if ($hours > 0) { |
|
| 409 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 410 | + } |
|
| 411 | + if ($minutes > 0) { |
|
| 412 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 413 | + } |
|
| 414 | + if ($seconds > 0) { |
|
| 415 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 416 | + } |
|
| 394 | 417 | |
| 395 | - if (!empty($totalTime)) |
|
| 396 | - echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
| 418 | + if (!empty($totalTime)) { |
|
| 419 | + echo "\n" . 'Upgrade completed in ' . $totalTime . "\n"; |
|
| 420 | + } |
|
| 397 | 421 | } |
| 398 | 422 | |
| 399 | 423 | // Bang - gone! |
@@ -406,8 +430,9 @@ discard block |
||
| 406 | 430 | global $upgradeurl, $upcontext, $command_line; |
| 407 | 431 | |
| 408 | 432 | // Command line users can't be redirected. |
| 409 | - if ($command_line) |
|
| 410 | - upgradeExit(true); |
|
| 433 | + if ($command_line) { |
|
| 434 | + upgradeExit(true); |
|
| 435 | + } |
|
| 411 | 436 | |
| 412 | 437 | // Are we providing the core info? |
| 413 | 438 | if ($addForm) |
@@ -433,12 +458,14 @@ discard block |
||
| 433 | 458 | define('SMF', 1); |
| 434 | 459 | |
| 435 | 460 | // Start the session. |
| 436 | - if (@ini_get('session.save_handler') == 'user') |
|
| 437 | - @ini_set('session.save_handler', 'files'); |
|
| 461 | + if (@ini_get('session.save_handler') == 'user') { |
|
| 462 | + @ini_set('session.save_handler', 'files'); |
|
| 463 | + } |
|
| 438 | 464 | @session_start(); |
| 439 | 465 | |
| 440 | - if (empty($smcFunc)) |
|
| 441 | - $smcFunc = array(); |
|
| 466 | + if (empty($smcFunc)) { |
|
| 467 | + $smcFunc = array(); |
|
| 468 | + } |
|
| 442 | 469 | |
| 443 | 470 | // We need this for authentication and some upgrade code |
| 444 | 471 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -465,24 +492,27 @@ discard block |
||
| 465 | 492 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
| 466 | 493 | |
| 467 | 494 | // Make the connection... |
| 468 | - if (empty($db_connection)) |
|
| 469 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
| 470 | - else |
|
| 471 | - // If we've returned here, ping/reconnect to be safe |
|
| 495 | + if (empty($db_connection)) { |
|
| 496 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true)); |
|
| 497 | + } else { |
|
| 498 | + // If we've returned here, ping/reconnect to be safe |
|
| 472 | 499 | $smcFunc['db_ping']($db_connection); |
| 500 | + } |
|
| 473 | 501 | |
| 474 | 502 | // Oh dear god!! |
| 475 | - if ($db_connection === null) |
|
| 476 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 503 | + if ($db_connection === null) { |
|
| 504 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 505 | + } |
|
| 477 | 506 | |
| 478 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
| 479 | - $smcFunc['db_query']('', ' |
|
| 507 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
| 508 | + $smcFunc['db_query']('', ' |
|
| 480 | 509 | SET NAMES {string:db_character_set}', |
| 481 | 510 | array( |
| 482 | 511 | 'db_error_skip' => true, |
| 483 | 512 | 'db_character_set' => $db_character_set, |
| 484 | 513 | ) |
| 485 | 514 | ); |
| 515 | + } |
|
| 486 | 516 | |
| 487 | 517 | // Load the modSettings data... |
| 488 | 518 | $request = $smcFunc['db_query']('', ' |
@@ -493,11 +523,11 @@ discard block |
||
| 493 | 523 | ) |
| 494 | 524 | ); |
| 495 | 525 | $modSettings = array(); |
| 496 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 497 | - $modSettings[$row['variable']] = $row['value']; |
|
| 526 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 527 | + $modSettings[$row['variable']] = $row['value']; |
|
| 528 | + } |
|
| 498 | 529 | $smcFunc['db_free_result']($request); |
| 499 | - } |
|
| 500 | - else |
|
| 530 | + } else |
|
| 501 | 531 | { |
| 502 | 532 | return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.'); |
| 503 | 533 | } |
@@ -511,9 +541,10 @@ discard block |
||
| 511 | 541 | cleanRequest(); |
| 512 | 542 | } |
| 513 | 543 | |
| 514 | - if (!isset($_GET['substep'])) |
|
| 515 | - $_GET['substep'] = 0; |
|
| 516 | -} |
|
| 544 | + if (!isset($_GET['substep'])) { |
|
| 545 | + $_GET['substep'] = 0; |
|
| 546 | + } |
|
| 547 | + } |
|
| 517 | 548 | |
| 518 | 549 | function initialize_inputs() |
| 519 | 550 | { |
@@ -543,8 +574,9 @@ discard block |
||
| 543 | 574 | $dh = opendir(dirname(__FILE__)); |
| 544 | 575 | while ($file = readdir($dh)) |
| 545 | 576 | { |
| 546 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
| 547 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
| 577 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
| 578 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
| 579 | + } |
|
| 548 | 580 | } |
| 549 | 581 | closedir($dh); |
| 550 | 582 | |
@@ -573,8 +605,9 @@ discard block |
||
| 573 | 605 | $temp = 'upgrade_php?step'; |
| 574 | 606 | while (strlen($temp) > 4) |
| 575 | 607 | { |
| 576 | - if (isset($_GET[$temp])) |
|
| 577 | - unset($_GET[$temp]); |
|
| 608 | + if (isset($_GET[$temp])) { |
|
| 609 | + unset($_GET[$temp]); |
|
| 610 | + } |
|
| 578 | 611 | $temp = substr($temp, 1); |
| 579 | 612 | } |
| 580 | 613 | |
@@ -601,32 +634,39 @@ discard block |
||
| 601 | 634 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
| 602 | 635 | |
| 603 | 636 | // Need legacy scripts? |
| 604 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
| 605 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 606 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
| 607 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 608 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
| 609 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 637 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
| 638 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 639 | + } |
|
| 640 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
| 641 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 642 | + } |
|
| 643 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
| 644 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 645 | + } |
|
| 610 | 646 | |
| 611 | 647 | // We don't need "-utf8" files anymore... |
| 612 | 648 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
| 613 | 649 | |
| 614 | 650 | // This needs to exist! |
| 615 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 616 | - return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 617 | - else |
|
| 618 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 651 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 652 | + return throw_error('The upgrader could not find the "Install" language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 653 | + } else { |
|
| 654 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 655 | + } |
|
| 619 | 656 | |
| 620 | - if (!$check) |
|
| 621 | - // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
| 657 | + if (!$check) { |
|
| 658 | + // Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb. |
|
| 622 | 659 | return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.'); |
| 660 | + } |
|
| 623 | 661 | |
| 624 | 662 | // Do they meet the install requirements? |
| 625 | - if (!php_version_check()) |
|
| 626 | - return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
| 663 | + if (!php_version_check()) { |
|
| 664 | + return throw_error('Warning! You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.'); |
|
| 665 | + } |
|
| 627 | 666 | |
| 628 | - if (!db_version_check()) |
|
| 629 | - return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
| 667 | + if (!db_version_check()) { |
|
| 668 | + return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.'); |
|
| 669 | + } |
|
| 630 | 670 | |
| 631 | 671 | // Do some checks to make sure they have proper privileges |
| 632 | 672 | db_extend('packages'); |
@@ -641,14 +681,16 @@ discard block |
||
| 641 | 681 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 642 | 682 | |
| 643 | 683 | // Sorry... we need CREATE, ALTER and DROP |
| 644 | - if (!$create || !$alter || !$drop) |
|
| 645 | - return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
| 684 | + if (!$create || !$alter || !$drop) { |
|
| 685 | + return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.'); |
|
| 686 | + } |
|
| 646 | 687 | |
| 647 | 688 | // Do a quick version spot check. |
| 648 | 689 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 649 | 690 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 650 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 651 | - return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
| 691 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 692 | + return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.'); |
|
| 693 | + } |
|
| 652 | 694 | |
| 653 | 695 | // What absolutely needs to be writable? |
| 654 | 696 | $writable_files = array( |
@@ -670,12 +712,13 @@ discard block |
||
| 670 | 712 | quickFileWritable($custom_av_dir); |
| 671 | 713 | |
| 672 | 714 | // Are we good now? |
| 673 | - if (!is_writable($custom_av_dir)) |
|
| 674 | - return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
| 675 | - elseif ($need_settings_update) |
|
| 715 | + if (!is_writable($custom_av_dir)) { |
|
| 716 | + return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir)); |
|
| 717 | + } elseif ($need_settings_update) |
|
| 676 | 718 | { |
| 677 | - if (!function_exists('cache_put_data')) |
|
| 678 | - require_once($sourcedir . '/Load.php'); |
|
| 719 | + if (!function_exists('cache_put_data')) { |
|
| 720 | + require_once($sourcedir . '/Load.php'); |
|
| 721 | + } |
|
| 679 | 722 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
| 680 | 723 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
| 681 | 724 | } |
@@ -684,28 +727,33 @@ discard block |
||
| 684 | 727 | |
| 685 | 728 | // Check the cache directory. |
| 686 | 729 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 687 | - if (!file_exists($cachedir_temp)) |
|
| 688 | - @mkdir($cachedir_temp); |
|
| 689 | - if (!file_exists($cachedir_temp)) |
|
| 690 | - return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
| 691 | - |
|
| 692 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 693 | - return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
| 694 | - elseif (!isset($_GET['skiplang'])) |
|
| 730 | + if (!file_exists($cachedir_temp)) { |
|
| 731 | + @mkdir($cachedir_temp); |
|
| 732 | + } |
|
| 733 | + if (!file_exists($cachedir_temp)) { |
|
| 734 | + return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called "cache" in your forum directory before continuing.'); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 738 | + return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.'); |
|
| 739 | + } elseif (!isset($_GET['skiplang'])) |
|
| 695 | 740 | { |
| 696 | 741 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 697 | 742 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 698 | 743 | |
| 699 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 700 | - return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 744 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 745 | + return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br> [<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]'); |
|
| 746 | + } |
|
| 701 | 747 | } |
| 702 | 748 | |
| 703 | - if (!makeFilesWritable($writable_files)) |
|
| 704 | - return false; |
|
| 749 | + if (!makeFilesWritable($writable_files)) { |
|
| 750 | + return false; |
|
| 751 | + } |
|
| 705 | 752 | |
| 706 | 753 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
| 707 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 708 | - return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
| 754 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 755 | + return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.'); |
|
| 756 | + } |
|
| 709 | 757 | |
| 710 | 758 | // Upgrade the agreement. |
| 711 | 759 | elseif (isset($modSettings['agreement'])) |
@@ -716,8 +764,8 @@ discard block |
||
| 716 | 764 | } |
| 717 | 765 | |
| 718 | 766 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
| 719 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
| 720 | - $upcontext['warning'] = ' |
|
| 767 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
| 768 | + $upcontext['warning'] = ' |
|
| 721 | 769 | It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to "' . $boarddir . '" but should probably be "' . dirname(__FILE__) . '". Settings.php currently lists your paths as:<br> |
| 722 | 770 | <ul> |
| 723 | 771 | <li>Board Directory: ' . $boarddir . '</li> |
@@ -725,19 +773,23 @@ discard block |
||
| 725 | 773 | <li>Cache Directory: ' . $cachedir_temp . '</li> |
| 726 | 774 | </ul> |
| 727 | 775 | If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.'; |
| 776 | + } |
|
| 728 | 777 | |
| 729 | 778 | // Confirm mbstring is loaded... |
| 730 | - if (!extension_loaded('mbstring')) |
|
| 731 | - return throw_error($txt['install_no_mbstring']); |
|
| 779 | + if (!extension_loaded('mbstring')) { |
|
| 780 | + return throw_error($txt['install_no_mbstring']); |
|
| 781 | + } |
|
| 732 | 782 | |
| 733 | 783 | // Check for https stream support. |
| 734 | 784 | $supported_streams = stream_get_wrappers(); |
| 735 | - if (!in_array('https', $supported_streams)) |
|
| 736 | - $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 785 | + if (!in_array('https', $supported_streams)) { |
|
| 786 | + $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 787 | + } |
|
| 737 | 788 | |
| 738 | 789 | // Either we're logged in or we're going to present the login. |
| 739 | - if (checkLogin()) |
|
| 740 | - return true; |
|
| 790 | + if (checkLogin()) { |
|
| 791 | + return true; |
|
| 792 | + } |
|
| 741 | 793 | |
| 742 | 794 | $upcontext += createToken('login'); |
| 743 | 795 | |
@@ -751,15 +803,17 @@ discard block |
||
| 751 | 803 | global $smcFunc, $db_type, $support_js; |
| 752 | 804 | |
| 753 | 805 | // Don't bother if the security is disabled. |
| 754 | - if ($disable_security) |
|
| 755 | - return true; |
|
| 806 | + if ($disable_security) { |
|
| 807 | + return true; |
|
| 808 | + } |
|
| 756 | 809 | |
| 757 | 810 | // Are we trying to login? |
| 758 | 811 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
| 759 | 812 | { |
| 760 | 813 | // If we've disabled security pick a suitable name! |
| 761 | - if (empty($_POST['user'])) |
|
| 762 | - $_POST['user'] = 'Administrator'; |
|
| 814 | + if (empty($_POST['user'])) { |
|
| 815 | + $_POST['user'] = 'Administrator'; |
|
| 816 | + } |
|
| 763 | 817 | |
| 764 | 818 | // Before 2.0 these column names were different! |
| 765 | 819 | $oldDB = false; |
@@ -774,16 +828,17 @@ discard block |
||
| 774 | 828 | 'db_error_skip' => true, |
| 775 | 829 | ) |
| 776 | 830 | ); |
| 777 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 778 | - $oldDB = true; |
|
| 831 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 832 | + $oldDB = true; |
|
| 833 | + } |
|
| 779 | 834 | $smcFunc['db_free_result']($request); |
| 780 | 835 | } |
| 781 | 836 | |
| 782 | 837 | // Get what we believe to be their details. |
| 783 | 838 | if (!$disable_security) |
| 784 | 839 | { |
| 785 | - if ($oldDB) |
|
| 786 | - $request = $smcFunc['db_query']('', ' |
|
| 840 | + if ($oldDB) { |
|
| 841 | + $request = $smcFunc['db_query']('', ' |
|
| 787 | 842 | SELECT id_member, memberName AS member_name, passwd, id_group, |
| 788 | 843 | additionalGroups AS additional_groups, lngfile |
| 789 | 844 | FROM {db_prefix}members |
@@ -793,8 +848,8 @@ discard block |
||
| 793 | 848 | 'db_error_skip' => true, |
| 794 | 849 | ) |
| 795 | 850 | ); |
| 796 | - else |
|
| 797 | - $request = $smcFunc['db_query']('', ' |
|
| 851 | + } else { |
|
| 852 | + $request = $smcFunc['db_query']('', ' |
|
| 798 | 853 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
| 799 | 854 | FROM {db_prefix}members |
| 800 | 855 | WHERE member_name = {string:member_name}', |
@@ -803,6 +858,7 @@ discard block |
||
| 803 | 858 | 'db_error_skip' => true, |
| 804 | 859 | ) |
| 805 | 860 | ); |
| 861 | + } |
|
| 806 | 862 | if ($smcFunc['db_num_rows']($request) != 0) |
| 807 | 863 | { |
| 808 | 864 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -810,16 +866,17 @@ discard block |
||
| 810 | 866 | $groups = explode(',', $addGroups); |
| 811 | 867 | $groups[] = $id_group; |
| 812 | 868 | |
| 813 | - foreach ($groups as $k => $v) |
|
| 814 | - $groups[$k] = (int) $v; |
|
| 869 | + foreach ($groups as $k => $v) { |
|
| 870 | + $groups[$k] = (int) $v; |
|
| 871 | + } |
|
| 815 | 872 | |
| 816 | 873 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
| 817 | 874 | |
| 818 | 875 | // We don't use "-utf8" anymore... |
| 819 | 876 | $user_language = str_ireplace('-utf8', '', $user_language); |
| 877 | + } else { |
|
| 878 | + $upcontext['username_incorrect'] = true; |
|
| 820 | 879 | } |
| 821 | - else |
|
| 822 | - $upcontext['username_incorrect'] = true; |
|
| 823 | 880 | $smcFunc['db_free_result']($request); |
| 824 | 881 | } |
| 825 | 882 | $upcontext['username'] = $_POST['user']; |
@@ -829,13 +886,14 @@ discard block |
||
| 829 | 886 | { |
| 830 | 887 | $upcontext['upgrade_status']['js'] = 1; |
| 831 | 888 | $support_js = 1; |
| 889 | + } else { |
|
| 890 | + $support_js = 0; |
|
| 832 | 891 | } |
| 833 | - else |
|
| 834 | - $support_js = 0; |
|
| 835 | 892 | |
| 836 | 893 | // Note down the version we are coming from. |
| 837 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
| 838 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 894 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
| 895 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 896 | + } |
|
| 839 | 897 | |
| 840 | 898 | // Didn't get anywhere? |
| 841 | 899 | if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect'])) |
@@ -869,15 +927,15 @@ discard block |
||
| 869 | 927 | 'db_error_skip' => true, |
| 870 | 928 | ) |
| 871 | 929 | ); |
| 872 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 873 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 930 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 931 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 932 | + } |
|
| 874 | 933 | $smcFunc['db_free_result']($request); |
| 875 | 934 | } |
| 876 | 935 | |
| 877 | 936 | $upcontext['user']['id'] = $id_member; |
| 878 | 937 | $upcontext['user']['name'] = $name; |
| 879 | - } |
|
| 880 | - else |
|
| 938 | + } else |
|
| 881 | 939 | { |
| 882 | 940 | $upcontext['user']['id'] = 1; |
| 883 | 941 | $upcontext['user']['name'] = 'Administrator'; |
@@ -893,11 +951,11 @@ discard block |
||
| 893 | 951 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
| 894 | 952 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 895 | 953 | |
| 896 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 897 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 898 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
| 899 | - $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 900 | - else |
|
| 954 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 955 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 956 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
| 957 | + $upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the "Install" language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.'; |
|
| 958 | + } else |
|
| 901 | 959 | { |
| 902 | 960 | // Set this as the new language. |
| 903 | 961 | $upcontext['language'] = $user_language; |
@@ -941,8 +999,9 @@ discard block |
||
| 941 | 999 | unset($member_columns); |
| 942 | 1000 | |
| 943 | 1001 | // If we've not submitted then we're done. |
| 944 | - if (empty($_POST['upcont'])) |
|
| 945 | - return false; |
|
| 1002 | + if (empty($_POST['upcont'])) { |
|
| 1003 | + return false; |
|
| 1004 | + } |
|
| 946 | 1005 | |
| 947 | 1006 | // Firstly, if they're enabling SM stat collection just do it. |
| 948 | 1007 | if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) |
@@ -962,16 +1021,17 @@ discard block |
||
| 962 | 1021 | fwrite($fp, $out); |
| 963 | 1022 | |
| 964 | 1023 | $return_data = ''; |
| 965 | - while (!feof($fp)) |
|
| 966 | - $return_data .= fgets($fp, 128); |
|
| 1024 | + while (!feof($fp)) { |
|
| 1025 | + $return_data .= fgets($fp, 128); |
|
| 1026 | + } |
|
| 967 | 1027 | |
| 968 | 1028 | fclose($fp); |
| 969 | 1029 | |
| 970 | 1030 | // Get the unique site ID. |
| 971 | 1031 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 972 | 1032 | |
| 973 | - if (!empty($ID[1])) |
|
| 974 | - $smcFunc['db_insert']('replace', |
|
| 1033 | + if (!empty($ID[1])) { |
|
| 1034 | + $smcFunc['db_insert']('replace', |
|
| 975 | 1035 | $db_prefix . 'settings', |
| 976 | 1036 | array('variable' => 'string', 'value' => 'string'), |
| 977 | 1037 | array( |
@@ -980,9 +1040,9 @@ discard block |
||
| 980 | 1040 | ), |
| 981 | 1041 | array('variable') |
| 982 | 1042 | ); |
| 1043 | + } |
|
| 983 | 1044 | } |
| 984 | - } |
|
| 985 | - else |
|
| 1045 | + } else |
|
| 986 | 1046 | { |
| 987 | 1047 | $smcFunc['db_insert']('replace', |
| 988 | 1048 | $db_prefix . 'settings', |
@@ -993,8 +1053,8 @@ discard block |
||
| 993 | 1053 | } |
| 994 | 1054 | } |
| 995 | 1055 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 996 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 997 | - $smcFunc['db_query']('', ' |
|
| 1056 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1057 | + $smcFunc['db_query']('', ' |
|
| 998 | 1058 | DELETE FROM {db_prefix}settings |
| 999 | 1059 | WHERE variable = {string:enable_sm_stats}', |
| 1000 | 1060 | array( |
@@ -1002,6 +1062,7 @@ discard block |
||
| 1002 | 1062 | 'db_error_skip' => true, |
| 1003 | 1063 | ) |
| 1004 | 1064 | ); |
| 1065 | + } |
|
| 1005 | 1066 | |
| 1006 | 1067 | // Deleting old karma stuff? |
| 1007 | 1068 | if (!empty($_POST['delete_karma'])) |
@@ -1016,20 +1077,22 @@ discard block |
||
| 1016 | 1077 | ); |
| 1017 | 1078 | |
| 1018 | 1079 | // Cleaning up old karma member settings. |
| 1019 | - if ($upcontext['karma_installed']['good']) |
|
| 1020 | - $smcFunc['db_query']('', ' |
|
| 1080 | + if ($upcontext['karma_installed']['good']) { |
|
| 1081 | + $smcFunc['db_query']('', ' |
|
| 1021 | 1082 | ALTER TABLE {db_prefix}members |
| 1022 | 1083 | DROP karma_good', |
| 1023 | 1084 | array() |
| 1024 | 1085 | ); |
| 1086 | + } |
|
| 1025 | 1087 | |
| 1026 | 1088 | // Does karma bad was enable? |
| 1027 | - if ($upcontext['karma_installed']['bad']) |
|
| 1028 | - $smcFunc['db_query']('', ' |
|
| 1089 | + if ($upcontext['karma_installed']['bad']) { |
|
| 1090 | + $smcFunc['db_query']('', ' |
|
| 1029 | 1091 | ALTER TABLE {db_prefix}members |
| 1030 | 1092 | DROP karma_bad', |
| 1031 | 1093 | array() |
| 1032 | 1094 | ); |
| 1095 | + } |
|
| 1033 | 1096 | |
| 1034 | 1097 | // Cleaning up old karma permissions. |
| 1035 | 1098 | $smcFunc['db_query']('', ' |
@@ -1042,26 +1105,29 @@ discard block |
||
| 1042 | 1105 | } |
| 1043 | 1106 | |
| 1044 | 1107 | // Emptying the error log? |
| 1045 | - if (!empty($_POST['empty_error'])) |
|
| 1046 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1108 | + if (!empty($_POST['empty_error'])) { |
|
| 1109 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1047 | 1110 | TRUNCATE {db_prefix}log_errors', |
| 1048 | 1111 | array( |
| 1049 | 1112 | ) |
| 1050 | 1113 | ); |
| 1114 | + } |
|
| 1051 | 1115 | |
| 1052 | 1116 | $changes = array(); |
| 1053 | 1117 | |
| 1054 | 1118 | // Add proxy settings. |
| 1055 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
| 1056 | - $changes += array( |
|
| 1119 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
| 1120 | + $changes += array( |
|
| 1057 | 1121 | 'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'', |
| 1058 | 1122 | 'image_proxy_maxsize' => 5190, |
| 1059 | 1123 | 'image_proxy_enabled' => 0, |
| 1060 | 1124 | ); |
| 1125 | + } |
|
| 1061 | 1126 | |
| 1062 | 1127 | // If we're overriding the language follow it through. |
| 1063 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
| 1064 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1128 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
| 1129 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1130 | + } |
|
| 1065 | 1131 | |
| 1066 | 1132 | if (!empty($_POST['maint'])) |
| 1067 | 1133 | { |
@@ -1073,26 +1139,29 @@ discard block |
||
| 1073 | 1139 | { |
| 1074 | 1140 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
| 1075 | 1141 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
| 1076 | - } |
|
| 1077 | - else |
|
| 1142 | + } else |
|
| 1078 | 1143 | { |
| 1079 | 1144 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
| 1080 | 1145 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
| 1081 | 1146 | } |
| 1082 | 1147 | } |
| 1083 | 1148 | |
| 1084 | - if ($command_line) |
|
| 1085 | - echo ' * Updating Settings.php...'; |
|
| 1149 | + if ($command_line) { |
|
| 1150 | + echo ' * Updating Settings.php...'; |
|
| 1151 | + } |
|
| 1086 | 1152 | |
| 1087 | 1153 | // Fix some old paths. |
| 1088 | - if (substr($boarddir, 0, 1) == '.') |
|
| 1089 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1154 | + if (substr($boarddir, 0, 1) == '.') { |
|
| 1155 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1156 | + } |
|
| 1090 | 1157 | |
| 1091 | - if (substr($sourcedir, 0, 1) == '.') |
|
| 1092 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1158 | + if (substr($sourcedir, 0, 1) == '.') { |
|
| 1159 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1160 | + } |
|
| 1093 | 1161 | |
| 1094 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
| 1095 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1162 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
| 1163 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1164 | + } |
|
| 1096 | 1165 | |
| 1097 | 1166 | // If they have a "host:port" setup for the host, split that into separate values |
| 1098 | 1167 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1103,32 +1172,36 @@ discard block |
||
| 1103 | 1172 | $changes['db_server'] = '\'' . $db_server . '\''; |
| 1104 | 1173 | |
| 1105 | 1174 | // Only set this if we're not using the default port |
| 1106 | - if ($db_port != ini_get('mysqli.default_port')) |
|
| 1107 | - $changes['db_port'] = (int) $db_port; |
|
| 1108 | - } |
|
| 1109 | - elseif (!empty($db_port)) |
|
| 1175 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
| 1176 | + $changes['db_port'] = (int) $db_port; |
|
| 1177 | + } |
|
| 1178 | + } elseif (!empty($db_port)) |
|
| 1110 | 1179 | { |
| 1111 | 1180 | // If db_port is set and is the same as the default, set it to '' |
| 1112 | 1181 | if ($db_type == 'mysql') |
| 1113 | 1182 | { |
| 1114 | - if ($db_port == ini_get('mysqli.default_port')) |
|
| 1115 | - $changes['db_port'] = '\'\''; |
|
| 1116 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
| 1117 | - $changes['db_port'] = '\'\''; |
|
| 1183 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
| 1184 | + $changes['db_port'] = '\'\''; |
|
| 1185 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
| 1186 | + $changes['db_port'] = '\'\''; |
|
| 1187 | + } |
|
| 1118 | 1188 | } |
| 1119 | 1189 | } |
| 1120 | 1190 | |
| 1121 | 1191 | // Maybe we haven't had this option yet? |
| 1122 | - if (empty($packagesdir)) |
|
| 1123 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1192 | + if (empty($packagesdir)) { |
|
| 1193 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1194 | + } |
|
| 1124 | 1195 | |
| 1125 | 1196 | // Add support for $tasksdir var. |
| 1126 | - if (empty($tasksdir)) |
|
| 1127 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1197 | + if (empty($tasksdir)) { |
|
| 1198 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1199 | + } |
|
| 1128 | 1200 | |
| 1129 | 1201 | // Make sure we fix the language as well. |
| 1130 | - if (stristr($language, '-utf8')) |
|
| 1131 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1202 | + if (stristr($language, '-utf8')) { |
|
| 1203 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1204 | + } |
|
| 1132 | 1205 | |
| 1133 | 1206 | // @todo Maybe change the cookie name if going to 1.1, too? |
| 1134 | 1207 | |
@@ -1136,8 +1209,9 @@ discard block |
||
| 1136 | 1209 | require_once($sourcedir . '/Subs-Admin.php'); |
| 1137 | 1210 | updateSettingsFile($changes); |
| 1138 | 1211 | |
| 1139 | - if ($command_line) |
|
| 1140 | - echo ' Successful.' . "\n"; |
|
| 1212 | + if ($command_line) { |
|
| 1213 | + echo ' Successful.' . "\n"; |
|
| 1214 | + } |
|
| 1141 | 1215 | |
| 1142 | 1216 | // Are we doing debug? |
| 1143 | 1217 | if (isset($_POST['debug'])) |
@@ -1147,8 +1221,9 @@ discard block |
||
| 1147 | 1221 | } |
| 1148 | 1222 | |
| 1149 | 1223 | // If we're not backing up then jump one. |
| 1150 | - if (empty($_POST['backup'])) |
|
| 1151 | - $upcontext['current_step']++; |
|
| 1224 | + if (empty($_POST['backup'])) { |
|
| 1225 | + $upcontext['current_step']++; |
|
| 1226 | + } |
|
| 1152 | 1227 | |
| 1153 | 1228 | // If we've got here then let's proceed to the next step! |
| 1154 | 1229 | return true; |
@@ -1163,8 +1238,9 @@ discard block |
||
| 1163 | 1238 | $upcontext['page_title'] = 'Backup Database'; |
| 1164 | 1239 | |
| 1165 | 1240 | // Done it already - js wise? |
| 1166 | - if (!empty($_POST['backup_done'])) |
|
| 1167 | - return true; |
|
| 1241 | + if (!empty($_POST['backup_done'])) { |
|
| 1242 | + return true; |
|
| 1243 | + } |
|
| 1168 | 1244 | |
| 1169 | 1245 | // Some useful stuff here. |
| 1170 | 1246 | db_extend(); |
@@ -1178,9 +1254,10 @@ discard block |
||
| 1178 | 1254 | $tables = $smcFunc['db_list_tables']($db, $filter); |
| 1179 | 1255 | |
| 1180 | 1256 | $table_names = array(); |
| 1181 | - foreach ($tables as $table) |
|
| 1182 | - if (substr($table, 0, 7) !== 'backup_') |
|
| 1257 | + foreach ($tables as $table) { |
|
| 1258 | + if (substr($table, 0, 7) !== 'backup_') |
|
| 1183 | 1259 | $table_names[] = $table; |
| 1260 | + } |
|
| 1184 | 1261 | |
| 1185 | 1262 | $upcontext['table_count'] = count($table_names); |
| 1186 | 1263 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1190,12 +1267,14 @@ discard block |
||
| 1190 | 1267 | $file_steps = $upcontext['table_count']; |
| 1191 | 1268 | |
| 1192 | 1269 | // What ones have we already done? |
| 1193 | - foreach ($table_names as $id => $table) |
|
| 1194 | - if ($id < $_GET['substep']) |
|
| 1270 | + foreach ($table_names as $id => $table) { |
|
| 1271 | + if ($id < $_GET['substep']) |
|
| 1195 | 1272 | $upcontext['previous_tables'][] = $table; |
| 1273 | + } |
|
| 1196 | 1274 | |
| 1197 | - if ($command_line) |
|
| 1198 | - echo 'Backing Up Tables.'; |
|
| 1275 | + if ($command_line) { |
|
| 1276 | + echo 'Backing Up Tables.'; |
|
| 1277 | + } |
|
| 1199 | 1278 | |
| 1200 | 1279 | // If we don't support javascript we backup here. |
| 1201 | 1280 | if (!$support_js || isset($_GET['xml'])) |
@@ -1214,8 +1293,9 @@ discard block |
||
| 1214 | 1293 | backupTable($table_names[$substep]); |
| 1215 | 1294 | |
| 1216 | 1295 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 1217 | - if (isset($_GET['xml'])) |
|
| 1218 | - return upgradeExit(); |
|
| 1296 | + if (isset($_GET['xml'])) { |
|
| 1297 | + return upgradeExit(); |
|
| 1298 | + } |
|
| 1219 | 1299 | } |
| 1220 | 1300 | |
| 1221 | 1301 | if ($command_line) |
@@ -1248,9 +1328,10 @@ discard block |
||
| 1248 | 1328 | |
| 1249 | 1329 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
| 1250 | 1330 | |
| 1251 | - if ($command_line) |
|
| 1252 | - echo ' done.'; |
|
| 1253 | -} |
|
| 1331 | + if ($command_line) { |
|
| 1332 | + echo ' done.'; |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1254 | 1335 | |
| 1255 | 1336 | // Step 2: Everything. |
| 1256 | 1337 | function DatabaseChanges() |
@@ -1259,8 +1340,9 @@ discard block |
||
| 1259 | 1340 | global $upcontext, $support_js, $db_type; |
| 1260 | 1341 | |
| 1261 | 1342 | // Have we just completed this? |
| 1262 | - if (!empty($_POST['database_done'])) |
|
| 1263 | - return true; |
|
| 1343 | + if (!empty($_POST['database_done'])) { |
|
| 1344 | + return true; |
|
| 1345 | + } |
|
| 1264 | 1346 | |
| 1265 | 1347 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
| 1266 | 1348 | $upcontext['page_title'] = 'Database Changes'; |
@@ -1275,15 +1357,16 @@ discard block |
||
| 1275 | 1357 | ); |
| 1276 | 1358 | |
| 1277 | 1359 | // How many files are there in total? |
| 1278 | - if (isset($_GET['filecount'])) |
|
| 1279 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1280 | - else |
|
| 1360 | + if (isset($_GET['filecount'])) { |
|
| 1361 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1362 | + } else |
|
| 1281 | 1363 | { |
| 1282 | 1364 | $upcontext['file_count'] = 0; |
| 1283 | 1365 | foreach ($files as $file) |
| 1284 | 1366 | { |
| 1285 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
| 1286 | - $upcontext['file_count']++; |
|
| 1367 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
| 1368 | + $upcontext['file_count']++; |
|
| 1369 | + } |
|
| 1287 | 1370 | } |
| 1288 | 1371 | } |
| 1289 | 1372 | |
@@ -1293,9 +1376,9 @@ discard block |
||
| 1293 | 1376 | $upcontext['cur_file_num'] = 0; |
| 1294 | 1377 | foreach ($files as $file) |
| 1295 | 1378 | { |
| 1296 | - if ($did_not_do) |
|
| 1297 | - $did_not_do--; |
|
| 1298 | - else |
|
| 1379 | + if ($did_not_do) { |
|
| 1380 | + $did_not_do--; |
|
| 1381 | + } else |
|
| 1299 | 1382 | { |
| 1300 | 1383 | $upcontext['cur_file_num']++; |
| 1301 | 1384 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1322,12 +1405,13 @@ discard block |
||
| 1322 | 1405 | // Flag to move on to the next. |
| 1323 | 1406 | $upcontext['completed_step'] = true; |
| 1324 | 1407 | // Did we complete the whole file? |
| 1325 | - if ($nextFile) |
|
| 1326 | - $upcontext['current_debug_item_num'] = -1; |
|
| 1408 | + if ($nextFile) { |
|
| 1409 | + $upcontext['current_debug_item_num'] = -1; |
|
| 1410 | + } |
|
| 1327 | 1411 | return upgradeExit(); |
| 1412 | + } elseif ($support_js) { |
|
| 1413 | + break; |
|
| 1328 | 1414 | } |
| 1329 | - elseif ($support_js) |
|
| 1330 | - break; |
|
| 1331 | 1415 | } |
| 1332 | 1416 | // Set the progress bar to be right as if we had - even if we hadn't... |
| 1333 | 1417 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1352,8 +1436,9 @@ discard block |
||
| 1352 | 1436 | global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type; |
| 1353 | 1437 | |
| 1354 | 1438 | // Now it's nice to have some of the basic SMF source files. |
| 1355 | - if (!isset($_GET['ssi']) && !$command_line) |
|
| 1356 | - redirectLocation('&ssi=1'); |
|
| 1439 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
| 1440 | + redirectLocation('&ssi=1'); |
|
| 1441 | + } |
|
| 1357 | 1442 | |
| 1358 | 1443 | $upcontext['sub_template'] = 'upgrade_complete'; |
| 1359 | 1444 | $upcontext['page_title'] = 'Upgrade Complete'; |
@@ -1369,14 +1454,16 @@ discard block |
||
| 1369 | 1454 | // Are we in maintenance mode? |
| 1370 | 1455 | if (isset($upcontext['user']['main'])) |
| 1371 | 1456 | { |
| 1372 | - if ($command_line) |
|
| 1373 | - echo ' * '; |
|
| 1457 | + if ($command_line) { |
|
| 1458 | + echo ' * '; |
|
| 1459 | + } |
|
| 1374 | 1460 | $upcontext['removed_maintenance'] = true; |
| 1375 | 1461 | $changes['maintenance'] = $upcontext['user']['main']; |
| 1376 | 1462 | } |
| 1377 | 1463 | // Otherwise if somehow we are in 2 let's go to 1. |
| 1378 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
| 1379 | - $changes['maintenance'] = 1; |
|
| 1464 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
| 1465 | + $changes['maintenance'] = 1; |
|
| 1466 | + } |
|
| 1380 | 1467 | |
| 1381 | 1468 | // Wipe this out... |
| 1382 | 1469 | $upcontext['user'] = array(); |
@@ -1391,9 +1478,9 @@ discard block |
||
| 1391 | 1478 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
| 1392 | 1479 | |
| 1393 | 1480 | // Now is the perfect time to fetch the SM files. |
| 1394 | - if ($command_line) |
|
| 1395 | - cli_scheduled_fetchSMfiles(); |
|
| 1396 | - else |
|
| 1481 | + if ($command_line) { |
|
| 1482 | + cli_scheduled_fetchSMfiles(); |
|
| 1483 | + } else |
|
| 1397 | 1484 | { |
| 1398 | 1485 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 1399 | 1486 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
@@ -1401,8 +1488,9 @@ discard block |
||
| 1401 | 1488 | } |
| 1402 | 1489 | |
| 1403 | 1490 | // Log what we've done. |
| 1404 | - if (empty($user_info['id'])) |
|
| 1405 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1491 | + if (empty($user_info['id'])) { |
|
| 1492 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1493 | + } |
|
| 1406 | 1494 | |
| 1407 | 1495 | // Log the action manually, so CLI still works. |
| 1408 | 1496 | $smcFunc['db_insert']('', |
@@ -1421,8 +1509,9 @@ discard block |
||
| 1421 | 1509 | |
| 1422 | 1510 | // Save the current database version. |
| 1423 | 1511 | $server_version = $smcFunc['db_server_info'](); |
| 1424 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1425 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1512 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1513 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1514 | + } |
|
| 1426 | 1515 | |
| 1427 | 1516 | if ($command_line) |
| 1428 | 1517 | { |
@@ -1434,8 +1523,9 @@ discard block |
||
| 1434 | 1523 | |
| 1435 | 1524 | // Make sure it says we're done. |
| 1436 | 1525 | $upcontext['overall_percent'] = 100; |
| 1437 | - if (isset($upcontext['step_progress'])) |
|
| 1438 | - unset($upcontext['step_progress']); |
|
| 1526 | + if (isset($upcontext['step_progress'])) { |
|
| 1527 | + unset($upcontext['step_progress']); |
|
| 1528 | + } |
|
| 1439 | 1529 | |
| 1440 | 1530 | $_GET['substep'] = 0; |
| 1441 | 1531 | return false; |
@@ -1446,8 +1536,9 @@ discard block |
||
| 1446 | 1536 | { |
| 1447 | 1537 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
| 1448 | 1538 | |
| 1449 | - if (empty($modSettings['time_format'])) |
|
| 1450 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1539 | + if (empty($modSettings['time_format'])) { |
|
| 1540 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1541 | + } |
|
| 1451 | 1542 | |
| 1452 | 1543 | // What files do we want to get |
| 1453 | 1544 | $request = $smcFunc['db_query']('', ' |
@@ -1481,8 +1572,9 @@ discard block |
||
| 1481 | 1572 | $file_data = fetch_web_data($url); |
| 1482 | 1573 | |
| 1483 | 1574 | // If we got an error - give up - the site might be down. |
| 1484 | - if ($file_data === false) |
|
| 1485 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1575 | + if ($file_data === false) { |
|
| 1576 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1577 | + } |
|
| 1486 | 1578 | |
| 1487 | 1579 | // Save the file to the database. |
| 1488 | 1580 | $smcFunc['db_query']('substring', ' |
@@ -1524,8 +1616,9 @@ discard block |
||
| 1524 | 1616 | $themeData = array(); |
| 1525 | 1617 | foreach ($values as $variable => $value) |
| 1526 | 1618 | { |
| 1527 | - if (!isset($value) || $value === null) |
|
| 1528 | - $value = 0; |
|
| 1619 | + if (!isset($value) || $value === null) { |
|
| 1620 | + $value = 0; |
|
| 1621 | + } |
|
| 1529 | 1622 | |
| 1530 | 1623 | $themeData[] = array(0, 1, $variable, $value); |
| 1531 | 1624 | } |
@@ -1554,8 +1647,9 @@ discard block |
||
| 1554 | 1647 | |
| 1555 | 1648 | foreach ($values as $variable => $value) |
| 1556 | 1649 | { |
| 1557 | - if (empty($modSettings[$value[0]])) |
|
| 1558 | - continue; |
|
| 1650 | + if (empty($modSettings[$value[0]])) { |
|
| 1651 | + continue; |
|
| 1652 | + } |
|
| 1559 | 1653 | |
| 1560 | 1654 | $smcFunc['db_query']('', ' |
| 1561 | 1655 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1641,19 +1735,21 @@ discard block |
||
| 1641 | 1735 | set_error_handler( |
| 1642 | 1736 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
| 1643 | 1737 | { |
| 1644 | - if ($support_js) |
|
| 1645 | - return true; |
|
| 1646 | - else |
|
| 1647 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1738 | + if ($support_js) { |
|
| 1739 | + return true; |
|
| 1740 | + } else { |
|
| 1741 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1742 | + } |
|
| 1648 | 1743 | } |
| 1649 | 1744 | ); |
| 1650 | 1745 | |
| 1651 | 1746 | // If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8 |
| 1652 | 1747 | // Note it is expected to be in the format: ENGINE=MyISAM{$db_collation}; |
| 1653 | - if ($db_type == 'mysql') |
|
| 1654 | - $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1655 | - else |
|
| 1656 | - $db_collation = ''; |
|
| 1748 | + if ($db_type == 'mysql') { |
|
| 1749 | + $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1750 | + } else { |
|
| 1751 | + $db_collation = ''; |
|
| 1752 | + } |
|
| 1657 | 1753 | |
| 1658 | 1754 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
| 1659 | 1755 | |
@@ -1665,8 +1761,9 @@ discard block |
||
| 1665 | 1761 | $last_step = ''; |
| 1666 | 1762 | |
| 1667 | 1763 | // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php |
| 1668 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
| 1669 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1764 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
| 1765 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1766 | + } |
|
| 1670 | 1767 | |
| 1671 | 1768 | // Count the total number of steps within this file - for progress. |
| 1672 | 1769 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1686,15 +1783,18 @@ discard block |
||
| 1686 | 1783 | $do_current = $substep >= $_GET['substep']; |
| 1687 | 1784 | |
| 1688 | 1785 | // Get rid of any comments in the beginning of the line... |
| 1689 | - if (substr(trim($line), 0, 2) === '/*') |
|
| 1690 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1786 | + if (substr(trim($line), 0, 2) === '/*') { |
|
| 1787 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1788 | + } |
|
| 1691 | 1789 | |
| 1692 | 1790 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
| 1693 | - if ($is_debug && !$support_js && $command_line) |
|
| 1694 | - flush(); |
|
| 1791 | + if ($is_debug && !$support_js && $command_line) { |
|
| 1792 | + flush(); |
|
| 1793 | + } |
|
| 1695 | 1794 | |
| 1696 | - if (trim($line) === '') |
|
| 1697 | - continue; |
|
| 1795 | + if (trim($line) === '') { |
|
| 1796 | + continue; |
|
| 1797 | + } |
|
| 1698 | 1798 | |
| 1699 | 1799 | if (trim(substr($line, 0, 3)) === '---') |
| 1700 | 1800 | { |
@@ -1704,8 +1804,9 @@ discard block |
||
| 1704 | 1804 | if (trim($current_data) != '' && $type !== '}') |
| 1705 | 1805 | { |
| 1706 | 1806 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
| 1707 | - if ($command_line) |
|
| 1708 | - echo $upcontext['error_message']; |
|
| 1807 | + if ($command_line) { |
|
| 1808 | + echo $upcontext['error_message']; |
|
| 1809 | + } |
|
| 1709 | 1810 | } |
| 1710 | 1811 | |
| 1711 | 1812 | if ($type == ' ') |
@@ -1723,17 +1824,18 @@ discard block |
||
| 1723 | 1824 | if ($do_current) |
| 1724 | 1825 | { |
| 1725 | 1826 | $upcontext['actioned_items'][] = $last_step; |
| 1726 | - if ($command_line) |
|
| 1727 | - echo ' * '; |
|
| 1827 | + if ($command_line) { |
|
| 1828 | + echo ' * '; |
|
| 1829 | + } |
|
| 1728 | 1830 | } |
| 1729 | - } |
|
| 1730 | - elseif ($type == '#') |
|
| 1831 | + } elseif ($type == '#') |
|
| 1731 | 1832 | { |
| 1732 | 1833 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
| 1733 | 1834 | |
| 1734 | 1835 | $upcontext['current_debug_item_num']++; |
| 1735 | - if (trim($line) != '---#') |
|
| 1736 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1836 | + if (trim($line) != '---#') { |
|
| 1837 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1838 | + } |
|
| 1737 | 1839 | |
| 1738 | 1840 | // Have we already done something? |
| 1739 | 1841 | if (isset($_GET['xml']) && $done_something) |
@@ -1744,34 +1846,36 @@ discard block |
||
| 1744 | 1846 | |
| 1745 | 1847 | if ($do_current) |
| 1746 | 1848 | { |
| 1747 | - if (trim($line) == '---#' && $command_line) |
|
| 1748 | - echo ' done.', $endl; |
|
| 1749 | - elseif ($command_line) |
|
| 1750 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1751 | - elseif (trim($line) != '---#') |
|
| 1849 | + if (trim($line) == '---#' && $command_line) { |
|
| 1850 | + echo ' done.', $endl; |
|
| 1851 | + } elseif ($command_line) { |
|
| 1852 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1853 | + } elseif (trim($line) != '---#') |
|
| 1752 | 1854 | { |
| 1753 | - if ($is_debug) |
|
| 1754 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1855 | + if ($is_debug) { |
|
| 1856 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1857 | + } |
|
| 1755 | 1858 | } |
| 1756 | 1859 | } |
| 1757 | 1860 | |
| 1758 | 1861 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
| 1759 | 1862 | { |
| 1760 | - if ($command_line) |
|
| 1761 | - echo ' * '; |
|
| 1762 | - else |
|
| 1763 | - $upcontext['actioned_items'][] = $last_step; |
|
| 1863 | + if ($command_line) { |
|
| 1864 | + echo ' * '; |
|
| 1865 | + } else { |
|
| 1866 | + $upcontext['actioned_items'][] = $last_step; |
|
| 1867 | + } |
|
| 1764 | 1868 | } |
| 1765 | 1869 | |
| 1766 | 1870 | // Small step - only if we're actually doing stuff. |
| 1767 | - if ($do_current) |
|
| 1768 | - nextSubstep(++$substep); |
|
| 1769 | - else |
|
| 1770 | - $substep++; |
|
| 1771 | - } |
|
| 1772 | - elseif ($type == '{') |
|
| 1773 | - $current_type = 'code'; |
|
| 1774 | - elseif ($type == '}') |
|
| 1871 | + if ($do_current) { |
|
| 1872 | + nextSubstep(++$substep); |
|
| 1873 | + } else { |
|
| 1874 | + $substep++; |
|
| 1875 | + } |
|
| 1876 | + } elseif ($type == '{') { |
|
| 1877 | + $current_type = 'code'; |
|
| 1878 | + } elseif ($type == '}') |
|
| 1775 | 1879 | { |
| 1776 | 1880 | $current_type = 'sql'; |
| 1777 | 1881 | |
@@ -1784,8 +1888,9 @@ discard block |
||
| 1784 | 1888 | if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false) |
| 1785 | 1889 | { |
| 1786 | 1890 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
| 1787 | - if ($command_line) |
|
| 1788 | - echo $upcontext['error_message']; |
|
| 1891 | + if ($command_line) { |
|
| 1892 | + echo $upcontext['error_message']; |
|
| 1893 | + } |
|
| 1789 | 1894 | } |
| 1790 | 1895 | |
| 1791 | 1896 | // Done with code! |
@@ -1865,8 +1970,9 @@ discard block |
||
| 1865 | 1970 | $db_unbuffered = false; |
| 1866 | 1971 | |
| 1867 | 1972 | // Failure?! |
| 1868 | - if ($result !== false) |
|
| 1869 | - return $result; |
|
| 1973 | + if ($result !== false) { |
|
| 1974 | + return $result; |
|
| 1975 | + } |
|
| 1870 | 1976 | |
| 1871 | 1977 | $db_error_message = $smcFunc['db_error']($db_connection); |
| 1872 | 1978 | // If MySQL we do something more clever. |
@@ -1894,54 +2000,61 @@ discard block |
||
| 1894 | 2000 | { |
| 1895 | 2001 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
| 1896 | 2002 | $result = mysqli_query($db_connection, $string); |
| 1897 | - if ($result !== false) |
|
| 1898 | - return $result; |
|
| 2003 | + if ($result !== false) { |
|
| 2004 | + return $result; |
|
| 2005 | + } |
|
| 1899 | 2006 | } |
| 1900 | - } |
|
| 1901 | - elseif ($mysqli_errno == 2013) |
|
| 2007 | + } elseif ($mysqli_errno == 2013) |
|
| 1902 | 2008 | { |
| 1903 | 2009 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
| 1904 | 2010 | mysqli_select_db($db_connection, $db_name); |
| 1905 | 2011 | if ($db_connection) |
| 1906 | 2012 | { |
| 1907 | 2013 | $result = mysqli_query($db_connection, $string); |
| 1908 | - if ($result !== false) |
|
| 1909 | - return $result; |
|
| 2014 | + if ($result !== false) { |
|
| 2015 | + return $result; |
|
| 2016 | + } |
|
| 1910 | 2017 | } |
| 1911 | 2018 | } |
| 1912 | 2019 | // Duplicate column name... should be okay ;). |
| 1913 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
| 1914 | - return false; |
|
| 2020 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
| 2021 | + return false; |
|
| 2022 | + } |
|
| 1915 | 2023 | // Duplicate insert... make sure it's the proper type of query ;). |
| 1916 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
| 1917 | - return false; |
|
| 2024 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
| 2025 | + return false; |
|
| 2026 | + } |
|
| 1918 | 2027 | // Creating an index on a non-existent column. |
| 1919 | - elseif ($mysqli_errno == 1072) |
|
| 1920 | - return false; |
|
| 1921 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
| 1922 | - return false; |
|
| 2028 | + elseif ($mysqli_errno == 1072) { |
|
| 2029 | + return false; |
|
| 2030 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
| 2031 | + return false; |
|
| 2032 | + } |
|
| 1923 | 2033 | } |
| 1924 | 2034 | // If a table already exists don't go potty. |
| 1925 | 2035 | else |
| 1926 | 2036 | { |
| 1927 | 2037 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
| 1928 | 2038 | { |
| 1929 | - if (strpos($db_error_message, 'exist') !== false) |
|
| 1930 | - return true; |
|
| 1931 | - } |
|
| 1932 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2039 | + if (strpos($db_error_message, 'exist') !== false) { |
|
| 2040 | + return true; |
|
| 2041 | + } |
|
| 2042 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 1933 | 2043 | { |
| 1934 | - if (strpos($db_error_message, 'duplicate') !== false) |
|
| 1935 | - return true; |
|
| 2044 | + if (strpos($db_error_message, 'duplicate') !== false) { |
|
| 2045 | + return true; |
|
| 2046 | + } |
|
| 1936 | 2047 | } |
| 1937 | 2048 | } |
| 1938 | 2049 | |
| 1939 | 2050 | // Get the query string so we pass everything. |
| 1940 | 2051 | $query_string = ''; |
| 1941 | - foreach ($_GET as $k => $v) |
|
| 1942 | - $query_string .= ';' . $k . '=' . $v; |
|
| 1943 | - if (strlen($query_string) != 0) |
|
| 1944 | - $query_string = '?' . substr($query_string, 1); |
|
| 2052 | + foreach ($_GET as $k => $v) { |
|
| 2053 | + $query_string .= ';' . $k . '=' . $v; |
|
| 2054 | + } |
|
| 2055 | + if (strlen($query_string) != 0) { |
|
| 2056 | + $query_string = '?' . substr($query_string, 1); |
|
| 2057 | + } |
|
| 1945 | 2058 | |
| 1946 | 2059 | if ($command_line) |
| 1947 | 2060 | { |
@@ -1996,16 +2109,18 @@ discard block |
||
| 1996 | 2109 | { |
| 1997 | 2110 | $found |= 1; |
| 1998 | 2111 | // Do some checks on the data if we have it set. |
| 1999 | - if (isset($change['col_type'])) |
|
| 2000 | - $found &= $change['col_type'] === $column['type']; |
|
| 2001 | - if (isset($change['null_allowed'])) |
|
| 2002 | - $found &= $column['null'] == $change['null_allowed']; |
|
| 2003 | - if (isset($change['default'])) |
|
| 2004 | - $found &= $change['default'] === $column['default']; |
|
| 2112 | + if (isset($change['col_type'])) { |
|
| 2113 | + $found &= $change['col_type'] === $column['type']; |
|
| 2114 | + } |
|
| 2115 | + if (isset($change['null_allowed'])) { |
|
| 2116 | + $found &= $column['null'] == $change['null_allowed']; |
|
| 2117 | + } |
|
| 2118 | + if (isset($change['default'])) { |
|
| 2119 | + $found &= $change['default'] === $column['default']; |
|
| 2120 | + } |
|
| 2005 | 2121 | } |
| 2006 | 2122 | } |
| 2007 | - } |
|
| 2008 | - elseif ($change['type'] === 'index') |
|
| 2123 | + } elseif ($change['type'] === 'index') |
|
| 2009 | 2124 | { |
| 2010 | 2125 | $request = upgrade_query(' |
| 2011 | 2126 | SHOW INDEX |
@@ -2014,9 +2129,10 @@ discard block |
||
| 2014 | 2129 | { |
| 2015 | 2130 | $cur_index = array(); |
| 2016 | 2131 | |
| 2017 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2018 | - if ($row['Key_name'] === $change['name']) |
|
| 2132 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2133 | + if ($row['Key_name'] === $change['name']) |
|
| 2019 | 2134 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
| 2135 | + } |
|
| 2020 | 2136 | |
| 2021 | 2137 | ksort($cur_index, SORT_NUMERIC); |
| 2022 | 2138 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2026,14 +2142,17 @@ discard block |
||
| 2026 | 2142 | } |
| 2027 | 2143 | |
| 2028 | 2144 | // If we're trying to add and it's added, we're done. |
| 2029 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
| 2030 | - return true; |
|
| 2145 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
| 2146 | + return true; |
|
| 2147 | + } |
|
| 2031 | 2148 | // Otherwise if we're removing and it wasn't found we're also done. |
| 2032 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
| 2033 | - return true; |
|
| 2149 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
| 2150 | + return true; |
|
| 2151 | + } |
|
| 2034 | 2152 | // Otherwise is it just a test? |
| 2035 | - elseif ($is_test) |
|
| 2036 | - return false; |
|
| 2153 | + elseif ($is_test) { |
|
| 2154 | + return false; |
|
| 2155 | + } |
|
| 2037 | 2156 | |
| 2038 | 2157 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
| 2039 | 2158 | $running = false; |
@@ -2044,8 +2163,9 @@ discard block |
||
| 2044 | 2163 | SHOW FULL PROCESSLIST'); |
| 2045 | 2164 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2046 | 2165 | { |
| 2047 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
| 2048 | - $found = true; |
|
| 2166 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
| 2167 | + $found = true; |
|
| 2168 | + } |
|
| 2049 | 2169 | } |
| 2050 | 2170 | |
| 2051 | 2171 | // Can't find it? Then we need to run it fools! |
@@ -2057,8 +2177,9 @@ discard block |
||
| 2057 | 2177 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
| 2058 | 2178 | ' . $change['text'], true) !== false; |
| 2059 | 2179 | |
| 2060 | - if (!$success) |
|
| 2061 | - return false; |
|
| 2180 | + if (!$success) { |
|
| 2181 | + return false; |
|
| 2182 | + } |
|
| 2062 | 2183 | |
| 2063 | 2184 | // Return |
| 2064 | 2185 | $running = true; |
@@ -2100,8 +2221,9 @@ discard block |
||
| 2100 | 2221 | 'db_error_skip' => true, |
| 2101 | 2222 | ) |
| 2102 | 2223 | ); |
| 2103 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2104 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2224 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2225 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2226 | + } |
|
| 2105 | 2227 | $table_row = $smcFunc['db_fetch_assoc']($request); |
| 2106 | 2228 | $smcFunc['db_free_result']($request); |
| 2107 | 2229 | |
@@ -2123,18 +2245,19 @@ discard block |
||
| 2123 | 2245 | ) |
| 2124 | 2246 | ); |
| 2125 | 2247 | // No results? Just forget it all together. |
| 2126 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2127 | - unset($table_row['Collation']); |
|
| 2128 | - else |
|
| 2129 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2248 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2249 | + unset($table_row['Collation']); |
|
| 2250 | + } else { |
|
| 2251 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2252 | + } |
|
| 2130 | 2253 | $smcFunc['db_free_result']($request); |
| 2131 | 2254 | } |
| 2132 | 2255 | |
| 2133 | 2256 | if ($column_fix) |
| 2134 | 2257 | { |
| 2135 | 2258 | // Make sure there are no NULL's left. |
| 2136 | - if ($null_fix) |
|
| 2137 | - $smcFunc['db_query']('', ' |
|
| 2259 | + if ($null_fix) { |
|
| 2260 | + $smcFunc['db_query']('', ' |
|
| 2138 | 2261 | UPDATE {db_prefix}' . $change['table'] . ' |
| 2139 | 2262 | SET ' . $change['column'] . ' = {string:default} |
| 2140 | 2263 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2143,6 +2266,7 @@ discard block |
||
| 2143 | 2266 | 'db_error_skip' => true, |
| 2144 | 2267 | ) |
| 2145 | 2268 | ); |
| 2269 | + } |
|
| 2146 | 2270 | |
| 2147 | 2271 | // Do the actual alteration. |
| 2148 | 2272 | $smcFunc['db_query']('', ' |
@@ -2171,8 +2295,9 @@ discard block |
||
| 2171 | 2295 | } |
| 2172 | 2296 | |
| 2173 | 2297 | // Not a column we need to check on? |
| 2174 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
| 2175 | - return; |
|
| 2298 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
| 2299 | + return; |
|
| 2300 | + } |
|
| 2176 | 2301 | |
| 2177 | 2302 | // Break it up you (six|seven). |
| 2178 | 2303 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2191,13 +2316,13 @@ discard block |
||
| 2191 | 2316 | 'new_name' => $temp[2], |
| 2192 | 2317 | )); |
| 2193 | 2318 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2194 | - if ($smcFunc['db_num_rows'] != 1) |
|
| 2195 | - return; |
|
| 2319 | + if ($smcFunc['db_num_rows'] != 1) { |
|
| 2320 | + return; |
|
| 2321 | + } |
|
| 2196 | 2322 | |
| 2197 | 2323 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
| 2198 | 2324 | $smcFunc['db_free_result']($request); |
| 2199 | - } |
|
| 2200 | - else |
|
| 2325 | + } else |
|
| 2201 | 2326 | { |
| 2202 | 2327 | // Do this the old fashion, sure method way. |
| 2203 | 2328 | $request = $smcFunc['db_query']('', ' |
@@ -2208,21 +2333,24 @@ discard block |
||
| 2208 | 2333 | )); |
| 2209 | 2334 | // Mayday! |
| 2210 | 2335 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2211 | - if ($smcFunc['db_num_rows'] == 0) |
|
| 2212 | - return; |
|
| 2336 | + if ($smcFunc['db_num_rows'] == 0) { |
|
| 2337 | + return; |
|
| 2338 | + } |
|
| 2213 | 2339 | |
| 2214 | 2340 | // Oh where, oh where has my little field gone. Oh where can it be... |
| 2215 | - while ($row = $smcFunc['db_query']($request)) |
|
| 2216 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2341 | + while ($row = $smcFunc['db_query']($request)) { |
|
| 2342 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2217 | 2343 | { |
| 2218 | 2344 | $current_type = $row['Type']; |
| 2345 | + } |
|
| 2219 | 2346 | break; |
| 2220 | 2347 | } |
| 2221 | 2348 | } |
| 2222 | 2349 | |
| 2223 | 2350 | // If this doesn't match, the column may of been altered for a reason. |
| 2224 | - if (trim($current_type) != trim($temp[3])) |
|
| 2225 | - $temp[3] = $current_type; |
|
| 2351 | + if (trim($current_type) != trim($temp[3])) { |
|
| 2352 | + $temp[3] = $current_type; |
|
| 2353 | + } |
|
| 2226 | 2354 | |
| 2227 | 2355 | // Piece this back together. |
| 2228 | 2356 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2234,8 +2362,9 @@ discard block |
||
| 2234 | 2362 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
| 2235 | 2363 | global $step_progress, $is_debug, $upcontext; |
| 2236 | 2364 | |
| 2237 | - if ($_GET['substep'] < $substep) |
|
| 2238 | - $_GET['substep'] = $substep; |
|
| 2365 | + if ($_GET['substep'] < $substep) { |
|
| 2366 | + $_GET['substep'] = $substep; |
|
| 2367 | + } |
|
| 2239 | 2368 | |
| 2240 | 2369 | if ($command_line) |
| 2241 | 2370 | { |
@@ -2248,29 +2377,33 @@ discard block |
||
| 2248 | 2377 | } |
| 2249 | 2378 | |
| 2250 | 2379 | @set_time_limit(300); |
| 2251 | - if (function_exists('apache_reset_timeout')) |
|
| 2252 | - @apache_reset_timeout(); |
|
| 2380 | + if (function_exists('apache_reset_timeout')) { |
|
| 2381 | + @apache_reset_timeout(); |
|
| 2382 | + } |
|
| 2253 | 2383 | |
| 2254 | - if (time() - $start_time <= $timeLimitThreshold) |
|
| 2255 | - return; |
|
| 2384 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
| 2385 | + return; |
|
| 2386 | + } |
|
| 2256 | 2387 | |
| 2257 | 2388 | // Do we have some custom step progress stuff? |
| 2258 | 2389 | if (!empty($step_progress)) |
| 2259 | 2390 | { |
| 2260 | 2391 | $upcontext['substep_progress'] = 0; |
| 2261 | 2392 | $upcontext['substep_progress_name'] = $step_progress['name']; |
| 2262 | - if ($step_progress['current'] > $step_progress['total']) |
|
| 2263 | - $upcontext['substep_progress'] = 99.9; |
|
| 2264 | - else |
|
| 2265 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2393 | + if ($step_progress['current'] > $step_progress['total']) { |
|
| 2394 | + $upcontext['substep_progress'] = 99.9; |
|
| 2395 | + } else { |
|
| 2396 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2397 | + } |
|
| 2266 | 2398 | |
| 2267 | 2399 | // Make it nicely rounded. |
| 2268 | 2400 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
| 2269 | 2401 | } |
| 2270 | 2402 | |
| 2271 | 2403 | // If this is XML we just exit right away! |
| 2272 | - if (isset($_GET['xml'])) |
|
| 2273 | - return upgradeExit(); |
|
| 2404 | + if (isset($_GET['xml'])) { |
|
| 2405 | + return upgradeExit(); |
|
| 2406 | + } |
|
| 2274 | 2407 | |
| 2275 | 2408 | // We're going to pause after this! |
| 2276 | 2409 | $upcontext['pause'] = true; |
@@ -2278,13 +2411,15 @@ discard block |
||
| 2278 | 2411 | $upcontext['query_string'] = ''; |
| 2279 | 2412 | foreach ($_GET as $k => $v) |
| 2280 | 2413 | { |
| 2281 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
| 2282 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2414 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
| 2415 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2416 | + } |
|
| 2283 | 2417 | } |
| 2284 | 2418 | |
| 2285 | 2419 | // Custom warning? |
| 2286 | - if (!empty($custom_warning)) |
|
| 2287 | - $upcontext['custom_warning'] = $custom_warning; |
|
| 2420 | + if (!empty($custom_warning)) { |
|
| 2421 | + $upcontext['custom_warning'] = $custom_warning; |
|
| 2422 | + } |
|
| 2288 | 2423 | |
| 2289 | 2424 | upgradeExit(); |
| 2290 | 2425 | } |
@@ -2299,25 +2434,26 @@ discard block |
||
| 2299 | 2434 | ob_implicit_flush(true); |
| 2300 | 2435 | @set_time_limit(600); |
| 2301 | 2436 | |
| 2302 | - if (!isset($_SERVER['argv'])) |
|
| 2303 | - $_SERVER['argv'] = array(); |
|
| 2437 | + if (!isset($_SERVER['argv'])) { |
|
| 2438 | + $_SERVER['argv'] = array(); |
|
| 2439 | + } |
|
| 2304 | 2440 | $_GET['maint'] = 1; |
| 2305 | 2441 | |
| 2306 | 2442 | foreach ($_SERVER['argv'] as $i => $arg) |
| 2307 | 2443 | { |
| 2308 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
| 2309 | - $_GET['lang'] = $match[1]; |
|
| 2310 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
| 2311 | - continue; |
|
| 2312 | - elseif ($arg == '--no-maintenance') |
|
| 2313 | - $_GET['maint'] = 0; |
|
| 2314 | - elseif ($arg == '--debug') |
|
| 2315 | - $is_debug = true; |
|
| 2316 | - elseif ($arg == '--backup') |
|
| 2317 | - $_POST['backup'] = 1; |
|
| 2318 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
| 2319 | - $_GET['conv'] = 1; |
|
| 2320 | - elseif ($i != 0) |
|
| 2444 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
| 2445 | + $_GET['lang'] = $match[1]; |
|
| 2446 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
| 2447 | + continue; |
|
| 2448 | + } elseif ($arg == '--no-maintenance') { |
|
| 2449 | + $_GET['maint'] = 0; |
|
| 2450 | + } elseif ($arg == '--debug') { |
|
| 2451 | + $is_debug = true; |
|
| 2452 | + } elseif ($arg == '--backup') { |
|
| 2453 | + $_POST['backup'] = 1; |
|
| 2454 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
| 2455 | + $_GET['conv'] = 1; |
|
| 2456 | + } elseif ($i != 0) |
|
| 2321 | 2457 | { |
| 2322 | 2458 | echo 'SMF Command-line Upgrader |
| 2323 | 2459 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2331,10 +2467,12 @@ discard block |
||
| 2331 | 2467 | } |
| 2332 | 2468 | } |
| 2333 | 2469 | |
| 2334 | - if (!php_version_check()) |
|
| 2335 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2336 | - if (!db_version_check()) |
|
| 2337 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2470 | + if (!php_version_check()) { |
|
| 2471 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2472 | + } |
|
| 2473 | + if (!db_version_check()) { |
|
| 2474 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2475 | + } |
|
| 2338 | 2476 | |
| 2339 | 2477 | // Do some checks to make sure they have proper privileges |
| 2340 | 2478 | db_extend('packages'); |
@@ -2349,39 +2487,45 @@ discard block |
||
| 2349 | 2487 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 2350 | 2488 | |
| 2351 | 2489 | // Sorry... we need CREATE, ALTER and DROP |
| 2352 | - if (!$create || !$alter || !$drop) |
|
| 2353 | - print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
| 2490 | + if (!$create || !$alter || !$drop) { |
|
| 2491 | + print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true); |
|
| 2492 | + } |
|
| 2354 | 2493 | |
| 2355 | 2494 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
| 2356 | 2495 | && @file_exists($sourcedir . '/QueryString.php') |
| 2357 | 2496 | && @file_exists($sourcedir . '/ManageBoards.php'); |
| 2358 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
| 2359 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2497 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
| 2498 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2499 | + } |
|
| 2360 | 2500 | |
| 2361 | 2501 | // Do a quick version spot check. |
| 2362 | 2502 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 2363 | 2503 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 2364 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 2365 | - print_error('Error: Some files have not yet been updated properly.'); |
|
| 2504 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 2505 | + print_error('Error: Some files have not yet been updated properly.'); |
|
| 2506 | + } |
|
| 2366 | 2507 | |
| 2367 | 2508 | // Make sure Settings.php is writable. |
| 2368 | 2509 | quickFileWritable($boarddir . '/Settings.php'); |
| 2369 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 2370 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2510 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 2511 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2512 | + } |
|
| 2371 | 2513 | |
| 2372 | 2514 | // Make sure Settings_bak.php is writable. |
| 2373 | 2515 | quickFileWritable($boarddir . '/Settings_bak.php'); |
| 2374 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
| 2375 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2516 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
| 2517 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2518 | + } |
|
| 2376 | 2519 | |
| 2377 | 2520 | // Make sure db_last_error.php is writable. |
| 2378 | 2521 | quickFileWritable($boarddir . '/db_last_error.php'); |
| 2379 | - if (!is_writable($boarddir . '/db_last_error.php')) |
|
| 2380 | - print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2522 | + if (!is_writable($boarddir . '/db_last_error.php')) { |
|
| 2523 | + print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2524 | + } |
|
| 2381 | 2525 | |
| 2382 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 2383 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2384 | - elseif (isset($modSettings['agreement'])) |
|
| 2526 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 2527 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2528 | + } elseif (isset($modSettings['agreement'])) |
|
| 2385 | 2529 | { |
| 2386 | 2530 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
| 2387 | 2531 | fwrite($fp, $modSettings['agreement']); |
@@ -2391,31 +2535,36 @@ discard block |
||
| 2391 | 2535 | // Make sure Themes is writable. |
| 2392 | 2536 | quickFileWritable($modSettings['theme_dir']); |
| 2393 | 2537 | |
| 2394 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
| 2395 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2538 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
| 2539 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2540 | + } |
|
| 2396 | 2541 | |
| 2397 | 2542 | // Make sure cache directory exists and is writable! |
| 2398 | 2543 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 2399 | - if (!file_exists($cachedir_temp)) |
|
| 2400 | - @mkdir($cachedir_temp); |
|
| 2544 | + if (!file_exists($cachedir_temp)) { |
|
| 2545 | + @mkdir($cachedir_temp); |
|
| 2546 | + } |
|
| 2401 | 2547 | |
| 2402 | 2548 | // Make sure the cache temp dir is writable. |
| 2403 | 2549 | quickFileWritable($cachedir_temp); |
| 2404 | 2550 | |
| 2405 | - if (!is_writable($cachedir_temp)) |
|
| 2406 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2551 | + if (!is_writable($cachedir_temp)) { |
|
| 2552 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2553 | + } |
|
| 2407 | 2554 | |
| 2408 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 2409 | - print_error('Error: Unable to find language files!', true); |
|
| 2410 | - else |
|
| 2555 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 2556 | + print_error('Error: Unable to find language files!', true); |
|
| 2557 | + } else |
|
| 2411 | 2558 | { |
| 2412 | 2559 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 2413 | 2560 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 2414 | 2561 | |
| 2415 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 2416 | - print_error('Error: Language files out of date.', true); |
|
| 2417 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 2418 | - print_error('Error: Install language is missing for selected language.', true); |
|
| 2562 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 2563 | + print_error('Error: Language files out of date.', true); |
|
| 2564 | + } |
|
| 2565 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 2566 | + print_error('Error: Install language is missing for selected language.', true); |
|
| 2567 | + } |
|
| 2419 | 2568 | |
| 2420 | 2569 | // Otherwise include it! |
| 2421 | 2570 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2434,8 +2583,9 @@ discard block |
||
| 2434 | 2583 | global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js; |
| 2435 | 2584 | |
| 2436 | 2585 | // Done it already? |
| 2437 | - if (!empty($_POST['utf8_done'])) |
|
| 2438 | - return true; |
|
| 2586 | + if (!empty($_POST['utf8_done'])) { |
|
| 2587 | + return true; |
|
| 2588 | + } |
|
| 2439 | 2589 | |
| 2440 | 2590 | // First make sure they aren't already on UTF-8 before we go anywhere... |
| 2441 | 2591 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2448,8 +2598,7 @@ discard block |
||
| 2448 | 2598 | ); |
| 2449 | 2599 | |
| 2450 | 2600 | return true; |
| 2451 | - } |
|
| 2452 | - else |
|
| 2601 | + } else |
|
| 2453 | 2602 | { |
| 2454 | 2603 | $upcontext['page_title'] = 'Converting to UTF8'; |
| 2455 | 2604 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2493,8 +2642,9 @@ discard block |
||
| 2493 | 2642 | ) |
| 2494 | 2643 | ); |
| 2495 | 2644 | $db_charsets = array(); |
| 2496 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2497 | - $db_charsets[] = $row['Charset']; |
|
| 2645 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2646 | + $db_charsets[] = $row['Charset']; |
|
| 2647 | + } |
|
| 2498 | 2648 | |
| 2499 | 2649 | $smcFunc['db_free_result']($request); |
| 2500 | 2650 | |
@@ -2530,13 +2680,15 @@ discard block |
||
| 2530 | 2680 | // If there's a fulltext index, we need to drop it first... |
| 2531 | 2681 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 2532 | 2682 | { |
| 2533 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2534 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2683 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2684 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2535 | 2685 | $upcontext['fulltext_index'][] = $row['Key_name']; |
| 2686 | + } |
|
| 2536 | 2687 | $smcFunc['db_free_result']($request); |
| 2537 | 2688 | |
| 2538 | - if (isset($upcontext['fulltext_index'])) |
|
| 2539 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2689 | + if (isset($upcontext['fulltext_index'])) { |
|
| 2690 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2691 | + } |
|
| 2540 | 2692 | } |
| 2541 | 2693 | |
| 2542 | 2694 | // Drop it and make a note... |
@@ -2726,8 +2878,9 @@ discard block |
||
| 2726 | 2878 | $replace = '%field%'; |
| 2727 | 2879 | |
| 2728 | 2880 | // Build a huge REPLACE statement... |
| 2729 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
| 2730 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 2881 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
| 2882 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 2883 | + } |
|
| 2731 | 2884 | } |
| 2732 | 2885 | |
| 2733 | 2886 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2737,9 +2890,10 @@ discard block |
||
| 2737 | 2890 | $upcontext['table_count'] = count($queryTables); |
| 2738 | 2891 | |
| 2739 | 2892 | // What ones have we already done? |
| 2740 | - foreach ($queryTables as $id => $table) |
|
| 2741 | - if ($id < $_GET['substep']) |
|
| 2893 | + foreach ($queryTables as $id => $table) { |
|
| 2894 | + if ($id < $_GET['substep']) |
|
| 2742 | 2895 | $upcontext['previous_tables'][] = $table; |
| 2896 | + } |
|
| 2743 | 2897 | |
| 2744 | 2898 | $upcontext['cur_table_num'] = $_GET['substep']; |
| 2745 | 2899 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2776,8 +2930,9 @@ discard block |
||
| 2776 | 2930 | nextSubstep($substep); |
| 2777 | 2931 | |
| 2778 | 2932 | // Just to make sure it doesn't time out. |
| 2779 | - if (function_exists('apache_reset_timeout')) |
|
| 2780 | - @apache_reset_timeout(); |
|
| 2933 | + if (function_exists('apache_reset_timeout')) { |
|
| 2934 | + @apache_reset_timeout(); |
|
| 2935 | + } |
|
| 2781 | 2936 | |
| 2782 | 2937 | $table_charsets = array(); |
| 2783 | 2938 | |
@@ -2800,8 +2955,9 @@ discard block |
||
| 2800 | 2955 | |
| 2801 | 2956 | // Build structure of columns to operate on organized by charset; only operate on columns not yet utf8 |
| 2802 | 2957 | if ($charset != 'utf8') { |
| 2803 | - if (!isset($table_charsets[$charset])) |
|
| 2804 | - $table_charsets[$charset] = array(); |
|
| 2958 | + if (!isset($table_charsets[$charset])) { |
|
| 2959 | + $table_charsets[$charset] = array(); |
|
| 2960 | + } |
|
| 2805 | 2961 | |
| 2806 | 2962 | $table_charsets[$charset][] = $column_info; |
| 2807 | 2963 | } |
@@ -2842,10 +2998,11 @@ discard block |
||
| 2842 | 2998 | if (isset($translation_tables[$upcontext['charset_detected']])) |
| 2843 | 2999 | { |
| 2844 | 3000 | $update = ''; |
| 2845 | - foreach ($table_charsets as $charset => $columns) |
|
| 2846 | - foreach ($columns as $column) |
|
| 3001 | + foreach ($table_charsets as $charset => $columns) { |
|
| 3002 | + foreach ($columns as $column) |
|
| 2847 | 3003 | $update .= ' |
| 2848 | 3004 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
| 3005 | + } |
|
| 2849 | 3006 | |
| 2850 | 3007 | $smcFunc['db_query']('', ' |
| 2851 | 3008 | UPDATE {raw:table_name} |
@@ -2870,8 +3027,9 @@ discard block |
||
| 2870 | 3027 | // Now do the actual conversion (if still needed). |
| 2871 | 3028 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
| 2872 | 3029 | { |
| 2873 | - if ($command_line) |
|
| 2874 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3030 | + if ($command_line) { |
|
| 3031 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3032 | + } |
|
| 2875 | 3033 | |
| 2876 | 3034 | $smcFunc['db_query']('', ' |
| 2877 | 3035 | ALTER TABLE {raw:table_name} |
@@ -2881,12 +3039,14 @@ discard block |
||
| 2881 | 3039 | ) |
| 2882 | 3040 | ); |
| 2883 | 3041 | |
| 2884 | - if ($command_line) |
|
| 2885 | - echo " done.\n"; |
|
| 3042 | + if ($command_line) { |
|
| 3043 | + echo " done.\n"; |
|
| 3044 | + } |
|
| 2886 | 3045 | } |
| 2887 | 3046 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 2888 | - if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) |
|
| 2889 | - return upgradeExit(); |
|
| 3047 | + if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) { |
|
| 3048 | + return upgradeExit(); |
|
| 3049 | + } |
|
| 2890 | 3050 | } |
| 2891 | 3051 | |
| 2892 | 3052 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -2915,8 +3075,8 @@ discard block |
||
| 2915 | 3075 | ); |
| 2916 | 3076 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2917 | 3077 | { |
| 2918 | - if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) |
|
| 2919 | - $smcFunc['db_query']('', ' |
|
| 3078 | + if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) { |
|
| 3079 | + $smcFunc['db_query']('', ' |
|
| 2920 | 3080 | UPDATE {db_prefix}log_actions |
| 2921 | 3081 | SET extra = {string:extra} |
| 2922 | 3082 | WHERE id_action = {int:current_action}', |
@@ -2925,6 +3085,7 @@ discard block |
||
| 2925 | 3085 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
| 2926 | 3086 | ) |
| 2927 | 3087 | ); |
| 3088 | + } |
|
| 2928 | 3089 | } |
| 2929 | 3090 | $smcFunc['db_free_result']($request); |
| 2930 | 3091 | |
@@ -2946,15 +3107,17 @@ discard block |
||
| 2946 | 3107 | // First thing's first - did we already do this? |
| 2947 | 3108 | if (!empty($modSettings['json_done'])) |
| 2948 | 3109 | { |
| 2949 | - if ($command_line) |
|
| 2950 | - return DeleteUpgrade(); |
|
| 2951 | - else |
|
| 2952 | - return true; |
|
| 3110 | + if ($command_line) { |
|
| 3111 | + return DeleteUpgrade(); |
|
| 3112 | + } else { |
|
| 3113 | + return true; |
|
| 3114 | + } |
|
| 2953 | 3115 | } |
| 2954 | 3116 | |
| 2955 | 3117 | // Done it already - js wise? |
| 2956 | - if (!empty($_POST['json_done'])) |
|
| 2957 | - return true; |
|
| 3118 | + if (!empty($_POST['json_done'])) { |
|
| 3119 | + return true; |
|
| 3120 | + } |
|
| 2958 | 3121 | |
| 2959 | 3122 | // List of tables affected by this function |
| 2960 | 3123 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -2986,12 +3149,14 @@ discard block |
||
| 2986 | 3149 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
| 2987 | 3150 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
| 2988 | 3151 | |
| 2989 | - foreach ($keys as $id => $table) |
|
| 2990 | - if ($id < $_GET['substep']) |
|
| 3152 | + foreach ($keys as $id => $table) { |
|
| 3153 | + if ($id < $_GET['substep']) |
|
| 2991 | 3154 | $upcontext['previous_tables'][] = $table; |
| 3155 | + } |
|
| 2992 | 3156 | |
| 2993 | - if ($command_line) |
|
| 2994 | - echo 'Converting data from serialize() to json_encode().'; |
|
| 3157 | + if ($command_line) { |
|
| 3158 | + echo 'Converting data from serialize() to json_encode().'; |
|
| 3159 | + } |
|
| 2995 | 3160 | |
| 2996 | 3161 | if (!$support_js || isset($_GET['xml'])) |
| 2997 | 3162 | { |
@@ -3031,8 +3196,9 @@ discard block |
||
| 3031 | 3196 | |
| 3032 | 3197 | // Loop through and fix these... |
| 3033 | 3198 | $new_settings = array(); |
| 3034 | - if ($command_line) |
|
| 3035 | - echo "\n" . 'Fixing some settings...'; |
|
| 3199 | + if ($command_line) { |
|
| 3200 | + echo "\n" . 'Fixing some settings...'; |
|
| 3201 | + } |
|
| 3036 | 3202 | |
| 3037 | 3203 | foreach ($serialized_settings as $var) |
| 3038 | 3204 | { |
@@ -3040,22 +3206,24 @@ discard block |
||
| 3040 | 3206 | { |
| 3041 | 3207 | // Attempt to unserialize the setting |
| 3042 | 3208 | $temp = @safe_unserialize($modSettings[$var]); |
| 3043 | - if (!$temp && $command_line) |
|
| 3044 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3045 | - elseif ($temp !== false) |
|
| 3046 | - $new_settings[$var] = json_encode($temp); |
|
| 3209 | + if (!$temp && $command_line) { |
|
| 3210 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3211 | + } elseif ($temp !== false) { |
|
| 3212 | + $new_settings[$var] = json_encode($temp); |
|
| 3213 | + } |
|
| 3047 | 3214 | } |
| 3048 | 3215 | } |
| 3049 | 3216 | |
| 3050 | 3217 | // Update everything at once |
| 3051 | - if (!function_exists('cache_put_data')) |
|
| 3052 | - require_once($sourcedir . '/Load.php'); |
|
| 3218 | + if (!function_exists('cache_put_data')) { |
|
| 3219 | + require_once($sourcedir . '/Load.php'); |
|
| 3220 | + } |
|
| 3053 | 3221 | updateSettings($new_settings, true); |
| 3054 | 3222 | |
| 3055 | - if ($command_line) |
|
| 3056 | - echo ' done.'; |
|
| 3057 | - } |
|
| 3058 | - elseif ($table == 'themes') |
|
| 3223 | + if ($command_line) { |
|
| 3224 | + echo ' done.'; |
|
| 3225 | + } |
|
| 3226 | + } elseif ($table == 'themes') |
|
| 3059 | 3227 | { |
| 3060 | 3228 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
| 3061 | 3229 | $query = $smcFunc['db_query']('', ' |
@@ -3074,10 +3242,11 @@ discard block |
||
| 3074 | 3242 | |
| 3075 | 3243 | if ($command_line) |
| 3076 | 3244 | { |
| 3077 | - if ($temp === false) |
|
| 3078 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3079 | - else |
|
| 3080 | - echo "\n" . 'Fixing admin preferences...'; |
|
| 3245 | + if ($temp === false) { |
|
| 3246 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3247 | + } else { |
|
| 3248 | + echo "\n" . 'Fixing admin preferences...'; |
|
| 3249 | + } |
|
| 3081 | 3250 | } |
| 3082 | 3251 | |
| 3083 | 3252 | if ($temp !== false) |
@@ -3099,15 +3268,15 @@ discard block |
||
| 3099 | 3268 | ) |
| 3100 | 3269 | ); |
| 3101 | 3270 | |
| 3102 | - if ($command_line) |
|
| 3103 | - echo ' done.'; |
|
| 3271 | + if ($command_line) { |
|
| 3272 | + echo ' done.'; |
|
| 3273 | + } |
|
| 3104 | 3274 | } |
| 3105 | 3275 | } |
| 3106 | 3276 | |
| 3107 | 3277 | $smcFunc['db_free_result']($query); |
| 3108 | 3278 | } |
| 3109 | - } |
|
| 3110 | - else |
|
| 3279 | + } else |
|
| 3111 | 3280 | { |
| 3112 | 3281 | // First item is always the key... |
| 3113 | 3282 | $key = $info[0]; |
@@ -3118,8 +3287,7 @@ discard block |
||
| 3118 | 3287 | { |
| 3119 | 3288 | $col_select = $info[1]; |
| 3120 | 3289 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
| 3121 | - } |
|
| 3122 | - else |
|
| 3290 | + } else |
|
| 3123 | 3291 | { |
| 3124 | 3292 | $col_select = implode(', ', $info); |
| 3125 | 3293 | } |
@@ -3152,8 +3320,7 @@ discard block |
||
| 3152 | 3320 | if ($temp === false && $command_line) |
| 3153 | 3321 | { |
| 3154 | 3322 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
| 3155 | - } |
|
| 3156 | - else |
|
| 3323 | + } else |
|
| 3157 | 3324 | { |
| 3158 | 3325 | $row[$col] = json_encode($temp); |
| 3159 | 3326 | |
@@ -3178,16 +3345,18 @@ discard block |
||
| 3178 | 3345 | } |
| 3179 | 3346 | } |
| 3180 | 3347 | |
| 3181 | - if ($command_line) |
|
| 3182 | - echo ' done.'; |
|
| 3348 | + if ($command_line) { |
|
| 3349 | + echo ' done.'; |
|
| 3350 | + } |
|
| 3183 | 3351 | |
| 3184 | 3352 | // Free up some memory... |
| 3185 | 3353 | $smcFunc['db_free_result']($query); |
| 3186 | 3354 | } |
| 3187 | 3355 | } |
| 3188 | 3356 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3189 | - if (isset($_GET['xml'])) |
|
| 3190 | - return upgradeExit(); |
|
| 3357 | + if (isset($_GET['xml'])) { |
|
| 3358 | + return upgradeExit(); |
|
| 3359 | + } |
|
| 3191 | 3360 | } |
| 3192 | 3361 | |
| 3193 | 3362 | if ($command_line) |
@@ -3202,8 +3371,9 @@ discard block |
||
| 3202 | 3371 | |
| 3203 | 3372 | $_GET['substep'] = 0; |
| 3204 | 3373 | // Make sure we move on! |
| 3205 | - if ($command_line) |
|
| 3206 | - return DeleteUpgrade(); |
|
| 3374 | + if ($command_line) { |
|
| 3375 | + return DeleteUpgrade(); |
|
| 3376 | + } |
|
| 3207 | 3377 | |
| 3208 | 3378 | return true; |
| 3209 | 3379 | } |
@@ -3223,14 +3393,16 @@ discard block |
||
| 3223 | 3393 | global $upcontext, $txt, $settings; |
| 3224 | 3394 | |
| 3225 | 3395 | // Don't call me twice! |
| 3226 | - if (!empty($upcontext['chmod_called'])) |
|
| 3227 | - return; |
|
| 3396 | + if (!empty($upcontext['chmod_called'])) { |
|
| 3397 | + return; |
|
| 3398 | + } |
|
| 3228 | 3399 | |
| 3229 | 3400 | $upcontext['chmod_called'] = true; |
| 3230 | 3401 | |
| 3231 | 3402 | // Nothing? |
| 3232 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
| 3233 | - return; |
|
| 3403 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
| 3404 | + return; |
|
| 3405 | + } |
|
| 3234 | 3406 | |
| 3235 | 3407 | // Was it a problem with Windows? |
| 3236 | 3408 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3262,11 +3434,12 @@ discard block |
||
| 3262 | 3434 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\'); |
| 3263 | 3435 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
| 3264 | 3436 | |
| 3265 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
| 3266 | - echo ' |
|
| 3437 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
| 3438 | + echo ' |
|
| 3267 | 3439 | content.write(\'<hr>\n\t\t\t\'); |
| 3268 | 3440 | content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\'); |
| 3269 | 3441 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
| 3442 | + } |
|
| 3270 | 3443 | |
| 3271 | 3444 | echo ' |
| 3272 | 3445 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3274,17 +3447,19 @@ discard block |
||
| 3274 | 3447 | } |
| 3275 | 3448 | </script>'; |
| 3276 | 3449 | |
| 3277 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
| 3278 | - echo ' |
|
| 3450 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
| 3451 | + echo ' |
|
| 3279 | 3452 | <div class="error_message red"> |
| 3280 | 3453 | The following error was encountered when trying to connect:<br><br> |
| 3281 | 3454 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
| 3282 | 3455 | </div> |
| 3283 | 3456 | <br>'; |
| 3457 | + } |
|
| 3284 | 3458 | |
| 3285 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3286 | - echo ' |
|
| 3459 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3460 | + echo ' |
|
| 3287 | 3461 | <form action="', $upcontext['form_url'], '" method="post">'; |
| 3462 | + } |
|
| 3288 | 3463 | |
| 3289 | 3464 | echo ' |
| 3290 | 3465 | <table width="520" border="0" align="center" style="margin-bottom: 1ex;"> |
@@ -3319,10 +3494,11 @@ discard block |
||
| 3319 | 3494 | <div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div> |
| 3320 | 3495 | </div>'; |
| 3321 | 3496 | |
| 3322 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3323 | - echo ' |
|
| 3497 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3498 | + echo ' |
|
| 3324 | 3499 | </form>'; |
| 3325 | -} |
|
| 3500 | + } |
|
| 3501 | + } |
|
| 3326 | 3502 | |
| 3327 | 3503 | function template_upgrade_above() |
| 3328 | 3504 | { |
@@ -3382,9 +3558,10 @@ discard block |
||
| 3382 | 3558 | <h2>', $txt['upgrade_progress'], '</h2> |
| 3383 | 3559 | <ul>'; |
| 3384 | 3560 | |
| 3385 | - foreach ($upcontext['steps'] as $num => $step) |
|
| 3386 | - echo ' |
|
| 3561 | + foreach ($upcontext['steps'] as $num => $step) { |
|
| 3562 | + echo ' |
|
| 3387 | 3563 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 3564 | + } |
|
| 3388 | 3565 | |
| 3389 | 3566 | echo ' |
| 3390 | 3567 | </ul> |
@@ -3397,8 +3574,8 @@ discard block |
||
| 3397 | 3574 | </div> |
| 3398 | 3575 | </div>'; |
| 3399 | 3576 | |
| 3400 | - if (isset($upcontext['step_progress'])) |
|
| 3401 | - echo ' |
|
| 3577 | + if (isset($upcontext['step_progress'])) { |
|
| 3578 | + echo ' |
|
| 3402 | 3579 | <br> |
| 3403 | 3580 | <br> |
| 3404 | 3581 | <div id="progress_bar_step"> |
@@ -3407,6 +3584,7 @@ discard block |
||
| 3407 | 3584 | <span>', $txt['upgrade_step_progress'], '</span> |
| 3408 | 3585 | </div> |
| 3409 | 3586 | </div>'; |
| 3587 | + } |
|
| 3410 | 3588 | |
| 3411 | 3589 | echo ' |
| 3412 | 3590 | <div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div> |
@@ -3437,32 +3615,36 @@ discard block |
||
| 3437 | 3615 | { |
| 3438 | 3616 | global $upcontext, $txt; |
| 3439 | 3617 | |
| 3440 | - if (!empty($upcontext['pause'])) |
|
| 3441 | - echo ' |
|
| 3618 | + if (!empty($upcontext['pause'])) { |
|
| 3619 | + echo ' |
|
| 3442 | 3620 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
| 3443 | 3621 | |
| 3444 | 3622 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
| 3445 | 3623 | <h3> |
| 3446 | 3624 | ', $txt['upgrade_paused_overload'], ' |
| 3447 | 3625 | </h3>'; |
| 3626 | + } |
|
| 3448 | 3627 | |
| 3449 | - if (!empty($upcontext['custom_warning'])) |
|
| 3450 | - echo ' |
|
| 3628 | + if (!empty($upcontext['custom_warning'])) { |
|
| 3629 | + echo ' |
|
| 3451 | 3630 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3452 | 3631 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3453 | 3632 | <strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br> |
| 3454 | 3633 | <div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div> |
| 3455 | 3634 | </div>'; |
| 3635 | + } |
|
| 3456 | 3636 | |
| 3457 | 3637 | echo ' |
| 3458 | 3638 | <div class="righttext" style="margin: 1ex;">'; |
| 3459 | 3639 | |
| 3460 | - if (!empty($upcontext['continue'])) |
|
| 3461 | - echo ' |
|
| 3640 | + if (!empty($upcontext['continue'])) { |
|
| 3641 | + echo ' |
|
| 3462 | 3642 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">'; |
| 3463 | - if (!empty($upcontext['skip'])) |
|
| 3464 | - echo ' |
|
| 3643 | + } |
|
| 3644 | + if (!empty($upcontext['skip'])) { |
|
| 3645 | + echo ' |
|
| 3465 | 3646 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">'; |
| 3647 | + } |
|
| 3466 | 3648 | |
| 3467 | 3649 | echo ' |
| 3468 | 3650 | </div> |
@@ -3512,11 +3694,12 @@ discard block |
||
| 3512 | 3694 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
| 3513 | 3695 | <smf>'; |
| 3514 | 3696 | |
| 3515 | - if (!empty($upcontext['get_data'])) |
|
| 3516 | - foreach ($upcontext['get_data'] as $k => $v) |
|
| 3697 | + if (!empty($upcontext['get_data'])) { |
|
| 3698 | + foreach ($upcontext['get_data'] as $k => $v) |
|
| 3517 | 3699 | echo ' |
| 3518 | 3700 | <get key="', $k, '">', $v, '</get>'; |
| 3519 | -} |
|
| 3701 | + } |
|
| 3702 | + } |
|
| 3520 | 3703 | |
| 3521 | 3704 | function template_xml_below() |
| 3522 | 3705 | { |
@@ -3557,8 +3740,8 @@ discard block |
||
| 3557 | 3740 | template_chmod(); |
| 3558 | 3741 | |
| 3559 | 3742 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
| 3560 | - if ($upcontext['is_large_forum']) |
|
| 3561 | - echo ' |
|
| 3743 | + if ($upcontext['is_large_forum']) { |
|
| 3744 | + echo ' |
|
| 3562 | 3745 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3563 | 3746 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3564 | 3747 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3566,10 +3749,11 @@ discard block |
||
| 3566 | 3749 | ', $txt['upgrade_warning_lots_data'], ' |
| 3567 | 3750 | </div> |
| 3568 | 3751 | </div>'; |
| 3752 | + } |
|
| 3569 | 3753 | |
| 3570 | 3754 | // A warning message? |
| 3571 | - if (!empty($upcontext['warning'])) |
|
| 3572 | - echo ' |
|
| 3755 | + if (!empty($upcontext['warning'])) { |
|
| 3756 | + echo ' |
|
| 3573 | 3757 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3574 | 3758 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3575 | 3759 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -3577,6 +3761,7 @@ discard block |
||
| 3577 | 3761 | ', $upcontext['warning'], ' |
| 3578 | 3762 | </div> |
| 3579 | 3763 | </div>'; |
| 3764 | + } |
|
| 3580 | 3765 | |
| 3581 | 3766 | // Paths are incorrect? |
| 3582 | 3767 | echo ' |
@@ -3592,20 +3777,22 @@ discard block |
||
| 3592 | 3777 | if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600)) |
| 3593 | 3778 | { |
| 3594 | 3779 | $ago = time() - $upcontext['started']; |
| 3595 | - if ($ago < 60) |
|
| 3596 | - $ago = $ago . ' seconds'; |
|
| 3597 | - elseif ($ago < 3600) |
|
| 3598 | - $ago = (int) ($ago / 60) . ' minutes'; |
|
| 3599 | - else |
|
| 3600 | - $ago = (int) ($ago / 3600) . ' hours'; |
|
| 3780 | + if ($ago < 60) { |
|
| 3781 | + $ago = $ago . ' seconds'; |
|
| 3782 | + } elseif ($ago < 3600) { |
|
| 3783 | + $ago = (int) ($ago / 60) . ' minutes'; |
|
| 3784 | + } else { |
|
| 3785 | + $ago = (int) ($ago / 3600) . ' hours'; |
|
| 3786 | + } |
|
| 3601 | 3787 | |
| 3602 | 3788 | $active = time() - $upcontext['updated']; |
| 3603 | - if ($active < 60) |
|
| 3604 | - $updated = $active . ' seconds'; |
|
| 3605 | - elseif ($active < 3600) |
|
| 3606 | - $updated = (int) ($active / 60) . ' minutes'; |
|
| 3607 | - else |
|
| 3608 | - $updated = (int) ($active / 3600) . ' hours'; |
|
| 3789 | + if ($active < 60) { |
|
| 3790 | + $updated = $active . ' seconds'; |
|
| 3791 | + } elseif ($active < 3600) { |
|
| 3792 | + $updated = (int) ($active / 60) . ' minutes'; |
|
| 3793 | + } else { |
|
| 3794 | + $updated = (int) ($active / 3600) . ' hours'; |
|
| 3795 | + } |
|
| 3609 | 3796 | |
| 3610 | 3797 | echo ' |
| 3611 | 3798 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
@@ -3614,16 +3801,18 @@ discard block |
||
| 3614 | 3801 | <div style="padding-left: 6ex;"> |
| 3615 | 3802 | "', $upcontext['user']['name'], '" has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.'; |
| 3616 | 3803 | |
| 3617 | - if ($active < 600) |
|
| 3618 | - echo ' |
|
| 3804 | + if ($active < 600) { |
|
| 3805 | + echo ' |
|
| 3619 | 3806 | We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.'; |
| 3807 | + } |
|
| 3620 | 3808 | |
| 3621 | - if ($active > $upcontext['inactive_timeout']) |
|
| 3622 | - echo ' |
|
| 3809 | + if ($active > $upcontext['inactive_timeout']) { |
|
| 3810 | + echo ' |
|
| 3623 | 3811 | <br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.'; |
| 3624 | - else |
|
| 3625 | - echo ' |
|
| 3812 | + } else { |
|
| 3813 | + echo ' |
|
| 3626 | 3814 | <br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'); |
| 3815 | + } |
|
| 3627 | 3816 | |
| 3628 | 3817 | echo ' |
| 3629 | 3818 | </div> |
@@ -3639,9 +3828,10 @@ discard block |
||
| 3639 | 3828 | <td> |
| 3640 | 3829 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">'; |
| 3641 | 3830 | |
| 3642 | - if (!empty($upcontext['username_incorrect'])) |
|
| 3643 | - echo ' |
|
| 3831 | + if (!empty($upcontext['username_incorrect'])) { |
|
| 3832 | + echo ' |
|
| 3644 | 3833 | <div class="smalltext" style="color: red;">Username Incorrect</div>'; |
| 3834 | + } |
|
| 3645 | 3835 | |
| 3646 | 3836 | echo ' |
| 3647 | 3837 | </td> |
@@ -3652,9 +3842,10 @@ discard block |
||
| 3652 | 3842 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password"> |
| 3653 | 3843 | <input type="hidden" name="hash_passwrd" value="">'; |
| 3654 | 3844 | |
| 3655 | - if (!empty($upcontext['password_failed'])) |
|
| 3656 | - echo ' |
|
| 3845 | + if (!empty($upcontext['password_failed'])) { |
|
| 3846 | + echo ' |
|
| 3657 | 3847 | <div class="smalltext" style="color: red;">Password Incorrect</div>'; |
| 3848 | + } |
|
| 3658 | 3849 | |
| 3659 | 3850 | echo ' |
| 3660 | 3851 | </td> |
@@ -3725,8 +3916,8 @@ discard block |
||
| 3725 | 3916 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
| 3726 | 3917 | |
| 3727 | 3918 | // Warning message? |
| 3728 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
| 3729 | - echo ' |
|
| 3919 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
| 3920 | + echo ' |
|
| 3730 | 3921 | <div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
| 3731 | 3922 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
| 3732 | 3923 | <strong style="text-decoration: underline;">Warning!</strong><br> |
@@ -3734,6 +3925,7 @@ discard block |
||
| 3734 | 3925 | ', $upcontext['upgrade_options_warning'], ' |
| 3735 | 3926 | </div> |
| 3736 | 3927 | </div>'; |
| 3928 | + } |
|
| 3737 | 3929 | |
| 3738 | 3930 | echo ' |
| 3739 | 3931 | <table> |
@@ -3776,8 +3968,8 @@ discard block |
||
| 3776 | 3968 | </td> |
| 3777 | 3969 | </tr>'; |
| 3778 | 3970 | |
| 3779 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
| 3780 | - echo ' |
|
| 3971 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
| 3972 | + echo ' |
|
| 3781 | 3973 | <tr valign="top"> |
| 3782 | 3974 | <td width="2%"> |
| 3783 | 3975 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check"> |
@@ -3786,6 +3978,7 @@ discard block |
||
| 3786 | 3978 | <label for="delete_karma">Delete all karma settings and info from the DB</label> |
| 3787 | 3979 | </td> |
| 3788 | 3980 | </tr>'; |
| 3981 | + } |
|
| 3789 | 3982 | |
| 3790 | 3983 | echo ' |
| 3791 | 3984 | <tr valign="top"> |
@@ -3823,10 +4016,11 @@ discard block |
||
| 3823 | 4016 | </div>'; |
| 3824 | 4017 | |
| 3825 | 4018 | // Dont any tables so far? |
| 3826 | - if (!empty($upcontext['previous_tables'])) |
|
| 3827 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4019 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4020 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 3828 | 4021 | echo ' |
| 3829 | 4022 | <br>Completed Table: "', $table, '".'; |
| 4023 | + } |
|
| 3830 | 4024 | |
| 3831 | 4025 | echo ' |
| 3832 | 4026 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
@@ -3863,12 +4057,13 @@ discard block |
||
| 3863 | 4057 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 3864 | 4058 | |
| 3865 | 4059 | // If debug flood the screen. |
| 3866 | - if ($is_debug) |
|
| 3867 | - echo ' |
|
| 4060 | + if ($is_debug) { |
|
| 4061 | + echo ' |
|
| 3868 | 4062 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 3869 | 4063 | |
| 3870 | 4064 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 3871 | 4065 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4066 | + } |
|
| 3872 | 4067 | |
| 3873 | 4068 | echo ' |
| 3874 | 4069 | // Get the next update... |
@@ -3901,8 +4096,9 @@ discard block |
||
| 3901 | 4096 | { |
| 3902 | 4097 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold; |
| 3903 | 4098 | |
| 3904 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
| 3905 | - $is_debug = true; |
|
| 4099 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
| 4100 | + $is_debug = true; |
|
| 4101 | + } |
|
| 3906 | 4102 | |
| 3907 | 4103 | echo ' |
| 3908 | 4104 | <h3>Executing database changes</h3> |
@@ -3917,8 +4113,9 @@ discard block |
||
| 3917 | 4113 | { |
| 3918 | 4114 | foreach ($upcontext['actioned_items'] as $num => $item) |
| 3919 | 4115 | { |
| 3920 | - if ($num != 0) |
|
| 3921 | - echo ' Successful!'; |
|
| 4116 | + if ($num != 0) { |
|
| 4117 | + echo ' Successful!'; |
|
| 4118 | + } |
|
| 3922 | 4119 | echo '<br>' . $item; |
| 3923 | 4120 | } |
| 3924 | 4121 | if (!empty($upcontext['changes_complete'])) |
@@ -3931,28 +4128,32 @@ discard block |
||
| 3931 | 4128 | $seconds = intval($active % 60); |
| 3932 | 4129 | |
| 3933 | 4130 | $totalTime = ''; |
| 3934 | - if ($hours > 0) |
|
| 3935 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 3936 | - if ($minutes > 0) |
|
| 3937 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 3938 | - if ($seconds > 0) |
|
| 3939 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4131 | + if ($hours > 0) { |
|
| 4132 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4133 | + } |
|
| 4134 | + if ($minutes > 0) { |
|
| 4135 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4136 | + } |
|
| 4137 | + if ($seconds > 0) { |
|
| 4138 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4139 | + } |
|
| 3940 | 4140 | } |
| 3941 | 4141 | |
| 3942 | - if ($is_debug && !empty($totalTime)) |
|
| 3943 | - echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
| 3944 | - else |
|
| 3945 | - echo ' Successful!<br><br>'; |
|
| 4142 | + if ($is_debug && !empty($totalTime)) { |
|
| 4143 | + echo ' Successful! Completed in ', $totalTime, '<br><br>'; |
|
| 4144 | + } else { |
|
| 4145 | + echo ' Successful!<br><br>'; |
|
| 4146 | + } |
|
| 3946 | 4147 | |
| 3947 | 4148 | echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>'; |
| 3948 | 4149 | } |
| 3949 | - } |
|
| 3950 | - else |
|
| 4150 | + } else |
|
| 3951 | 4151 | { |
| 3952 | 4152 | // Tell them how many files we have in total. |
| 3953 | - if ($upcontext['file_count'] > 1) |
|
| 3954 | - echo ' |
|
| 4153 | + if ($upcontext['file_count'] > 1) { |
|
| 4154 | + echo ' |
|
| 3955 | 4155 | <strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
| 4156 | + } |
|
| 3956 | 4157 | |
| 3957 | 4158 | echo ' |
| 3958 | 4159 | <h3 id="info2"><strong>Executing:</strong> "<span id="cur_item_name">', $upcontext['current_item_name'], '</span>" (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3> |
@@ -3968,19 +4169,23 @@ discard block |
||
| 3968 | 4169 | $seconds = intval($active % 60); |
| 3969 | 4170 | |
| 3970 | 4171 | $totalTime = ''; |
| 3971 | - if ($hours > 0) |
|
| 3972 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 3973 | - if ($minutes > 0) |
|
| 3974 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 3975 | - if ($seconds > 0) |
|
| 3976 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4172 | + if ($hours > 0) { |
|
| 4173 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4174 | + } |
|
| 4175 | + if ($minutes > 0) { |
|
| 4176 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4177 | + } |
|
| 4178 | + if ($seconds > 0) { |
|
| 4179 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4180 | + } |
|
| 3977 | 4181 | } |
| 3978 | 4182 | |
| 3979 | 4183 | echo ' |
| 3980 | 4184 | <br><span id="upgradeCompleted">'; |
| 3981 | 4185 | |
| 3982 | - if (!empty($totalTime)) |
|
| 3983 | - echo 'Completed in ', $totalTime, '<br>'; |
|
| 4186 | + if (!empty($totalTime)) { |
|
| 4187 | + echo 'Completed in ', $totalTime, '<br>'; |
|
| 4188 | + } |
|
| 3984 | 4189 | |
| 3985 | 4190 | echo '</span> |
| 3986 | 4191 | <div id="debug_section" style="height: 59px; overflow: auto;"> |
@@ -4017,9 +4222,10 @@ discard block |
||
| 4017 | 4222 | var getData = ""; |
| 4018 | 4223 | var debugItems = ', $upcontext['debug_items'], ';'; |
| 4019 | 4224 | |
| 4020 | - if ($is_debug) |
|
| 4021 | - echo ' |
|
| 4225 | + if ($is_debug) { |
|
| 4226 | + echo ' |
|
| 4022 | 4227 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
| 4228 | + } |
|
| 4023 | 4229 | |
| 4024 | 4230 | echo ' |
| 4025 | 4231 | function getNextItem() |
@@ -4059,9 +4265,10 @@ discard block |
||
| 4059 | 4265 | document.getElementById("error_block").style.display = ""; |
| 4060 | 4266 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
| 4061 | 4267 | |
| 4062 | - if ($is_debug) |
|
| 4063 | - echo ' |
|
| 4268 | + if ($is_debug) { |
|
| 4269 | + echo ' |
|
| 4064 | 4270 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4271 | + } |
|
| 4065 | 4272 | |
| 4066 | 4273 | echo ' |
| 4067 | 4274 | } |
@@ -4082,9 +4289,10 @@ discard block |
||
| 4082 | 4289 | document.getElementById("error_block").style.display = ""; |
| 4083 | 4290 | setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);'; |
| 4084 | 4291 | |
| 4085 | - if ($is_debug) |
|
| 4086 | - echo ' |
|
| 4292 | + if ($is_debug) { |
|
| 4293 | + echo ' |
|
| 4087 | 4294 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4295 | + } |
|
| 4088 | 4296 | |
| 4089 | 4297 | echo ' |
| 4090 | 4298 | } |
@@ -4143,8 +4351,8 @@ discard block |
||
| 4143 | 4351 | if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ') |
| 4144 | 4352 | {'; |
| 4145 | 4353 | |
| 4146 | - if ($is_debug) |
|
| 4147 | - echo ' |
|
| 4354 | + if ($is_debug) { |
|
| 4355 | + echo ' |
|
| 4148 | 4356 | document.getElementById(\'debug_section\').style.display = "none"; |
| 4149 | 4357 | |
| 4150 | 4358 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4162,6 +4370,7 @@ discard block |
||
| 4162 | 4370 | totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : ""); |
| 4163 | 4371 | |
| 4164 | 4372 | setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);'; |
| 4373 | + } |
|
| 4165 | 4374 | |
| 4166 | 4375 | echo ' |
| 4167 | 4376 | |
@@ -4169,9 +4378,10 @@ discard block |
||
| 4169 | 4378 | document.getElementById(\'contbutt\').disabled = 0; |
| 4170 | 4379 | document.getElementById(\'database_done\').value = 1;'; |
| 4171 | 4380 | |
| 4172 | - if ($upcontext['file_count'] > 1) |
|
| 4173 | - echo ' |
|
| 4381 | + if ($upcontext['file_count'] > 1) { |
|
| 4382 | + echo ' |
|
| 4174 | 4383 | document.getElementById(\'info1\').style.display = "none";'; |
| 4384 | + } |
|
| 4175 | 4385 | |
| 4176 | 4386 | echo ' |
| 4177 | 4387 | document.getElementById(\'info2\').style.display = "none"; |
@@ -4184,9 +4394,10 @@ discard block |
||
| 4184 | 4394 | lastItem = 0; |
| 4185 | 4395 | prevFile = curFile;'; |
| 4186 | 4396 | |
| 4187 | - if ($is_debug) |
|
| 4188 | - echo ' |
|
| 4397 | + if ($is_debug) { |
|
| 4398 | + echo ' |
|
| 4189 | 4399 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
| 4400 | + } |
|
| 4190 | 4401 | |
| 4191 | 4402 | echo ' |
| 4192 | 4403 | getNextItem(); |
@@ -4194,8 +4405,8 @@ discard block |
||
| 4194 | 4405 | }'; |
| 4195 | 4406 | |
| 4196 | 4407 | // If debug scroll the screen. |
| 4197 | - if ($is_debug) |
|
| 4198 | - echo ' |
|
| 4408 | + if ($is_debug) { |
|
| 4409 | + echo ' |
|
| 4199 | 4410 | if (iLastSubStepProgress == -1) |
| 4200 | 4411 | { |
| 4201 | 4412 | // Give it consistent dots. |
@@ -4214,6 +4425,7 @@ discard block |
||
| 4214 | 4425 | |
| 4215 | 4426 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4216 | 4427 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4428 | + } |
|
| 4217 | 4429 | |
| 4218 | 4430 | echo ' |
| 4219 | 4431 | // Update the page. |
@@ -4274,9 +4486,10 @@ discard block |
||
| 4274 | 4486 | }'; |
| 4275 | 4487 | |
| 4276 | 4488 | // Start things off assuming we've not errored. |
| 4277 | - if (empty($upcontext['error_message'])) |
|
| 4278 | - echo ' |
|
| 4489 | + if (empty($upcontext['error_message'])) { |
|
| 4490 | + echo ' |
|
| 4279 | 4491 | getNextItem();'; |
| 4492 | + } |
|
| 4280 | 4493 | |
| 4281 | 4494 | echo ' |
| 4282 | 4495 | //# sourceURL=dynamicScript-dbch.js |
@@ -4294,18 +4507,21 @@ discard block |
||
| 4294 | 4507 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
| 4295 | 4508 | <debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>'; |
| 4296 | 4509 | |
| 4297 | - if (!empty($upcontext['error_message'])) |
|
| 4298 | - echo ' |
|
| 4510 | + if (!empty($upcontext['error_message'])) { |
|
| 4511 | + echo ' |
|
| 4299 | 4512 | <error>', $upcontext['error_message'], '</error>'; |
| 4513 | + } |
|
| 4300 | 4514 | |
| 4301 | - if (!empty($upcontext['error_string'])) |
|
| 4302 | - echo ' |
|
| 4515 | + if (!empty($upcontext['error_string'])) { |
|
| 4516 | + echo ' |
|
| 4303 | 4517 | <sql>', $upcontext['error_string'], '</sql>'; |
| 4518 | + } |
|
| 4304 | 4519 | |
| 4305 | - if ($is_debug) |
|
| 4306 | - echo ' |
|
| 4520 | + if ($is_debug) { |
|
| 4521 | + echo ' |
|
| 4307 | 4522 | <curtime>', time(), '</curtime>'; |
| 4308 | -} |
|
| 4523 | + } |
|
| 4524 | + } |
|
| 4309 | 4525 | |
| 4310 | 4526 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
| 4311 | 4527 | function template_convert_utf8() |
@@ -4324,18 +4540,20 @@ discard block |
||
| 4324 | 4540 | </div>'; |
| 4325 | 4541 | |
| 4326 | 4542 | // Done any tables so far? |
| 4327 | - if (!empty($upcontext['previous_tables'])) |
|
| 4328 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4543 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4544 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4329 | 4545 | echo ' |
| 4330 | 4546 | <br>Completed Table: "', $table, '".'; |
| 4547 | + } |
|
| 4331 | 4548 | |
| 4332 | 4549 | echo ' |
| 4333 | 4550 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3>'; |
| 4334 | 4551 | |
| 4335 | 4552 | // If we dropped their index, let's let them know |
| 4336 | - if ($upcontext['dropping_index']) |
|
| 4337 | - echo ' |
|
| 4553 | + if ($upcontext['dropping_index']) { |
|
| 4554 | + echo ' |
|
| 4338 | 4555 | <br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>'; |
| 4556 | + } |
|
| 4339 | 4557 | |
| 4340 | 4558 | // Completion notification |
| 4341 | 4559 | echo ' |
@@ -4372,12 +4590,13 @@ discard block |
||
| 4372 | 4590 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4373 | 4591 | |
| 4374 | 4592 | // If debug flood the screen. |
| 4375 | - if ($is_debug) |
|
| 4376 | - echo ' |
|
| 4593 | + if ($is_debug) { |
|
| 4594 | + echo ' |
|
| 4377 | 4595 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4378 | 4596 | |
| 4379 | 4597 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4380 | 4598 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4599 | + } |
|
| 4381 | 4600 | |
| 4382 | 4601 | echo ' |
| 4383 | 4602 | // Get the next update... |
@@ -4425,19 +4644,21 @@ discard block |
||
| 4425 | 4644 | </div>'; |
| 4426 | 4645 | |
| 4427 | 4646 | // Dont any tables so far? |
| 4428 | - if (!empty($upcontext['previous_tables'])) |
|
| 4429 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4647 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4648 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4430 | 4649 | echo ' |
| 4431 | 4650 | <br>Completed Table: "', $table, '".'; |
| 4651 | + } |
|
| 4432 | 4652 | |
| 4433 | 4653 | echo ' |
| 4434 | 4654 | <h3 id="current_tab_div">Current Table: "<span id="current_table">', $upcontext['cur_table_name'], '</span>"</h3> |
| 4435 | 4655 | <br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>'; |
| 4436 | 4656 | |
| 4437 | 4657 | // Try to make sure substep was reset. |
| 4438 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
| 4439 | - echo ' |
|
| 4658 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
| 4659 | + echo ' |
|
| 4440 | 4660 | <input type="hidden" name="substep" id="substep" value="0">'; |
| 4661 | + } |
|
| 4441 | 4662 | |
| 4442 | 4663 | // Continue please! |
| 4443 | 4664 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4470,12 +4691,13 @@ discard block |
||
| 4470 | 4691 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4471 | 4692 | |
| 4472 | 4693 | // If debug flood the screen. |
| 4473 | - if ($is_debug) |
|
| 4474 | - echo ' |
|
| 4694 | + if ($is_debug) { |
|
| 4695 | + echo ' |
|
| 4475 | 4696 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4476 | 4697 | |
| 4477 | 4698 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4478 | 4699 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4700 | + } |
|
| 4479 | 4701 | |
| 4480 | 4702 | echo ' |
| 4481 | 4703 | // Get the next update... |
@@ -4511,8 +4733,8 @@ discard block |
||
| 4511 | 4733 | <h3>That wasn\'t so hard, was it? Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>. Hope you like it!</h3> |
| 4512 | 4734 | <form action="', $boardurl, '/index.php">'; |
| 4513 | 4735 | |
| 4514 | - if (!empty($upcontext['can_delete_script'])) |
|
| 4515 | - echo ' |
|
| 4736 | + if (!empty($upcontext['can_delete_script'])) { |
|
| 4737 | + echo ' |
|
| 4516 | 4738 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em> |
| 4517 | 4739 | <script> |
| 4518 | 4740 | function doTheDelete(theCheck) |
@@ -4524,6 +4746,7 @@ discard block |
||
| 4524 | 4746 | } |
| 4525 | 4747 | </script> |
| 4526 | 4748 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
| 4749 | + } |
|
| 4527 | 4750 | |
| 4528 | 4751 | $active = time() - $upcontext['started']; |
| 4529 | 4752 | $hours = floor($active / 3600); |
@@ -4533,16 +4756,20 @@ discard block |
||
| 4533 | 4756 | if ($is_debug) |
| 4534 | 4757 | { |
| 4535 | 4758 | $totalTime = ''; |
| 4536 | - if ($hours > 0) |
|
| 4537 | - $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4538 | - if ($minutes > 0) |
|
| 4539 | - $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4540 | - if ($seconds > 0) |
|
| 4541 | - $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4759 | + if ($hours > 0) { |
|
| 4760 | + $totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' '; |
|
| 4761 | + } |
|
| 4762 | + if ($minutes > 0) { |
|
| 4763 | + $totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' '; |
|
| 4764 | + } |
|
| 4765 | + if ($seconds > 0) { |
|
| 4766 | + $totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' '; |
|
| 4767 | + } |
|
| 4542 | 4768 | } |
| 4543 | 4769 | |
| 4544 | - if ($is_debug && !empty($totalTime)) |
|
| 4545 | - echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
| 4770 | + if ($is_debug && !empty($totalTime)) { |
|
| 4771 | + echo '<br> Upgrade completed in ', $totalTime, '<br><br>'; |
|
| 4772 | + } |
|
| 4546 | 4773 | |
| 4547 | 4774 | echo '<br> |
| 4548 | 4775 | If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br> |
@@ -4569,8 +4796,9 @@ discard block |
||
| 4569 | 4796 | |
| 4570 | 4797 | $current_substep = $_GET['substep']; |
| 4571 | 4798 | |
| 4572 | - if (empty($_GET['a'])) |
|
| 4573 | - $_GET['a'] = 0; |
|
| 4799 | + if (empty($_GET['a'])) { |
|
| 4800 | + $_GET['a'] = 0; |
|
| 4801 | + } |
|
| 4574 | 4802 | $step_progress['name'] = 'Converting ips'; |
| 4575 | 4803 | $step_progress['current'] = $_GET['a']; |
| 4576 | 4804 | |
@@ -4613,16 +4841,19 @@ discard block |
||
| 4613 | 4841 | 'empty' => '', |
| 4614 | 4842 | 'limit' => $limit, |
| 4615 | 4843 | )); |
| 4616 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4617 | - $arIp[] = $row[$oldCol]; |
|
| 4844 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4845 | + $arIp[] = $row[$oldCol]; |
|
| 4846 | + } |
|
| 4618 | 4847 | $smcFunc['db_free_result']($request); |
| 4619 | 4848 | |
| 4620 | 4849 | // Special case, null ip could keep us in a loop. |
| 4621 | - if (is_null($arIp[0])) |
|
| 4622 | - unset($arIp[0]); |
|
| 4850 | + if (is_null($arIp[0])) { |
|
| 4851 | + unset($arIp[0]); |
|
| 4852 | + } |
|
| 4623 | 4853 | |
| 4624 | - if (empty($arIp)) |
|
| 4625 | - $is_done = true; |
|
| 4854 | + if (empty($arIp)) { |
|
| 4855 | + $is_done = true; |
|
| 4856 | + } |
|
| 4626 | 4857 | |
| 4627 | 4858 | $updates = array(); |
| 4628 | 4859 | $cases = array(); |
@@ -4631,16 +4862,18 @@ discard block |
||
| 4631 | 4862 | { |
| 4632 | 4863 | $arIp[$i] = trim($arIp[$i]); |
| 4633 | 4864 | |
| 4634 | - if (empty($arIp[$i])) |
|
| 4635 | - continue; |
|
| 4865 | + if (empty($arIp[$i])) { |
|
| 4866 | + continue; |
|
| 4867 | + } |
|
| 4636 | 4868 | |
| 4637 | 4869 | $updates['ip' . $i] = $arIp[$i]; |
| 4638 | 4870 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
| 4639 | 4871 | |
| 4640 | 4872 | if ($setSize > 0 && $i % $setSize === 0) |
| 4641 | 4873 | { |
| 4642 | - if (count($updates) == 1) |
|
| 4643 | - continue; |
|
| 4874 | + if (count($updates) == 1) { |
|
| 4875 | + continue; |
|
| 4876 | + } |
|
| 4644 | 4877 | |
| 4645 | 4878 | $updates['whereSet'] = array_values($updates); |
| 4646 | 4879 | $smcFunc['db_query']('', ' |
@@ -4674,8 +4907,7 @@ discard block |
||
| 4674 | 4907 | 'ip' => $ip |
| 4675 | 4908 | )); |
| 4676 | 4909 | } |
| 4677 | - } |
|
| 4678 | - else |
|
| 4910 | + } else |
|
| 4679 | 4911 | { |
| 4680 | 4912 | $updates['whereSet'] = array_values($updates); |
| 4681 | 4913 | $smcFunc['db_query']('', ' |
@@ -4689,9 +4921,9 @@ discard block |
||
| 4689 | 4921 | $updates |
| 4690 | 4922 | ); |
| 4691 | 4923 | } |
| 4924 | + } else { |
|
| 4925 | + $is_done = true; |
|
| 4692 | 4926 | } |
| 4693 | - else |
|
| 4694 | - $is_done = true; |
|
| 4695 | 4927 | |
| 4696 | 4928 | $_GET['a'] += $limit; |
| 4697 | 4929 | $step_progress['current'] = $_GET['a']; |
@@ -4717,10 +4949,11 @@ discard block |
||
| 4717 | 4949 | |
| 4718 | 4950 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
| 4719 | 4951 | |
| 4720 | - if (isset($columns[$column])) |
|
| 4721 | - return $columns[$column]; |
|
| 4722 | - else |
|
| 4723 | - return null; |
|
| 4724 | -} |
|
| 4952 | + if (isset($columns[$column])) { |
|
| 4953 | + return $columns[$column]; |
|
| 4954 | + } else { |
|
| 4955 | + return null; |
|
| 4956 | + } |
|
| 4957 | + } |
|
| 4725 | 4958 | |
| 4726 | 4959 | ?> |
| 4727 | 4960 | \ No newline at end of file |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | public $headers; |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Start the curl object |
|
| 98 | - * - allow for user override values |
|
| 99 | - * |
|
| 100 | - * @param array $options An array of cURL options |
|
| 101 | - * @param int $max_redirect Maximum number of redirects |
|
| 102 | - */ |
|
| 97 | + * Start the curl object |
|
| 98 | + * - allow for user override values |
|
| 99 | + * |
|
| 100 | + * @param array $options An array of cURL options |
|
| 101 | + * @param int $max_redirect Maximum number of redirects |
|
| 102 | + */ |
|
| 103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
| 104 | 104 | { |
| 105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | - * Main calling function, |
|
| 112 | - * - will request the page data from a given $url |
|
| 113 | - * - optionally will post data to the page form if post data is supplied |
|
| 114 | - * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | - * |
|
| 117 | - * @param string $url the site we are going to fetch |
|
| 118 | - * @param array $post_data any post data as form name => value |
|
| 119 | - * @return object An instance of the curl_fetch_web_data class |
|
| 120 | - */ |
|
| 111 | + * Main calling function, |
|
| 112 | + * - will request the page data from a given $url |
|
| 113 | + * - optionally will post data to the page form if post data is supplied |
|
| 114 | + * - passed arrays will be converted to a post string joined with &'s |
|
| 115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
| 116 | + * |
|
| 117 | + * @param string $url the site we are going to fetch |
|
| 118 | + * @param array $post_data any post data as form name => value |
|
| 119 | + * @return object An instance of the curl_fetch_web_data class |
|
| 120 | + */ |
|
| 121 | 121 | public function get_url_data($url, $post_data = array()) |
| 122 | 122 | { |
| 123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Makes the actual cURL call |
|
| 138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | - * |
|
| 141 | - * @param string $url The site to fetch |
|
| 142 | - * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | - */ |
|
| 137 | + * Makes the actual cURL call |
|
| 138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
| 139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
| 140 | + * |
|
| 141 | + * @param string $url The site to fetch |
|
| 142 | + * @param bool $redirect Whether or not this was a redirect request |
|
| 143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | + */ |
|
| 145 | 145 | private function curl_request($url, $redirect = false) |
| 146 | 146 | { |
| 147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | - * |
|
| 198 | - * @param string $last_url The URL we went to |
|
| 199 | - * @param string $new_url The URL we were redirected to |
|
| 200 | - * @return string The new URL that was in the HTTP header |
|
| 201 | - */ |
|
| 196 | + * Used if being redirected to ensure we have a fully qualified address |
|
| 197 | + * |
|
| 198 | + * @param string $last_url The URL we went to |
|
| 199 | + * @param string $new_url The URL we were redirected to |
|
| 200 | + * @return string The new URL that was in the HTTP header |
|
| 201 | + */ |
|
| 202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
| 203 | 203 | { |
| 204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | - * Used to return the results to the calling program |
|
| 220 | - * - called as ->result() will return the full final array |
|
| 221 | - * - called as ->result('body') to just return the page source of the result |
|
| 222 | - * |
|
| 223 | - * @param string $area Used to return an area such as body, header, error |
|
| 224 | - * @return string The response |
|
| 225 | - */ |
|
| 219 | + * Used to return the results to the calling program |
|
| 220 | + * - called as ->result() will return the full final array |
|
| 221 | + * - called as ->result('body') to just return the page source of the result |
|
| 222 | + * |
|
| 223 | + * @param string $area Used to return an area such as body, header, error |
|
| 224 | + * @return string The response |
|
| 225 | + */ |
|
| 226 | 226 | public function result($area = '') |
| 227 | 227 | { |
| 228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | - * Will return all results from all loops (redirects) |
|
| 239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | - * - Call as ->result_raw() for everything. |
|
| 241 | - * |
|
| 242 | - * @param string $response_number Which response we want to get |
|
| 243 | - * @return array|string The entire response array or just the specified response |
|
| 244 | - */ |
|
| 238 | + * Will return all results from all loops (redirects) |
|
| 239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
| 240 | + * - Call as ->result_raw() for everything. |
|
| 241 | + * |
|
| 242 | + * @param string $response_number Which response we want to get |
|
| 243 | + * @return array|string The entire response array or just the specified response |
|
| 244 | + */ |
|
| 245 | 245 | public function result_raw($response_number = '') |
| 246 | 246 | { |
| 247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Takes supplied POST data and url encodes it |
|
| 258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | - * |
|
| 261 | - * @param array|string $post_data The raw POST data |
|
| 262 | - * @return string A string of post data |
|
| 263 | - */ |
|
| 257 | + * Takes supplied POST data and url encodes it |
|
| 258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
| 259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
| 260 | + * |
|
| 261 | + * @param array|string $post_data The raw POST data |
|
| 262 | + * @return string A string of post data |
|
| 263 | + */ |
|
| 264 | 264 | private function build_post_data($post_data) |
| 265 | 265 | { |
| 266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * Sets the final cURL options for the current call |
|
| 283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | - * - sets the callback function now that $this is existing |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 282 | + * Sets the final cURL options for the current call |
|
| 283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
| 284 | + * - sets the callback function now that $this is existing |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | 287 | private function set_options() |
| 288 | 288 | { |
| 289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | - * |
|
| 314 | - * @param string $target_url The URL we want to redirect to |
|
| 315 | - * @param string $referer_url The URL that we're redirecting from |
|
| 316 | - */ |
|
| 311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
| 312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
| 313 | + * |
|
| 314 | + * @param string $target_url The URL we want to redirect to |
|
| 315 | + * @param string $referer_url The URL that we're redirecting from |
|
| 316 | + */ |
|
| 317 | 317 | private function redirect($target_url, $referer_url) |
| 318 | 318 | { |
| 319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
| 326 | - * Callback function to parse returned headers |
|
| 327 | - * - lowercases everything to make it consistent |
|
| 328 | - * |
|
| 329 | - * @param type $cr Not sure what this is used for? |
|
| 330 | - * @param string $header The header |
|
| 331 | - * @return int The length of the header |
|
| 332 | - */ |
|
| 326 | + * Callback function to parse returned headers |
|
| 327 | + * - lowercases everything to make it consistent |
|
| 328 | + * |
|
| 329 | + * @param type $cr Not sure what this is used for? |
|
| 330 | + * @param string $header The header |
|
| 331 | + * @return int The length of the header |
|
| 332 | + */ |
|
| 333 | 333 | private function header_callback($cr, $header) |
| 334 | 334 | { |
| 335 | 335 | $_header = trim($header); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * Start the curl object |
| 98 | 98 | * - allow for user override values |
| 99 | 99 | * |
| 100 | - * @param array $options An array of cURL options |
|
| 100 | + * @param integer[] $options An array of cURL options |
|
| 101 | 101 | * @param int $max_redirect Maximum number of redirects |
| 102 | 102 | */ |
| 103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | * - calls set_options to set the curl opts array values based on the defaults and user input |
| 116 | 116 | * |
| 117 | 117 | * @param string $url the site we are going to fetch |
| 118 | - * @param array $post_data any post data as form name => value |
|
| 119 | - * @return object An instance of the curl_fetch_web_data class |
|
| 118 | + * @param string $post_data any post data as form name => value |
|
| 119 | + * @return curl_fetch_web_data An instance of the curl_fetch_web_data class |
|
| 120 | 120 | */ |
| 121 | 121 | public function get_url_data($url, $post_data = array()) |
| 122 | 122 | { |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @param string $url The site to fetch |
| 142 | 142 | * @param bool $redirect Whether or not this was a redirect request |
| 143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
| 143 | + * @return false|null Sets various properties of the class or returns false if the URL isn't specified |
|
| 144 | 144 | */ |
| 145 | 145 | private function curl_request($url, $redirect = false) |
| 146 | 146 | { |
@@ -10,8 +10,9 @@ discard block |
||
| 10 | 10 | * @version 2.1 Beta 4 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if (!defined('SMF')) |
|
| 13 | +if (!defined('SMF')) { |
|
| 14 | 14 | die('No direct access...'); |
| 15 | +} |
|
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * Class curl_fetch_web_data |
@@ -121,10 +122,11 @@ discard block |
||
| 121 | 122 | public function get_url_data($url, $post_data = array()) |
| 122 | 123 | { |
| 123 | 124 | // POSTing some data perhaps? |
| 124 | - if (!empty($post_data) && is_array($post_data)) |
|
| 125 | - $this->post_data = $this->build_post_data($post_data); |
|
| 126 | - elseif (!empty($post_data)) |
|
| 127 | - $this->post_data = trim($post_data); |
|
| 125 | + if (!empty($post_data) && is_array($post_data)) { |
|
| 126 | + $this->post_data = $this->build_post_data($post_data); |
|
| 127 | + } elseif (!empty($post_data)) { |
|
| 128 | + $this->post_data = trim($post_data); |
|
| 129 | + } |
|
| 128 | 130 | |
| 129 | 131 | // set the options and get it |
| 130 | 132 | $this->set_options(); |
@@ -145,10 +147,11 @@ discard block |
||
| 145 | 147 | private function curl_request($url, $redirect = false) |
| 146 | 148 | { |
| 147 | 149 | // we do have a url I hope |
| 148 | - if ($url == '') |
|
| 149 | - return false; |
|
| 150 | - else |
|
| 151 | - $this->options[CURLOPT_URL] = $url; |
|
| 150 | + if ($url == '') { |
|
| 151 | + return false; |
|
| 152 | + } else { |
|
| 153 | + $this->options[CURLOPT_URL] = $url; |
|
| 154 | + } |
|
| 152 | 155 | |
| 153 | 156 | // if we have not already been redirected, set it up so we can if needed |
| 154 | 157 | if (!$redirect) |
@@ -228,10 +231,11 @@ discard block |
||
| 228 | 231 | $max_result = count($this->response) - 1; |
| 229 | 232 | |
| 230 | 233 | // just return a specifed area or the entire result? |
| 231 | - if ($area == '') |
|
| 232 | - return $this->response[$max_result]; |
|
| 233 | - else |
|
| 234 | - return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 234 | + if ($area == '') { |
|
| 235 | + return $this->response[$max_result]; |
|
| 236 | + } else { |
|
| 237 | + return isset($this->response[$max_result][$area]) ? $this->response[$max_result][$area] : $this->response[$max_result]; |
|
| 238 | + } |
|
| 235 | 239 | } |
| 236 | 240 | |
| 237 | 241 | /** |
@@ -244,9 +248,9 @@ discard block |
||
| 244 | 248 | */ |
| 245 | 249 | public function result_raw($response_number = '') |
| 246 | 250 | { |
| 247 | - if (!is_numeric($response_number)) |
|
| 248 | - return $this->response; |
|
| 249 | - else |
|
| 251 | + if (!is_numeric($response_number)) { |
|
| 252 | + return $this->response; |
|
| 253 | + } else |
|
| 250 | 254 | { |
| 251 | 255 | $response_number = min($response_number, count($this->response) - 1); |
| 252 | 256 | return $this->response[$response_number]; |
@@ -268,13 +272,14 @@ discard block |
||
| 268 | 272 | $postvars = array(); |
| 269 | 273 | |
| 270 | 274 | // build the post data, drop ones with leading @'s since those can be used to send files, we don't support that. |
| 271 | - foreach ($post_data as $name => $value) |
|
| 272 | - $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 275 | + foreach ($post_data as $name => $value) { |
|
| 276 | + $postvars[] = $name . '=' . urlencode($value[0] == '@' ? '' : $value); |
|
| 277 | + } |
|
| 273 | 278 | |
| 274 | 279 | return implode('&', $postvars); |
| 280 | + } else { |
|
| 281 | + return $post_data; |
|
| 275 | 282 | } |
| 276 | - else |
|
| 277 | - return $post_data; |
|
| 278 | 283 | |
| 279 | 284 | } |
| 280 | 285 | |
@@ -295,9 +300,9 @@ discard block |
||
| 295 | 300 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
| 296 | 301 | $vals = array_merge($this->default_options, $this->user_options); |
| 297 | 302 | $this->options = array_combine($keys, $vals); |
| 303 | + } else { |
|
| 304 | + $this->options = $this->default_options; |
|
| 298 | 305 | } |
| 299 | - else |
|
| 300 | - $this->options = $this->default_options; |
|
| 301 | 306 | |
| 302 | 307 | // POST data options, here we don't allow any overide |
| 303 | 308 | if (isset($this->post_data)) |
@@ -336,8 +341,9 @@ discard block |
||
| 336 | 341 | $temp = explode(': ', $_header, 2); |
| 337 | 342 | |
| 338 | 343 | // set proper headers only |
| 339 | - if (isset($temp[0]) && isset($temp[1])) |
|
| 340 | - $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 344 | + if (isset($temp[0]) && isset($temp[1])) { |
|
| 345 | + $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 346 | + } |
|
| 341 | 347 | |
| 342 | 348 | // return the length of what was passed unless you want a Failed writing header error ;) |
| 343 | 349 | return strlen($header); |
@@ -497,6 +497,7 @@ |
||
| 497 | 497 | * @param string $xml_format The format to use ('atom', 'rss', 'rss2' or empty for plain XML) |
| 498 | 498 | * @param array $forceCdataKeys A list of keys on which to force cdata wrapping (used by mods, maybe) |
| 499 | 499 | * @param array $nsKeys Key-value pairs of namespace prefixes to pass to cdata_parse() (used by mods, maybe) |
| 500 | + * @param string $tag |
|
| 500 | 501 | */ |
| 501 | 502 | function dumpTags($data, $i, $tag = null, $xml_format = '', $forceCdataKeys = array(), $nsKeys = array()) |
| 502 | 503 | { |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | { |
| 838 | 838 | uasort($loaded_attachments, function($a, $b) { |
| 839 | 839 | if ($a['filesize'] == $b['filesize']) |
| 840 | - return 0; |
|
| 840 | + return 0; |
|
| 841 | 841 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 842 | 842 | }); |
| 843 | 843 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | { |
| 1243 | 1243 | uasort($loaded_attachments, function($a, $b) { |
| 1244 | 1244 | if ($a['filesize'] == $b['filesize']) |
| 1245 | - return 0; |
|
| 1245 | + return 0; |
|
| 1246 | 1246 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 1247 | 1247 | }); |
| 1248 | 1248 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $smcFunc['db_free_result']($request); |
| 166 | 166 | |
| 167 | 167 | $feed_meta['title'] = ' - ' . strip_tags($board_info['name']); |
| 168 | - $feed_meta['source'] .= '?board=' . $board . '.0' ; |
|
| 168 | + $feed_meta['source'] .= '?board=' . $board . '.0'; |
|
| 169 | 169 | |
| 170 | 170 | $query_this_board = 'b.id_board = ' . $board; |
| 171 | 171 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | foreach ($xml_data as $item) |
| 391 | 391 | { |
| 392 | - $link = array_filter($item['content'], function ($e) { return ($e['tag'] == 'link'); }); |
|
| 392 | + $link = array_filter($item['content'], function($e) { return ($e['tag'] == 'link'); }); |
|
| 393 | 393 | $link = array_pop($link); |
| 394 | 394 | |
| 395 | 395 | echo ' |
@@ -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( |
@@ -229,7 +229,7 @@ |
||
| 229 | 229 | //In maintenance mode, only login is allowed and don't show OverlayDiv |
| 230 | 230 | echo ' |
| 231 | 231 | <ul class="floatleft welcome"> |
| 232 | - <li>', sprintf($txt['welcome_guest'], $txt['guest_title'], '', $scripturl. '?action=login', 'return true;'), '</li> |
|
| 232 | + <li>', sprintf($txt['welcome_guest'], $txt['guest_title'], '', $scripturl . '?action=login', 'return true;'), '</li> |
|
| 233 | 233 | </ul>'; |
| 234 | 234 | |
| 235 | 235 | if (!empty($modSettings['userLanguage']) && !empty($context['languages']) && count($context['languages']) > 1) |
@@ -72,9 +72,10 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | // Allow css/js files to be disable for this specific theme. |
| 74 | 74 | // Add the identifier as an array key. IE array('smf_script'); Some external files might not add identifiers, on those cases SMF uses its filename as reference. |
| 75 | - if (!isset($settings['disable_files'])) |
|
| 76 | - $settings['disable_files'] = array(); |
|
| 77 | -} |
|
| 75 | + if (!isset($settings['disable_files'])) { |
|
| 76 | + $settings['disable_files'] = array(); |
|
| 77 | + } |
|
| 78 | + } |
|
| 78 | 79 | |
| 79 | 80 | /** |
| 80 | 81 | * The main sub template above the content. |
@@ -111,8 +112,9 @@ discard block |
||
| 111 | 112 | echo ' |
| 112 | 113 | <meta'; |
| 113 | 114 | |
| 114 | - foreach ($meta_tag as $meta_key => $meta_value) |
|
| 115 | - echo ' ', $meta_key, '="', $meta_value, '"'; |
|
| 115 | + foreach ($meta_tag as $meta_key => $meta_value) { |
|
| 116 | + echo ' ', $meta_key, '="', $meta_value, '"'; |
|
| 117 | + } |
|
| 116 | 118 | |
| 117 | 119 | echo '>'; |
| 118 | 120 | } |
@@ -123,14 +125,16 @@ discard block |
||
| 123 | 125 | <meta name="theme-color" content="#557EA0">'; |
| 124 | 126 | |
| 125 | 127 | // Please don't index these Mr Robot. |
| 126 | - if (!empty($context['robot_no_index'])) |
|
| 127 | - echo ' |
|
| 128 | + if (!empty($context['robot_no_index'])) { |
|
| 129 | + echo ' |
|
| 128 | 130 | <meta name="robots" content="noindex">'; |
| 131 | + } |
|
| 129 | 132 | |
| 130 | 133 | // Present a canonical url for search engines to prevent duplicate content in their indices. |
| 131 | - if (!empty($context['canonical_url'])) |
|
| 132 | - echo ' |
|
| 134 | + if (!empty($context['canonical_url'])) { |
|
| 135 | + echo ' |
|
| 133 | 136 | <link rel="canonical" href="', $context['canonical_url'], '">'; |
| 137 | + } |
|
| 134 | 138 | |
| 135 | 139 | // Show all the relative links, such as help, search, contents, and the like. |
| 136 | 140 | echo ' |
@@ -139,10 +143,11 @@ discard block |
||
| 139 | 143 | <link rel="search" href="' . $scripturl . '?action=search">' : ''); |
| 140 | 144 | |
| 141 | 145 | // If RSS feeds are enabled, advertise the presence of one. |
| 142 | - if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged'])) |
|
| 143 | - echo ' |
|
| 146 | + if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged'])) { |
|
| 147 | + echo ' |
|
| 144 | 148 | <link rel="alternate feed" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?action=.xml;type=rss2', !empty($context['current_board']) ? ';board=' . $context['current_board'] : '', '"> |
| 145 | 149 | <link rel="alternate feed" type="application/atom+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['atom'], '" href="', $scripturl, '?action=.xml;type=atom', !empty($context['current_board']) ? ';board=' . $context['current_board'] : '', '">'; |
| 150 | + } |
|
| 146 | 151 | |
| 147 | 152 | // If we're viewing a topic, these should be the previous and next topics, respectively. |
| 148 | 153 | if (!empty($context['links']['next'])) |
@@ -158,9 +163,10 @@ discard block |
||
| 158 | 163 | } |
| 159 | 164 | |
| 160 | 165 | // If we're in a board, or a topic for that matter, the index will be the board's index. |
| 161 | - if (!empty($context['current_board'])) |
|
| 162 | - echo ' |
|
| 166 | + if (!empty($context['current_board'])) { |
|
| 167 | + echo ' |
|
| 163 | 168 | <link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0">'; |
| 169 | + } |
|
| 164 | 170 | |
| 165 | 171 | // Output any remaining HTML headers. (from mods, maybe?) |
| 166 | 172 | echo $context['html_headers']; |
@@ -191,8 +197,9 @@ discard block |
||
| 191 | 197 | <ul class="floatleft" id="top_info"> |
| 192 | 198 | <li> |
| 193 | 199 | <a href="', $scripturl, '?action=profile"', !empty($context['self_profile']) ? ' class="active"' : '', ' id="profile_menu_top" onclick="return false;">'; |
| 194 | - if (!empty($context['user']['avatar'])) |
|
| 195 | - echo $context['user']['avatar']['image']; |
|
| 200 | + if (!empty($context['user']['avatar'])) { |
|
| 201 | + echo $context['user']['avatar']['image']; |
|
| 202 | + } |
|
| 196 | 203 | echo $context['user']['name'], '</a> |
| 197 | 204 | <div id="profile_menu" class="top_menu"></div> |
| 198 | 205 | </li>'; |
@@ -220,17 +227,18 @@ discard block |
||
| 220 | 227 | } |
| 221 | 228 | // Otherwise they're a guest. Ask them to either register or login. |
| 222 | 229 | else |
| 223 | - if (empty($maintenance)) |
|
| 224 | - echo ' |
|
| 230 | + if (empty($maintenance)) { |
|
| 231 | + echo ' |
|
| 225 | 232 | <ul class="floatleft welcome"> |
| 226 | 233 | <li>', sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup'), '</li> |
| 227 | 234 | </ul>'; |
| 228 | - else |
|
| 229 | - //In maintenance mode, only login is allowed and don't show OverlayDiv |
|
| 235 | + } else { |
|
| 236 | + //In maintenance mode, only login is allowed and don't show OverlayDiv |
|
| 230 | 237 | echo ' |
| 231 | 238 | <ul class="floatleft welcome"> |
| 232 | 239 | <li>', sprintf($txt['welcome_guest'], $txt['guest_title'], '', $scripturl. '?action=login', 'return true;'), '</li> |
| 233 | 240 | </ul>'; |
| 241 | + } |
|
| 234 | 242 | |
| 235 | 243 | if (!empty($modSettings['userLanguage']) && !empty($context['languages']) && count($context['languages']) > 1) |
| 236 | 244 | { |
@@ -238,9 +246,10 @@ discard block |
||
| 238 | 246 | <form id="languages_form" method="get" class="floatright"> |
| 239 | 247 | <select id="language_select" name="language" onchange="this.form.submit()">'; |
| 240 | 248 | |
| 241 | - foreach ($context['languages'] as $language) |
|
| 242 | - echo ' |
|
| 249 | + foreach ($context['languages'] as $language) { |
|
| 250 | + echo ' |
|
| 243 | 251 | <option value="', $language['filename'], '"', isset($context['user']['language']) && $context['user']['language'] == $language['filename'] ? ' selected="selected"' : '', '>', str_replace('-utf8', '', $language['name']), '</option>'; |
| 252 | + } |
|
| 244 | 253 | |
| 245 | 254 | echo ' |
| 246 | 255 | </select> |
@@ -264,31 +273,36 @@ discard block |
||
| 264 | 273 | <option value="all"', ($selected == 'all' ? ' selected' : ''), '>', $txt['search_entireforum'], ' </option>'; |
| 265 | 274 | |
| 266 | 275 | // Can't limit it to a specific topic if we are not in one |
| 267 | - if (!empty($context['current_topic'])) |
|
| 268 | - echo ' |
|
| 276 | + if (!empty($context['current_topic'])) { |
|
| 277 | + echo ' |
|
| 269 | 278 | <option value="topic"', ($selected == 'current_topic' ? ' selected' : ''), '>', $txt['search_thistopic'], '</option>'; |
| 279 | + } |
|
| 270 | 280 | |
| 271 | 281 | // Can't limit it to a specific board if we are not in one |
| 272 | - if (!empty($context['current_board'])) |
|
| 273 | - echo ' |
|
| 282 | + if (!empty($context['current_board'])) { |
|
| 283 | + echo ' |
|
| 274 | 284 | <option value="board"', ($selected == 'current_board' ? ' selected' : ''), '>', $txt['search_thisbrd'], '</option>'; |
| 285 | + } |
|
| 275 | 286 | |
| 276 | 287 | // Can't search for members if we can't see the memberlist |
| 277 | - if (!empty($context['allow_memberlist'])) |
|
| 278 | - echo ' |
|
| 288 | + if (!empty($context['allow_memberlist'])) { |
|
| 289 | + echo ' |
|
| 279 | 290 | <option value="members"', ($selected == 'members' ? ' selected' : ''), '>', $txt['search_members'], ' </option>'; |
| 291 | + } |
|
| 280 | 292 | |
| 281 | 293 | echo ' |
| 282 | 294 | </select>'; |
| 283 | 295 | |
| 284 | 296 | // Search within current topic? |
| 285 | - if (!empty($context['current_topic'])) |
|
| 286 | - echo ' |
|
| 297 | + if (!empty($context['current_topic'])) { |
|
| 298 | + echo ' |
|
| 287 | 299 | <input type="hidden" name="sd_topic" value="', $context['current_topic'], '">'; |
| 300 | + } |
|
| 288 | 301 | // If we're on a certain board, limit it to this board ;). |
| 289 | - elseif (!empty($context['current_board'])) |
|
| 290 | - echo ' |
|
| 302 | + elseif (!empty($context['current_board'])) { |
|
| 303 | + echo ' |
|
| 291 | 304 | <input type="hidden" name="sd_brd" value="', $context['current_board'], '">'; |
| 305 | + } |
|
| 292 | 306 | |
| 293 | 307 | echo ' |
| 294 | 308 | <input type="submit" name="search2" value="', $txt['search'], '" class="button_submit"> |
@@ -318,12 +332,13 @@ discard block |
||
| 318 | 332 | ', $context['current_time'], ' |
| 319 | 333 | </div>'; |
| 320 | 334 | // Show a random news item? (or you could pick one from news_lines...) |
| 321 | - if (!empty($settings['enable_news']) && !empty($context['random_news_line'])) |
|
| 322 | - echo ' |
|
| 335 | + if (!empty($settings['enable_news']) && !empty($context['random_news_line'])) { |
|
| 336 | + echo ' |
|
| 323 | 337 | <div class="news"> |
| 324 | 338 | <h2>', $txt['news'], ': </h2> |
| 325 | 339 | <p>', $context['random_news_line'], '</p> |
| 326 | 340 | </div>'; |
| 341 | + } |
|
| 327 | 342 | |
| 328 | 343 | echo ' |
| 329 | 344 | <hr class="clear"> |
@@ -386,9 +401,10 @@ discard block |
||
| 386 | 401 | </ul>'; |
| 387 | 402 | |
| 388 | 403 | // Show the load time? |
| 389 | - if ($context['show_load_time']) |
|
| 390 | - echo ' |
|
| 404 | + if ($context['show_load_time']) { |
|
| 405 | + echo ' |
|
| 391 | 406 | <p>', sprintf($txt['page_created_full'], $context['load_time'], $context['load_queries']), '</p>'; |
| 407 | + } |
|
| 392 | 408 | |
| 393 | 409 | echo ' |
| 394 | 410 | </div>'; |
@@ -418,19 +434,21 @@ discard block |
||
| 418 | 434 | global $context, $shown_linktree, $scripturl, $txt; |
| 419 | 435 | |
| 420 | 436 | // If linktree is empty, just return - also allow an override. |
| 421 | - if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show)) |
|
| 422 | - return; |
|
| 437 | + if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show)) { |
|
| 438 | + return; |
|
| 439 | + } |
|
| 423 | 440 | |
| 424 | 441 | echo ' |
| 425 | 442 | <div class="navigate_section"> |
| 426 | 443 | <ul>'; |
| 427 | 444 | |
| 428 | - if ($context['user']['is_logged']) |
|
| 429 | - echo ' |
|
| 445 | + if ($context['user']['is_logged']) { |
|
| 446 | + echo ' |
|
| 430 | 447 | <li class="unread_links"> |
| 431 | 448 | <a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a> |
| 432 | 449 | <a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a> |
| 433 | 450 | </li>'; |
| 451 | + } |
|
| 434 | 452 | |
| 435 | 453 | // Each tree item has a URL and name. Some may have extra_before and extra_after. |
| 436 | 454 | foreach ($context['linktree'] as $link_num => $tree) |
@@ -441,25 +459,29 @@ discard block |
||
| 441 | 459 | // Don't show a separator for the first one. |
| 442 | 460 | // Better here. Always points to the next level when the linktree breaks to a second line. |
| 443 | 461 | // Picked a better looking HTML entity, and added support for RTL plus a span for styling. |
| 444 | - if ($link_num != 0) |
|
| 445 | - echo ' |
|
| 462 | + if ($link_num != 0) { |
|
| 463 | + echo ' |
|
| 446 | 464 | <span class="dividers">', $context['right_to_left'] ? ' ◄ ' : ' ► ', '</span>'; |
| 465 | + } |
|
| 447 | 466 | |
| 448 | 467 | // Show something before the link? |
| 449 | - if (isset($tree['extra_before'])) |
|
| 450 | - echo $tree['extra_before'], ' '; |
|
| 468 | + if (isset($tree['extra_before'])) { |
|
| 469 | + echo $tree['extra_before'], ' '; |
|
| 470 | + } |
|
| 451 | 471 | |
| 452 | 472 | // Show the link, including a URL if it should have one. |
| 453 | - if (isset($tree['url'])) |
|
| 454 | - echo ' |
|
| 473 | + if (isset($tree['url'])) { |
|
| 474 | + echo ' |
|
| 455 | 475 | <a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>'; |
| 456 | - else |
|
| 457 | - echo ' |
|
| 476 | + } else { |
|
| 477 | + echo ' |
|
| 458 | 478 | <span>' . $tree['name'] . '</span>'; |
| 479 | + } |
|
| 459 | 480 | |
| 460 | 481 | // Show something after the link...? |
| 461 | - if (isset($tree['extra_after'])) |
|
| 462 | - echo ' ', $tree['extra_after']; |
|
| 482 | + if (isset($tree['extra_after'])) { |
|
| 483 | + echo ' ', $tree['extra_after']; |
|
| 484 | + } |
|
| 463 | 485 | |
| 464 | 486 | echo ' |
| 465 | 487 | </li>'; |
@@ -509,13 +531,14 @@ discard block |
||
| 509 | 531 | echo ' |
| 510 | 532 | <ul>'; |
| 511 | 533 | |
| 512 | - foreach ($childbutton['sub_buttons'] as $grandchildbutton) |
|
| 513 | - echo ' |
|
| 534 | + foreach ($childbutton['sub_buttons'] as $grandchildbutton) { |
|
| 535 | + echo ' |
|
| 514 | 536 | <li> |
| 515 | 537 | <a href="', $grandchildbutton['href'], '"', isset($grandchildbutton['target']) ? ' target="' . $grandchildbutton['target'] . '"' : '', '> |
| 516 | 538 | ', $grandchildbutton['title'], ' |
| 517 | 539 | </a> |
| 518 | 540 | </li>'; |
| 541 | + } |
|
| 519 | 542 | |
| 520 | 543 | echo ' |
| 521 | 544 | </ul>'; |
@@ -546,8 +569,9 @@ discard block |
||
| 546 | 569 | { |
| 547 | 570 | global $context, $txt; |
| 548 | 571 | |
| 549 | - if (!is_array($strip_options)) |
|
| 550 | - $strip_options = array(); |
|
| 572 | + if (!is_array($strip_options)) { |
|
| 573 | + $strip_options = array(); |
|
| 574 | + } |
|
| 551 | 575 | |
| 552 | 576 | // Create the buttons... |
| 553 | 577 | $buttons = array(); |
@@ -556,8 +580,9 @@ discard block |
||
| 556 | 580 | // As of 2.1, the 'test' for each button happens while the array is being generated. The extra 'test' check here is deprecated but kept for backward compatibility (update your mods, folks!) |
| 557 | 581 | if (!isset($value['test']) || !empty($context[$value['test']])) |
| 558 | 582 | { |
| 559 | - if (!isset($value['id'])) |
|
| 560 | - $value['id'] = $key; |
|
| 583 | + if (!isset($value['id'])) { |
|
| 584 | + $value['id'] = $key; |
|
| 585 | + } |
|
| 561 | 586 | |
| 562 | 587 | $button = ' |
| 563 | 588 | <a class="button button_strip_' . $key . (!empty($value['active']) ? ' active' : '') . (isset($value['class']) ? ' ' . $value['class'] : '') . '" ' . (!empty($value['url']) ? 'href="' . $value['url'] . '"' : '') . ' ' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '>' . $txt[$value['text']] . '</a>'; |
@@ -570,13 +595,15 @@ discard block |
||
| 570 | 595 | <div class="overview">'; |
| 571 | 596 | foreach ($value['sub_buttons'] as $element) |
| 572 | 597 | { |
| 573 | - if (isset($element['test']) && empty($context[$element['test']])) |
|
| 574 | - continue; |
|
| 598 | + if (isset($element['test']) && empty($context[$element['test']])) { |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 575 | 601 | |
| 576 | 602 | $button .= ' |
| 577 | 603 | <a href="' . $element['url'] . '"><strong>' . $txt[$element['text']] . '</strong>'; |
| 578 | - if (isset($txt[$element['text'] . '_desc'])) |
|
| 579 | - $button .= '<br /><span>' . $txt[$element['text'] . '_desc'] . '</span>'; |
|
| 604 | + if (isset($txt[$element['text'] . '_desc'])) { |
|
| 605 | + $button .= '<br /><span>' . $txt[$element['text'] . '_desc'] . '</span>'; |
|
| 606 | + } |
|
| 580 | 607 | $button .= '</a>'; |
| 581 | 608 | } |
| 582 | 609 | $button .= ' |
@@ -590,8 +617,9 @@ discard block |
||
| 590 | 617 | } |
| 591 | 618 | |
| 592 | 619 | // No buttons? No button strip either. |
| 593 | - if (empty($buttons)) |
|
| 594 | - return; |
|
| 620 | + if (empty($buttons)) { |
|
| 621 | + return; |
|
| 622 | + } |
|
| 595 | 623 | |
| 596 | 624 | echo ' |
| 597 | 625 | <div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"' : ''), '> |
@@ -1542,7 +1542,7 @@ discard block |
||
| 1542 | 1542 | 'no_msg' => 0, |
| 1543 | 1543 | 'substep' => $_GET['substep'], |
| 1544 | 1544 | 'ignore_ids' => $ignore_ids, |
| 1545 | - 'attach_thumb' => array(0,3), |
|
| 1545 | + 'attach_thumb' => array(0, 3), |
|
| 1546 | 1546 | ) |
| 1547 | 1547 | ); |
| 1548 | 1548 | |
@@ -1572,7 +1572,7 @@ discard block |
||
| 1572 | 1572 | array( |
| 1573 | 1573 | 'to_remove' => $to_remove, |
| 1574 | 1574 | 'no_member' => 0, |
| 1575 | - 'attach_thumb' => array(0,3), |
|
| 1575 | + 'attach_thumb' => array(0, 3), |
|
| 1576 | 1576 | ) |
| 1577 | 1577 | ); |
| 1578 | 1578 | |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 4 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * The main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
| 64 | 65 | |
| 65 | 66 | // Pick the correct sub-action. |
| 66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 68 | - else |
|
| 69 | - $context['sub_action'] = 'browse'; |
|
| 67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 69 | + } else { |
|
| 70 | + $context['sub_action'] = 'browse'; |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Default page title is good. |
| 72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
| 94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 95 | 97 | |
| 96 | 98 | // If not set, show a default path for the base directory |
| 97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
| 98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
| 100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
| 100 | - |
|
| 101 | - else |
|
| 102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 102 | + } else { |
|
| 103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
| 105 | 107 | |
| 106 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 108 | - |
|
| 109 | - else |
|
| 110 | - $context['valid_basedirectory'] = true; |
|
| 108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 110 | + } else { |
|
| 111 | + $context['valid_basedirectory'] = true; |
|
| 112 | + } |
|
| 111 | 113 | |
| 112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
| 113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
| 185 | 187 | |
| 186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
| 187 | 189 | |
| 188 | - if ($return_config) |
|
| 189 | - return $config_vars; |
|
| 190 | + if ($return_config) { |
|
| 191 | + return $config_vars; |
|
| 192 | + } |
|
| 190 | 193 | |
| 191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
| 192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
| 197 | 200 | { |
| 198 | 201 | checkSession(); |
| 199 | 202 | |
| 200 | - if (isset($_POST['attachmentUploadDir'])) |
|
| 201 | - unset($_POST['attachmentUploadDir']); |
|
| 203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
| 204 | + unset($_POST['attachmentUploadDir']); |
|
| 205 | + } |
|
| 202 | 206 | |
| 203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
| 204 | 208 | { |
| 205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
| 206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
| 210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 211 | + } |
|
| 207 | 212 | |
| 208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
| 209 | 214 | { |
| 210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 211 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 216 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 212 | 220 | } |
| 213 | - else |
|
| 214 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 215 | 221 | |
| 216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
| 217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
| 219 | 225 | |
| 220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
| 221 | 227 | { |
| 222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
| 223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
| 229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 230 | + } |
|
| 224 | 231 | } |
| 225 | 232 | |
| 226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
| 336 | 343 | |
| 337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
| 338 | 345 | |
| 339 | - if ($return_config) |
|
| 340 | - return $config_vars; |
|
| 346 | + if ($return_config) { |
|
| 347 | + return $config_vars; |
|
| 348 | + } |
|
| 341 | 349 | |
| 342 | 350 | // We need this file for the settings template. |
| 343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
| 348 | 356 | checkSession(); |
| 349 | 357 | |
| 350 | 358 | // These settings cannot be left empty! |
| 351 | - if (empty($_POST['custom_avatar_dir'])) |
|
| 352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
| 360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 361 | + } |
|
| 353 | 362 | |
| 354 | - if (empty($_POST['custom_avatar_url'])) |
|
| 355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 363 | + if (empty($_POST['custom_avatar_url'])) { |
|
| 364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 365 | + } |
|
| 356 | 366 | |
| 357 | - if (empty($_POST['avatar_directory'])) |
|
| 358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 367 | + if (empty($_POST['avatar_directory'])) { |
|
| 368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 369 | + } |
|
| 359 | 370 | |
| 360 | - if (empty($_POST['avatar_url'])) |
|
| 361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 371 | + if (empty($_POST['avatar_url'])) { |
|
| 372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 373 | + } |
|
| 362 | 374 | |
| 363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
| 364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
| 406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
| 407 | 419 | foreach ($titles as $browse_type => $details) |
| 408 | 420 | { |
| 409 | - if ($browse_type != 'attachments') |
|
| 410 | - $list_title .= ' | '; |
|
| 421 | + if ($browse_type != 'attachments') { |
|
| 422 | + $list_title .= ' | '; |
|
| 423 | + } |
|
| 411 | 424 | |
| 412 | - if ($context['browse_type'] == $browse_type) |
|
| 413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 425 | + if ($context['browse_type'] == $browse_type) { |
|
| 426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 427 | + } |
|
| 414 | 428 | |
| 415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
| 416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
| 446 | 460 | $link = '<a href="'; |
| 447 | 461 | |
| 448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
| 449 | - if ($rowData['attachment_type'] == 1) |
|
| 450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 463 | + if ($rowData['attachment_type'] == 1) { |
|
| 464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 465 | + } |
|
| 451 | 466 | |
| 452 | 467 | // By default avatars are downloaded almost as attachments. |
| 453 | - elseif ($context['browse_type'] == 'avatars') |
|
| 454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 468 | + elseif ($context['browse_type'] == 'avatars') { |
|
| 469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 470 | + } |
|
| 455 | 471 | |
| 456 | 472 | // Normal attachments are always linked to a topic ID. |
| 457 | - else |
|
| 458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 473 | + else { |
|
| 474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 475 | + } |
|
| 459 | 476 | |
| 460 | 477 | $link .= '"'; |
| 461 | 478 | |
| 462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
| 463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 482 | + } |
|
| 465 | 483 | |
| 466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
| 467 | 485 | |
| 468 | 486 | // Show the dimensions. |
| 469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 489 | + } |
|
| 471 | 490 | |
| 472 | 491 | return $link; |
| 473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
| 500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
| 501 | 520 | { |
| 502 | 521 | // In case of an attachment, return the poster of the attachment. |
| 503 | - if (empty($rowData['id_member'])) |
|
| 504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 522 | + if (empty($rowData['id_member'])) { |
|
| 523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 524 | + } |
|
| 505 | 525 | |
| 506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
| 507 | - else |
|
| 508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 527 | + else { |
|
| 528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 529 | + } |
|
| 509 | 530 | }, |
| 510 | 531 | ), |
| 511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
| 524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
| 525 | 546 | |
| 526 | 547 | // Add a link to the topic in case of an attachment. |
| 527 | - if ($context['browse_type'] !== 'avatars') |
|
| 528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 548 | + if ($context['browse_type'] !== 'avatars') { |
|
| 549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 550 | + } |
|
| 529 | 551 | |
| 530 | 552 | return $date; |
| 531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
| 610 | 632 | global $smcFunc, $txt; |
| 611 | 633 | |
| 612 | 634 | // Choose a query depending on what we are viewing. |
| 613 | - if ($browse_type === 'avatars') |
|
| 614 | - $request = $smcFunc['db_query']('', ' |
|
| 635 | + if ($browse_type === 'avatars') { |
|
| 636 | + $request = $smcFunc['db_query']('', ' |
|
| 615 | 637 | SELECT |
| 616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
| 617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
| 630 | 652 | 'per_page' => $items_per_page, |
| 631 | 653 | ) |
| 632 | 654 | ); |
| 633 | - else |
|
| 634 | - $request = $smcFunc['db_query']('', ' |
|
| 655 | + } else { |
|
| 656 | + $request = $smcFunc['db_query']('', ' |
|
| 635 | 657 | SELECT |
| 636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
| 637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
| 650 | 672 | 'per_page' => $items_per_page, |
| 651 | 673 | ) |
| 652 | 674 | ); |
| 675 | + } |
|
| 653 | 676 | $files = array(); |
| 654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 655 | - $files[] = $row; |
|
| 677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 678 | + $files[] = $row; |
|
| 679 | + } |
|
| 656 | 680 | $smcFunc['db_free_result']($request); |
| 657 | 681 | |
| 658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
| 670 | 694 | global $smcFunc; |
| 671 | 695 | |
| 672 | 696 | // Depending on the type of file, different queries are used. |
| 673 | - if ($browse_type === 'avatars') |
|
| 674 | - $request = $smcFunc['db_query']('', ' |
|
| 697 | + if ($browse_type === 'avatars') { |
|
| 698 | + $request = $smcFunc['db_query']('', ' |
|
| 675 | 699 | SELECT COUNT(*) |
| 676 | 700 | FROM {db_prefix}attachments |
| 677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
| 679 | 703 | 'guest_id_member' => 0, |
| 680 | 704 | ) |
| 681 | 705 | ); |
| 682 | - else |
|
| 683 | - $request = $smcFunc['db_query']('', ' |
|
| 706 | + } else { |
|
| 707 | + $request = $smcFunc['db_query']('', ' |
|
| 684 | 708 | SELECT COUNT(*) AS num_attach |
| 685 | 709 | FROM {db_prefix}attachments AS a |
| 686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
| 693 | 717 | 'guest_id_member' => 0, |
| 694 | 718 | ) |
| 695 | 719 | ); |
| 720 | + } |
|
| 696 | 721 | |
| 697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
| 698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
| 775 | 800 | $current_dir_size /= 1024; |
| 776 | 801 | |
| 777 | 802 | // If they specified a limit only.... |
| 778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
| 779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
| 804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 805 | + } |
|
| 780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
| 781 | 807 | |
| 782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
| 783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
| 809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 810 | + } |
|
| 784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
| 785 | 812 | |
| 786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
| 817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
| 818 | 845 | |
| 819 | 846 | // Update the messages to reflect the change. |
| 820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 821 | - $smcFunc['db_query']('', ' |
|
| 847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 848 | + $smcFunc['db_query']('', ' |
|
| 822 | 849 | UPDATE {db_prefix}messages |
| 823 | 850 | SET body = CONCAT(body, {string:notice}) |
| 824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
| 827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
| 828 | 855 | ) |
| 829 | 856 | ); |
| 830 | - } |
|
| 831 | - else |
|
| 857 | + } |
|
| 858 | + } else |
|
| 832 | 859 | { |
| 833 | 860 | // Remove all the old avatars. |
| 834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
| 853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
| 854 | 881 | |
| 855 | 882 | // And make a note on the post. |
| 856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 857 | - $smcFunc['db_query']('', ' |
|
| 883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 884 | + $smcFunc['db_query']('', ' |
|
| 858 | 885 | UPDATE {db_prefix}messages |
| 859 | 886 | SET body = CONCAT(body, {string:notice}) |
| 860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
| 863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
| 864 | 891 | ) |
| 865 | 892 | ); |
| 893 | + } |
|
| 866 | 894 | |
| 867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | $attachments = array(); |
| 884 | 912 | // There must be a quicker way to pass this safety test?? |
| 885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
| 886 | - $attachments[] = (int) $removeID; |
|
| 913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
| 914 | + $attachments[] = (int) $removeID; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
| 889 | 918 | $filesRemoved = false; |
| 890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
| 891 | 920 | |
| 892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
| 893 | - removeAttachments(array('id_attach' => $attachments)); |
|
| 894 | - else if (!empty($attachments)) |
|
| 921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
| 922 | + removeAttachments(array('id_attach' => $attachments)); |
|
| 923 | + } else if (!empty($attachments)) |
|
| 895 | 924 | { |
| 896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
| 897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
| 930 | 959 | |
| 931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
| 932 | 961 | |
| 933 | - if (!isset($_POST['notice'])) |
|
| 934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 962 | + if (!isset($_POST['notice'])) { |
|
| 963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 964 | + } |
|
| 935 | 965 | |
| 936 | 966 | // Add the notice on the end of the changed messages. |
| 937 | - if (!empty($messages)) |
|
| 938 | - $smcFunc['db_query']('', ' |
|
| 967 | + if (!empty($messages)) { |
|
| 968 | + $smcFunc['db_query']('', ' |
|
| 939 | 969 | UPDATE {db_prefix}messages |
| 940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
| 941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
| 944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
| 945 | 975 | ) |
| 946 | 976 | ); |
| 977 | + } |
|
| 947 | 978 | |
| 948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
| 982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
| 983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
| 984 | 1015 | |
| 985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
| 986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 987 | - elseif ($type == 'attachment_type') |
|
| 988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 989 | - elseif ($type == 'poster_time') |
|
| 990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 991 | - elseif ($type == 'last_login') |
|
| 992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 993 | - elseif ($type == 'size') |
|
| 994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 995 | - elseif ($type == 'id_topic') |
|
| 996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
| 1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1018 | + } elseif ($type == 'attachment_type') { |
|
| 1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 1020 | + } elseif ($type == 'poster_time') { |
|
| 1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 1022 | + } elseif ($type == 'last_login') { |
|
| 1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 1024 | + } elseif ($type == 'size') { |
|
| 1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 1026 | + } elseif ($type == 'id_topic') { |
|
| 1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1028 | + } |
|
| 997 | 1029 | |
| 998 | 1030 | // Add the parameter! |
| 999 | 1031 | $query_parameter[$real_type] = $restriction; |
| 1000 | 1032 | |
| 1001 | - if ($type == 'do_logging') |
|
| 1002 | - $do_logging = $condition['id_attach']; |
|
| 1033 | + if ($type == 'do_logging') { |
|
| 1034 | + $do_logging = $condition['id_attach']; |
|
| 1035 | + } |
|
| 1003 | 1036 | } |
| 1004 | 1037 | $condition = implode(' AND ', $new_condition); |
| 1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
| 1031 | 1064 | // wasn't it obvious? :P |
| 1032 | 1065 | // @todo look again at this. |
| 1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
| 1034 | - } |
|
| 1035 | - else |
|
| 1067 | + } else |
|
| 1036 | 1068 | { |
| 1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
| 1038 | 1070 | @unlink($filename); |
| 1039 | 1071 | |
| 1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
| 1041 | - if (!empty($row['id_parent'])) |
|
| 1042 | - $parents[] = $row['id_parent']; |
|
| 1073 | + if (!empty($row['id_parent'])) { |
|
| 1074 | + $parents[] = $row['id_parent']; |
|
| 1075 | + } |
|
| 1043 | 1076 | |
| 1044 | 1077 | // If this attachments has a thumb, remove it as well. |
| 1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
| 1051 | 1084 | } |
| 1052 | 1085 | |
| 1053 | 1086 | // Make a list. |
| 1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
| 1055 | - $msgs[] = $row['id_msg']; |
|
| 1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
| 1088 | + $msgs[] = $row['id_msg']; |
|
| 1089 | + } |
|
| 1056 | 1090 | |
| 1057 | 1091 | $attach[] = $row['id_attach']; |
| 1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
| 1060 | 1094 | |
| 1061 | 1095 | // Removed attachments don't have to be updated anymore. |
| 1062 | 1096 | $parents = array_diff($parents, $attach); |
| 1063 | - if (!empty($parents)) |
|
| 1064 | - $smcFunc['db_query']('', ' |
|
| 1097 | + if (!empty($parents)) { |
|
| 1098 | + $smcFunc['db_query']('', ' |
|
| 1065 | 1099 | UPDATE {db_prefix}attachments |
| 1066 | 1100 | SET id_thumb = {int:no_thumb} |
| 1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
| 1070 | 1104 | 'no_thumb' => 0, |
| 1071 | 1105 | ) |
| 1072 | 1106 | ); |
| 1107 | + } |
|
| 1073 | 1108 | |
| 1074 | 1109 | if (!empty($do_logging)) |
| 1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
| 1086 | 1121 | ) |
| 1087 | 1122 | ); |
| 1088 | 1123 | |
| 1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1090 | - logAction( |
|
| 1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1125 | + logAction( |
|
| 1091 | 1126 | 'remove_attach', |
| 1092 | 1127 | array( |
| 1093 | 1128 | 'message' => $row['id_msg'], |
| 1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1095 | 1130 | ) |
| 1096 | 1131 | ); |
| 1132 | + } |
|
| 1097 | 1133 | $smcFunc['db_free_result']($request); |
| 1098 | 1134 | } |
| 1099 | 1135 | |
| 1100 | - if (!empty($attach)) |
|
| 1101 | - $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($attach)) { |
|
| 1137 | + $smcFunc['db_query']('', ' |
|
| 1102 | 1138 | DELETE FROM {db_prefix}attachments |
| 1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
| 1104 | 1140 | array( |
| 1105 | 1141 | 'attachment_list' => $attach, |
| 1106 | 1142 | ) |
| 1107 | 1143 | ); |
| 1144 | + } |
|
| 1108 | 1145 | |
| 1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
| 1110 | 1147 | |
| 1111 | - if ($return_affected_messages) |
|
| 1112 | - return array_unique($msgs); |
|
| 1113 | -} |
|
| 1148 | + if ($return_affected_messages) { |
|
| 1149 | + return array_unique($msgs); |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1114 | 1152 | |
| 1115 | 1153 | /** |
| 1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
| 1122 | 1160 | checkSession('get'); |
| 1123 | 1161 | |
| 1124 | 1162 | // If we choose cancel, redirect right back. |
| 1125 | - if (isset($_POST['cancel'])) |
|
| 1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1163 | + if (isset($_POST['cancel'])) { |
|
| 1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1165 | + } |
|
| 1127 | 1166 | |
| 1128 | 1167 | // Try give us a while to sort this out... |
| 1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
| 1140 | 1179 | if (isset($_GET['fixErrors'])) |
| 1141 | 1180 | { |
| 1142 | 1181 | // Nothing? |
| 1143 | - if (empty($_POST['to_fix'])) |
|
| 1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1182 | + if (empty($_POST['to_fix'])) { |
|
| 1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1184 | + } |
|
| 1145 | 1185 | |
| 1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
| 1147 | 1187 | // @todo No need to do this I think. |
| 1148 | - foreach ($_POST['to_fix'] as $value) |
|
| 1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
| 1188 | + foreach ($_POST['to_fix'] as $value) { |
|
| 1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
| 1190 | + } |
|
| 1150 | 1191 | } |
| 1151 | 1192 | } |
| 1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
| 1213 | 1254 | } |
| 1214 | 1255 | } |
| 1215 | 1256 | } |
| 1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1259 | + } |
|
| 1218 | 1260 | $smcFunc['db_free_result']($result); |
| 1219 | 1261 | |
| 1220 | 1262 | // Do we need to delete what we have? |
| 1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
| 1222 | - $smcFunc['db_query']('', ' |
|
| 1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
| 1264 | + $smcFunc['db_query']('', ' |
|
| 1223 | 1265 | DELETE FROM {db_prefix}attachments |
| 1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
| 1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
| 1228 | 1270 | 'attachment_type' => 3, |
| 1229 | 1271 | ) |
| 1230 | 1272 | ); |
| 1273 | + } |
|
| 1231 | 1274 | |
| 1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
| 1272 | 1315 | $to_update[] = $row['id_attach']; |
| 1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
| 1274 | 1317 | } |
| 1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1320 | + } |
|
| 1277 | 1321 | $smcFunc['db_free_result']($result); |
| 1278 | 1322 | |
| 1279 | 1323 | // Do we need to delete what we have? |
| 1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
| 1281 | - $smcFunc['db_query']('', ' |
|
| 1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
| 1325 | + $smcFunc['db_query']('', ' |
|
| 1282 | 1326 | UPDATE {db_prefix}attachments |
| 1283 | 1327 | SET id_thumb = {int:no_thumb} |
| 1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
| 1287 | 1331 | 'no_thumb' => 0, |
| 1288 | 1332 | ) |
| 1289 | 1333 | ); |
| 1334 | + } |
|
| 1290 | 1335 | |
| 1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
| 1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1325 | 1370 | { |
| 1326 | 1371 | // Get the filename. |
| 1327 | - if ($row['attachment_type'] == 1) |
|
| 1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1329 | - else |
|
| 1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1372 | + if ($row['attachment_type'] == 1) { |
|
| 1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1374 | + } else { |
|
| 1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1376 | + } |
|
| 1331 | 1377 | |
| 1332 | 1378 | // File doesn't exist? |
| 1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
| 1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
| 1340 | 1386 | |
| 1341 | 1387 | // Loop through the other folders. |
| 1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
| 1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
| 1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
| 1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
| 1344 | 1390 | { |
| 1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
| 1392 | + } |
|
| 1346 | 1393 | $errors_found[] = 'wrong_folder'; |
| 1347 | 1394 | |
| 1348 | 1395 | // Are we going to fix this now? |
| 1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
| 1350 | - $smcFunc['db_query']('', ' |
|
| 1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
| 1397 | + $smcFunc['db_query']('', ' |
|
| 1351 | 1398 | UPDATE {db_prefix}attachments |
| 1352 | 1399 | SET id_folder = {int:new_folder} |
| 1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
| 1356 | 1403 | 'id_attach' => $row['id_attach'], |
| 1357 | 1404 | ) |
| 1358 | 1405 | ); |
| 1406 | + } |
|
| 1359 | 1407 | |
| 1360 | 1408 | continue 2; |
| 1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
| 1364 | 1412 | $to_remove[] = $row['id_attach']; |
| 1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
| 1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
| 1367 | - } |
|
| 1368 | - elseif (filesize($filename) == 0) |
|
| 1415 | + } elseif (filesize($filename) == 0) |
|
| 1369 | 1416 | { |
| 1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
| 1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
| 1376 | 1423 | $to_remove[] = $row['id_attach']; |
| 1377 | 1424 | @unlink($filename); |
| 1378 | 1425 | } |
| 1379 | - } |
|
| 1380 | - elseif (filesize($filename) != $row['size']) |
|
| 1426 | + } elseif (filesize($filename) != $row['size']) |
|
| 1381 | 1427 | { |
| 1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
| 1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
| 1398 | 1444 | } |
| 1399 | 1445 | } |
| 1400 | 1446 | |
| 1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
| 1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
| 1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
| 1404 | - $to_fix[] = 'file_size_of_zero'; |
|
| 1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
| 1406 | - $to_fix[] = 'file_wrong_size'; |
|
| 1407 | - if (in_array('wrong_folder', $errors_found)) |
|
| 1408 | - $to_fix[] = 'wrong_folder'; |
|
| 1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
| 1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
| 1449 | + } |
|
| 1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
| 1451 | + $to_fix[] = 'file_size_of_zero'; |
|
| 1452 | + } |
|
| 1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
| 1454 | + $to_fix[] = 'file_wrong_size'; |
|
| 1455 | + } |
|
| 1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
| 1457 | + $to_fix[] = 'wrong_folder'; |
|
| 1458 | + } |
|
| 1409 | 1459 | $smcFunc['db_free_result']($result); |
| 1410 | 1460 | |
| 1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
| 1475 | 1525 | // If we are repairing remove the file from disk now. |
| 1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
| 1477 | 1527 | { |
| 1478 | - if ($row['attachment_type'] == 1) |
|
| 1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1480 | - else |
|
| 1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1528 | + if ($row['attachment_type'] == 1) { |
|
| 1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1530 | + } else { |
|
| 1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1532 | + } |
|
| 1482 | 1533 | @unlink($filename); |
| 1483 | 1534 | } |
| 1484 | 1535 | } |
| 1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1486 | - $to_fix[] = 'avatar_no_member'; |
|
| 1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1537 | + $to_fix[] = 'avatar_no_member'; |
|
| 1538 | + } |
|
| 1487 | 1539 | $smcFunc['db_free_result']($result); |
| 1488 | 1540 | |
| 1489 | 1541 | // Do we need to delete what we have? |
| 1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
| 1491 | - $smcFunc['db_query']('', ' |
|
| 1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
| 1543 | + $smcFunc['db_query']('', ' |
|
| 1492 | 1544 | DELETE FROM {db_prefix}attachments |
| 1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
| 1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
| 1499 | 1551 | 'no_msg' => 0, |
| 1500 | 1552 | ) |
| 1501 | 1553 | ); |
| 1554 | + } |
|
| 1502 | 1555 | |
| 1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1504 | 1557 | } |
@@ -1558,13 +1611,14 @@ discard block |
||
| 1558 | 1611 | @unlink($filename); |
| 1559 | 1612 | } |
| 1560 | 1613 | } |
| 1561 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1562 | - $to_fix[] = 'attachment_no_msg'; |
|
| 1614 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1615 | + $to_fix[] = 'attachment_no_msg'; |
|
| 1616 | + } |
|
| 1563 | 1617 | $smcFunc['db_free_result']($result); |
| 1564 | 1618 | |
| 1565 | 1619 | // Do we need to delete what we have? |
| 1566 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
| 1567 | - $smcFunc['db_query']('', ' |
|
| 1620 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
| 1621 | + $smcFunc['db_query']('', ' |
|
| 1568 | 1622 | DELETE FROM {db_prefix}attachments |
| 1569 | 1623 | WHERE id_attach IN ({array_int:to_remove}) |
| 1570 | 1624 | AND id_member = {int:no_member} |
@@ -1575,6 +1629,7 @@ discard block |
||
| 1575 | 1629 | 'attach_thumb' => array(0,3), |
| 1576 | 1630 | ) |
| 1577 | 1631 | ); |
| 1632 | + } |
|
| 1578 | 1633 | |
| 1579 | 1634 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1580 | 1635 | } |
@@ -1598,8 +1653,9 @@ discard block |
||
| 1598 | 1653 | { |
| 1599 | 1654 | while ($file = readdir($dir)) |
| 1600 | 1655 | { |
| 1601 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 1602 | - continue; |
|
| 1656 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 1657 | + continue; |
|
| 1658 | + } |
|
| 1603 | 1659 | |
| 1604 | 1660 | if ($files_checked <= $current_check) |
| 1605 | 1661 | { |
@@ -1607,8 +1663,9 @@ discard block |
||
| 1607 | 1663 | if (strpos($file, 'post_tmp_') !== false) |
| 1608 | 1664 | { |
| 1609 | 1665 | // Temp file is more than 5 hours old! |
| 1610 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1611 | - @unlink($attach_dir . '/' . $file); |
|
| 1666 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1667 | + @unlink($attach_dir . '/' . $file); |
|
| 1668 | + } |
|
| 1612 | 1669 | } |
| 1613 | 1670 | // That should be an attachment, let's check if we have it in the database |
| 1614 | 1671 | elseif (strpos($file, '_') !== false) |
@@ -1630,8 +1687,7 @@ discard block |
||
| 1630 | 1687 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1631 | 1688 | { |
| 1632 | 1689 | @unlink($attach_dir . '/' . $file); |
| 1633 | - } |
|
| 1634 | - else |
|
| 1690 | + } else |
|
| 1635 | 1691 | { |
| 1636 | 1692 | $context['repair_errors']['files_without_attachment']++; |
| 1637 | 1693 | $to_fix[] = 'files_without_attachment'; |
@@ -1639,14 +1695,12 @@ discard block |
||
| 1639 | 1695 | } |
| 1640 | 1696 | $smcFunc['db_free_result']($request); |
| 1641 | 1697 | } |
| 1642 | - } |
|
| 1643 | - else |
|
| 1698 | + } else |
|
| 1644 | 1699 | { |
| 1645 | 1700 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1646 | 1701 | { |
| 1647 | 1702 | @unlink($attach_dir . '/' . $file); |
| 1648 | - } |
|
| 1649 | - else |
|
| 1703 | + } else |
|
| 1650 | 1704 | { |
| 1651 | 1705 | $context['repair_errors']['files_without_attachment']++; |
| 1652 | 1706 | $to_fix[] = 'files_without_attachment'; |
@@ -1655,8 +1709,9 @@ discard block |
||
| 1655 | 1709 | } |
| 1656 | 1710 | $current_check++; |
| 1657 | 1711 | $_GET['substep'] = $current_check; |
| 1658 | - if ($current_check - $files_checked >= $max_checks) |
|
| 1659 | - pauseAttachmentMaintenance($to_fix); |
|
| 1712 | + if ($current_check - $files_checked >= $max_checks) { |
|
| 1713 | + pauseAttachmentMaintenance($to_fix); |
|
| 1714 | + } |
|
| 1660 | 1715 | } |
| 1661 | 1716 | closedir($dir); |
| 1662 | 1717 | } |
@@ -1692,12 +1747,14 @@ discard block |
||
| 1692 | 1747 | |
| 1693 | 1748 | // Try get more time... |
| 1694 | 1749 | @set_time_limit(600); |
| 1695 | - if (function_exists('apache_reset_timeout')) |
|
| 1696 | - @apache_reset_timeout(); |
|
| 1750 | + if (function_exists('apache_reset_timeout')) { |
|
| 1751 | + @apache_reset_timeout(); |
|
| 1752 | + } |
|
| 1697 | 1753 | |
| 1698 | 1754 | // Have we already used our maximum time? |
| 1699 | - if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
| 1700 | - return; |
|
| 1755 | + if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
| 1756 | + return; |
|
| 1757 | + } |
|
| 1701 | 1758 | |
| 1702 | 1759 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1703 | 1760 | $context['page_title'] = $txt['not_done_title']; |
@@ -1709,10 +1766,11 @@ discard block |
||
| 1709 | 1766 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
| 1710 | 1767 | |
| 1711 | 1768 | // Change these two if more steps are added! |
| 1712 | - if (empty($max_substep)) |
|
| 1713 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1714 | - else |
|
| 1715 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1769 | + if (empty($max_substep)) { |
|
| 1770 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1771 | + } else { |
|
| 1772 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1773 | + } |
|
| 1716 | 1774 | |
| 1717 | 1775 | // Never more than 100%! |
| 1718 | 1776 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1754,15 +1812,17 @@ discard block |
||
| 1754 | 1812 | 'attachment_type' => 0, |
| 1755 | 1813 | ) |
| 1756 | 1814 | ); |
| 1757 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1758 | - $attachments[] = $row['id_attach']; |
|
| 1815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1816 | + $attachments[] = $row['id_attach']; |
|
| 1817 | + } |
|
| 1759 | 1818 | $smcFunc['db_free_result']($request); |
| 1819 | + } elseif (!empty($_GET['aid'])) { |
|
| 1820 | + $attachments[] = (int) $_GET['aid']; |
|
| 1760 | 1821 | } |
| 1761 | - elseif (!empty($_GET['aid'])) |
|
| 1762 | - $attachments[] = (int) $_GET['aid']; |
|
| 1763 | 1822 | |
| 1764 | - if (empty($attachments)) |
|
| 1765 | - fatal_lang_error('no_access', false); |
|
| 1823 | + if (empty($attachments)) { |
|
| 1824 | + fatal_lang_error('no_access', false); |
|
| 1825 | + } |
|
| 1766 | 1826 | |
| 1767 | 1827 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
| 1768 | 1828 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1795,17 +1855,18 @@ discard block |
||
| 1795 | 1855 | } |
| 1796 | 1856 | $smcFunc['db_free_result']($request); |
| 1797 | 1857 | |
| 1798 | - if (empty($attachments)) |
|
| 1799 | - fatal_lang_error('no_access', false); |
|
| 1858 | + if (empty($attachments)) { |
|
| 1859 | + fatal_lang_error('no_access', false); |
|
| 1860 | + } |
|
| 1800 | 1861 | |
| 1801 | 1862 | // Finally, we are there. Follow through! |
| 1802 | 1863 | if ($is_approve) |
| 1803 | 1864 | { |
| 1804 | 1865 | // Checked and deemed worthy. |
| 1805 | 1866 | ApproveAttachments($attachments); |
| 1867 | + } else { |
|
| 1868 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1806 | 1869 | } |
| 1807 | - else |
|
| 1808 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1809 | 1870 | |
| 1810 | 1871 | // Return to the topic.... |
| 1811 | 1872 | redirectexit($redirect); |
@@ -1821,8 +1882,9 @@ discard block |
||
| 1821 | 1882 | { |
| 1822 | 1883 | global $smcFunc; |
| 1823 | 1884 | |
| 1824 | - if (empty($attachments)) |
|
| 1825 | - return 0; |
|
| 1885 | + if (empty($attachments)) { |
|
| 1886 | + return 0; |
|
| 1887 | + } |
|
| 1826 | 1888 | |
| 1827 | 1889 | // For safety, check for thumbnails... |
| 1828 | 1890 | $request = $smcFunc['db_query']('', ' |
@@ -1841,15 +1903,17 @@ discard block |
||
| 1841 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1842 | 1904 | { |
| 1843 | 1905 | // Update the thumbnail too... |
| 1844 | - if (!empty($row['id_thumb'])) |
|
| 1845 | - $attachments[] = $row['id_thumb']; |
|
| 1906 | + if (!empty($row['id_thumb'])) { |
|
| 1907 | + $attachments[] = $row['id_thumb']; |
|
| 1908 | + } |
|
| 1846 | 1909 | |
| 1847 | 1910 | $attachments[] = $row['id_attach']; |
| 1848 | 1911 | } |
| 1849 | 1912 | $smcFunc['db_free_result']($request); |
| 1850 | 1913 | |
| 1851 | - if (empty($attachments)) |
|
| 1852 | - return 0; |
|
| 1914 | + if (empty($attachments)) { |
|
| 1915 | + return 0; |
|
| 1916 | + } |
|
| 1853 | 1917 | |
| 1854 | 1918 | // Approving an attachment is not hard - it's easy. |
| 1855 | 1919 | $smcFunc['db_query']('', ' |
@@ -1875,14 +1939,15 @@ discard block |
||
| 1875 | 1939 | ) |
| 1876 | 1940 | ); |
| 1877 | 1941 | |
| 1878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1879 | - logAction( |
|
| 1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1943 | + logAction( |
|
| 1880 | 1944 | 'approve_attach', |
| 1881 | 1945 | array( |
| 1882 | 1946 | 'message' => $row['id_msg'], |
| 1883 | 1947 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1884 | 1948 | ) |
| 1885 | 1949 | ); |
| 1950 | + } |
|
| 1886 | 1951 | $smcFunc['db_free_result']($request); |
| 1887 | 1952 | |
| 1888 | 1953 | // Remove from the approval queue. |
@@ -1905,11 +1970,11 @@ discard block |
||
| 1905 | 1970 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
| 1906 | 1971 | |
| 1907 | 1972 | // Since this needs to be done eventually. |
| 1908 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
| 1909 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 1910 | - |
|
| 1911 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
| 1912 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1973 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
| 1974 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 1975 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 1976 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1977 | + } |
|
| 1913 | 1978 | |
| 1914 | 1979 | $errors = array(); |
| 1915 | 1980 | |
@@ -1924,8 +1989,9 @@ discard block |
||
| 1924 | 1989 | { |
| 1925 | 1990 | $error = ''; |
| 1926 | 1991 | $id = (int) $id; |
| 1927 | - if ($id < 1) |
|
| 1928 | - continue; |
|
| 1992 | + if ($id < 1) { |
|
| 1993 | + continue; |
|
| 1994 | + } |
|
| 1929 | 1995 | |
| 1930 | 1996 | // Sorry, these dirs are NOT valid |
| 1931 | 1997 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1944,8 +2010,7 @@ discard block |
||
| 1944 | 2010 | { |
| 1945 | 2011 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
| 1946 | 2012 | continue; |
| 1947 | - } |
|
| 1948 | - elseif (empty($path)) |
|
| 2013 | + } elseif (empty($path)) |
|
| 1949 | 2014 | { |
| 1950 | 2015 | // Ignore this and set $id to one less |
| 1951 | 2016 | continue; |
@@ -1953,10 +2018,11 @@ discard block |
||
| 1953 | 2018 | |
| 1954 | 2019 | // OK, so let's try to create it then. |
| 1955 | 2020 | require_once($sourcedir . '/Subs-Attachments.php'); |
| 1956 | - if (automanage_attachments_create_directory($path)) |
|
| 1957 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 1958 | - else |
|
| 1959 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2021 | + if (automanage_attachments_create_directory($path)) { |
|
| 2022 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2023 | + } else { |
|
| 2024 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2025 | + } |
|
| 1960 | 2026 | } |
| 1961 | 2027 | |
| 1962 | 2028 | // Changing a directory name? |
@@ -1969,8 +2035,7 @@ discard block |
||
| 1969 | 2035 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
| 1970 | 2036 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1971 | 2037 | } |
| 1972 | - } |
|
| 1973 | - else |
|
| 2038 | + } else |
|
| 1974 | 2039 | { |
| 1975 | 2040 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
| 1976 | 2041 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1995,12 +2060,13 @@ discard block |
||
| 1995 | 2060 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1996 | 2061 | |
| 1997 | 2062 | // It's not a good idea to delete the current directory. |
| 1998 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
| 1999 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2063 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
| 2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2065 | + } |
|
| 2000 | 2066 | // Or the current base directory |
| 2001 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
| 2002 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2003 | - else |
|
| 2067 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
| 2068 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2069 | + } else |
|
| 2004 | 2070 | { |
| 2005 | 2071 | // Let's not try to delete a path with files in it. |
| 2006 | 2072 | $request = $smcFunc['db_query']('', ' |
@@ -2019,17 +2085,18 @@ discard block |
||
| 2019 | 2085 | if (!empty($modSettings['attachment_basedirectories'])) |
| 2020 | 2086 | { |
| 2021 | 2087 | // Count any sub-folders. |
| 2022 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
| 2023 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2088 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
| 2089 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2024 | 2090 | $num_attach++; |
| 2091 | + } |
|
| 2025 | 2092 | } |
| 2026 | 2093 | |
| 2027 | 2094 | // It's safe to delete. So try to delete the folder also |
| 2028 | 2095 | if ($num_attach == 0) |
| 2029 | 2096 | { |
| 2030 | - if (is_dir($path)) |
|
| 2031 | - $doit = true; |
|
| 2032 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2097 | + if (is_dir($path)) { |
|
| 2098 | + $doit = true; |
|
| 2099 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2033 | 2100 | { |
| 2034 | 2101 | $doit = true; |
| 2035 | 2102 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2039,8 +2106,9 @@ discard block |
||
| 2039 | 2106 | { |
| 2040 | 2107 | unlink($path . '/.htaccess'); |
| 2041 | 2108 | unlink($path . '/index.php'); |
| 2042 | - if (!@rmdir($path)) |
|
| 2043 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2109 | + if (!@rmdir($path)) { |
|
| 2110 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2111 | + } |
|
| 2044 | 2112 | } |
| 2045 | 2113 | |
| 2046 | 2114 | // Remove it from the base directory list. |
@@ -2050,14 +2118,15 @@ discard block |
||
| 2050 | 2118 | updateSettings(array('attachment_basedirectories' => json_encode($modSettings['attachment_basedirectories']))); |
| 2051 | 2119 | $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
| 2052 | 2120 | } |
| 2121 | + } else { |
|
| 2122 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2053 | 2123 | } |
| 2054 | - else |
|
| 2055 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2056 | 2124 | |
| 2057 | - if (empty($error)) |
|
| 2058 | - continue; |
|
| 2059 | - else |
|
| 2060 | - $errors[] = $error; |
|
| 2125 | + if (empty($error)) { |
|
| 2126 | + continue; |
|
| 2127 | + } else { |
|
| 2128 | + $errors[] = $error; |
|
| 2129 | + } |
|
| 2061 | 2130 | } |
| 2062 | 2131 | } |
| 2063 | 2132 | |
@@ -2065,23 +2134,26 @@ discard block |
||
| 2065 | 2134 | } |
| 2066 | 2135 | |
| 2067 | 2136 | // We need to make sure the current directory is right. |
| 2068 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
| 2069 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2137 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 2138 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2139 | + } |
|
| 2070 | 2140 | |
| 2071 | 2141 | // Find the current directory if there's no value carried, |
| 2072 | 2142 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
| 2073 | 2143 | { |
| 2074 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
| 2075 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2076 | - else |
|
| 2077 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2144 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
| 2145 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2146 | + } else { |
|
| 2147 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2148 | + } |
|
| 2078 | 2149 | } |
| 2079 | 2150 | |
| 2080 | 2151 | // If the user wishes to go back, update the last_dir array |
| 2081 | 2152 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
| 2082 | 2153 | { |
| 2083 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 2084 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2154 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 2155 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2156 | + } |
|
| 2085 | 2157 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
| 2086 | 2158 | |
| 2087 | 2159 | if (is_numeric($num)) |
@@ -2089,16 +2161,18 @@ discard block |
||
| 2089 | 2161 | // Need to find the base folder. |
| 2090 | 2162 | $bid = -1; |
| 2091 | 2163 | $use_subdirectories_for_attachments = 0; |
| 2092 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2093 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2164 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2165 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2094 | 2166 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
| 2095 | 2167 | { |
| 2096 | 2168 | $use_subdirectories_for_attachments = 1; |
| 2169 | + } |
|
| 2097 | 2170 | break; |
| 2098 | 2171 | } |
| 2099 | 2172 | |
| 2100 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
| 2101 | - $bid = 0; |
|
| 2173 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
| 2174 | + $bid = 0; |
|
| 2175 | + } |
|
| 2102 | 2176 | |
| 2103 | 2177 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
| 2104 | 2178 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2117,8 +2191,8 @@ discard block |
||
| 2117 | 2191 | // We might need to reset the paths. This loop will just loop through once. |
| 2118 | 2192 | foreach ($new_dirs as $id => $dir) |
| 2119 | 2193 | { |
| 2120 | - if ($id != 1) |
|
| 2121 | - $smcFunc['db_query']('', ' |
|
| 2194 | + if ($id != 1) { |
|
| 2195 | + $smcFunc['db_query']('', ' |
|
| 2122 | 2196 | UPDATE {db_prefix}attachments |
| 2123 | 2197 | SET id_folder = {int:default_folder} |
| 2124 | 2198 | WHERE id_folder = {int:current_folder}', |
@@ -2127,14 +2201,14 @@ discard block |
||
| 2127 | 2201 | 'current_folder' => $id, |
| 2128 | 2202 | ) |
| 2129 | 2203 | ); |
| 2204 | + } |
|
| 2130 | 2205 | |
| 2131 | 2206 | $update = array( |
| 2132 | 2207 | 'currentAttachmentUploadDir' => 1, |
| 2133 | 2208 | 'attachmentUploadDir' => json_encode(array(1 => $dir)), |
| 2134 | 2209 | ); |
| 2135 | 2210 | } |
| 2136 | - } |
|
| 2137 | - else |
|
| 2211 | + } else |
|
| 2138 | 2212 | { |
| 2139 | 2213 | // Save it to the database. |
| 2140 | 2214 | $update = array( |
@@ -2143,11 +2217,13 @@ discard block |
||
| 2143 | 2217 | ); |
| 2144 | 2218 | } |
| 2145 | 2219 | |
| 2146 | - if (!empty($update)) |
|
| 2147 | - updateSettings($update); |
|
| 2220 | + if (!empty($update)) { |
|
| 2221 | + updateSettings($update); |
|
| 2222 | + } |
|
| 2148 | 2223 | |
| 2149 | - if (!empty($errors)) |
|
| 2150 | - $_SESSION['errors']['dir'] = $errors; |
|
| 2224 | + if (!empty($errors)) { |
|
| 2225 | + $_SESSION['errors']['dir'] = $errors; |
|
| 2226 | + } |
|
| 2151 | 2227 | |
| 2152 | 2228 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2153 | 2229 | } |
@@ -2161,10 +2237,11 @@ discard block |
||
| 2161 | 2237 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
| 2162 | 2238 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
| 2163 | 2239 | { |
| 2164 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
| 2165 | - $update = (array( |
|
| 2240 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
| 2241 | + $update = (array( |
|
| 2166 | 2242 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
| 2167 | 2243 | )); |
| 2244 | + } |
|
| 2168 | 2245 | } |
| 2169 | 2246 | |
| 2170 | 2247 | if (isset($_POST['base_dir'])) |
@@ -2212,13 +2289,15 @@ discard block |
||
| 2212 | 2289 | |
| 2213 | 2290 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
| 2214 | 2291 | { |
| 2215 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
| 2216 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2292 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
| 2293 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2294 | + } |
|
| 2217 | 2295 | } |
| 2218 | 2296 | |
| 2219 | 2297 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
| 2220 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
| 2221 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2298 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
| 2299 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2300 | + } |
|
| 2222 | 2301 | ksort($modSettings['attachment_basedirectories']); |
| 2223 | 2302 | |
| 2224 | 2303 | $update = (array( |
@@ -2228,11 +2307,13 @@ discard block |
||
| 2228 | 2307 | )); |
| 2229 | 2308 | } |
| 2230 | 2309 | |
| 2231 | - if (!empty($errors)) |
|
| 2232 | - $_SESSION['errors']['base'] = $errors; |
|
| 2310 | + if (!empty($errors)) { |
|
| 2311 | + $_SESSION['errors']['base'] = $errors; |
|
| 2312 | + } |
|
| 2233 | 2313 | |
| 2234 | - if (!empty($update)) |
|
| 2235 | - updateSettings($update); |
|
| 2314 | + if (!empty($update)) { |
|
| 2315 | + updateSettings($update); |
|
| 2316 | + } |
|
| 2236 | 2317 | |
| 2237 | 2318 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2238 | 2319 | } |
@@ -2242,13 +2323,15 @@ discard block |
||
| 2242 | 2323 | if (is_array($_SESSION['errors'])) |
| 2243 | 2324 | { |
| 2244 | 2325 | $errors = array(); |
| 2245 | - if (!empty($_SESSION['errors']['dir'])) |
|
| 2246 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2326 | + if (!empty($_SESSION['errors']['dir'])) { |
|
| 2327 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2247 | 2328 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2329 | + } |
|
| 2248 | 2330 | |
| 2249 | - if (!empty($_SESSION['errors']['base'])) |
|
| 2250 | - foreach ($_SESSION['errors']['base'] as $error) |
|
| 2331 | + if (!empty($_SESSION['errors']['base'])) { |
|
| 2332 | + foreach ($_SESSION['errors']['base'] as $error) |
|
| 2251 | 2333 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2334 | + } |
|
| 2252 | 2335 | } |
| 2253 | 2336 | unset($_SESSION['errors']); |
| 2254 | 2337 | } |
@@ -2458,8 +2541,9 @@ discard block |
||
| 2458 | 2541 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
| 2459 | 2542 | { |
| 2460 | 2543 | // If there aren't any attachments in this directory this won't exist. |
| 2461 | - if (!isset($expected_files[$id])) |
|
| 2462 | - $expected_files[$id] = 0; |
|
| 2544 | + if (!isset($expected_files[$id])) { |
|
| 2545 | + $expected_files[$id] = 0; |
|
| 2546 | + } |
|
| 2463 | 2547 | |
| 2464 | 2548 | // Check if the directory is doing okay. |
| 2465 | 2549 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2472,10 +2556,11 @@ discard block |
||
| 2472 | 2556 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
| 2473 | 2557 | |
| 2474 | 2558 | // Count any sub-folders. |
| 2475 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2476 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2559 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2560 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2477 | 2561 | { |
| 2478 | 2562 | $expected_files[$id]++; |
| 2563 | + } |
|
| 2479 | 2564 | $sub_dirs++; |
| 2480 | 2565 | } |
| 2481 | 2566 | } |
@@ -2493,8 +2578,8 @@ discard block |
||
| 2493 | 2578 | } |
| 2494 | 2579 | |
| 2495 | 2580 | // Just stick a new directory on at the bottom. |
| 2496 | - if (isset($_REQUEST['new_path'])) |
|
| 2497 | - $attachdirs[] = array( |
|
| 2581 | + if (isset($_REQUEST['new_path'])) { |
|
| 2582 | + $attachdirs[] = array( |
|
| 2498 | 2583 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
| 2499 | 2584 | 'current' => false, |
| 2500 | 2585 | 'path' => '', |
@@ -2502,6 +2587,7 @@ discard block |
||
| 2502 | 2587 | 'num_files' => '', |
| 2503 | 2588 | 'status' => '', |
| 2504 | 2589 | ); |
| 2590 | + } |
|
| 2505 | 2591 | |
| 2506 | 2592 | return $attachdirs; |
| 2507 | 2593 | } |
@@ -2514,8 +2600,9 @@ discard block |
||
| 2514 | 2600 | { |
| 2515 | 2601 | global $modSettings, $txt; |
| 2516 | 2602 | |
| 2517 | - if (empty($modSettings['attachment_basedirectories'])) |
|
| 2518 | - return; |
|
| 2603 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
| 2604 | + return; |
|
| 2605 | + } |
|
| 2519 | 2606 | |
| 2520 | 2607 | $basedirs = array(); |
| 2521 | 2608 | // Get a list of the base directories. |
@@ -2523,16 +2610,18 @@ discard block |
||
| 2523 | 2610 | { |
| 2524 | 2611 | // Loop through the attach directory array to count any sub-directories |
| 2525 | 2612 | $expected_dirs = 0; |
| 2526 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2527 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2613 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2614 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2528 | 2615 | $expected_dirs++; |
| 2616 | + } |
|
| 2529 | 2617 | |
| 2530 | - if (!is_dir($dir)) |
|
| 2531 | - $status = 'does_not_exist'; |
|
| 2532 | - elseif (!is_writeable($dir)) |
|
| 2533 | - $status = 'not_writable'; |
|
| 2534 | - else |
|
| 2535 | - $status = 'ok'; |
|
| 2618 | + if (!is_dir($dir)) { |
|
| 2619 | + $status = 'does_not_exist'; |
|
| 2620 | + } elseif (!is_writeable($dir)) { |
|
| 2621 | + $status = 'not_writable'; |
|
| 2622 | + } else { |
|
| 2623 | + $status = 'ok'; |
|
| 2624 | + } |
|
| 2536 | 2625 | |
| 2537 | 2626 | $basedirs[] = array( |
| 2538 | 2627 | 'id' => $id, |
@@ -2543,14 +2632,15 @@ discard block |
||
| 2543 | 2632 | ); |
| 2544 | 2633 | } |
| 2545 | 2634 | |
| 2546 | - if (isset($_REQUEST['new_base_path'])) |
|
| 2547 | - $basedirs[] = array( |
|
| 2635 | + if (isset($_REQUEST['new_base_path'])) { |
|
| 2636 | + $basedirs[] = array( |
|
| 2548 | 2637 | 'id' => '', |
| 2549 | 2638 | 'current' => false, |
| 2550 | 2639 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
| 2551 | 2640 | 'num_dirs' => '', |
| 2552 | 2641 | 'status' => '', |
| 2553 | 2642 | ); |
| 2643 | + } |
|
| 2554 | 2644 | |
| 2555 | 2645 | return $basedirs; |
| 2556 | 2646 | } |
@@ -2566,10 +2656,11 @@ discard block |
||
| 2566 | 2656 | */ |
| 2567 | 2657 | function attachDirStatus($dir, $expected_files) |
| 2568 | 2658 | { |
| 2569 | - if (!is_dir($dir)) |
|
| 2570 | - return array('does_not_exist', true, ''); |
|
| 2571 | - elseif (!is_writable($dir)) |
|
| 2572 | - return array('not_writable', true, ''); |
|
| 2659 | + if (!is_dir($dir)) { |
|
| 2660 | + return array('does_not_exist', true, ''); |
|
| 2661 | + } elseif (!is_writable($dir)) { |
|
| 2662 | + return array('not_writable', true, ''); |
|
| 2663 | + } |
|
| 2573 | 2664 | |
| 2574 | 2665 | // Everything is okay so far, start to scan through the directory. |
| 2575 | 2666 | $num_files = 0; |
@@ -2577,22 +2668,26 @@ discard block |
||
| 2577 | 2668 | while ($file = $dir_handle->read()) |
| 2578 | 2669 | { |
| 2579 | 2670 | // Now do we have a real file here? |
| 2580 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 2581 | - continue; |
|
| 2671 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 2672 | + continue; |
|
| 2673 | + } |
|
| 2582 | 2674 | |
| 2583 | 2675 | $num_files++; |
| 2584 | 2676 | } |
| 2585 | 2677 | $dir_handle->close(); |
| 2586 | 2678 | |
| 2587 | - if ($num_files < $expected_files) |
|
| 2588 | - return array('files_missing', true, $num_files); |
|
| 2679 | + if ($num_files < $expected_files) { |
|
| 2680 | + return array('files_missing', true, $num_files); |
|
| 2681 | + } |
|
| 2589 | 2682 | // Empty? |
| 2590 | - elseif ($expected_files == 0) |
|
| 2591 | - return array('unused', false, $num_files); |
|
| 2683 | + elseif ($expected_files == 0) { |
|
| 2684 | + return array('unused', false, $num_files); |
|
| 2685 | + } |
|
| 2592 | 2686 | // All good! |
| 2593 | - else |
|
| 2594 | - return array('ok', false, $num_files); |
|
| 2595 | -} |
|
| 2687 | + else { |
|
| 2688 | + return array('ok', false, $num_files); |
|
| 2689 | + } |
|
| 2690 | + } |
|
| 2596 | 2691 | |
| 2597 | 2692 | /** |
| 2598 | 2693 | * Maintance function to move attachments from one directory to another |
@@ -2604,10 +2699,11 @@ discard block |
||
| 2604 | 2699 | checkSession(); |
| 2605 | 2700 | |
| 2606 | 2701 | $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
| 2607 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2608 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2609 | - else |
|
| 2610 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2702 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2703 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2704 | + } else { |
|
| 2705 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2706 | + } |
|
| 2611 | 2707 | |
| 2612 | 2708 | $_POST['from'] = (int) $_POST['from']; |
| 2613 | 2709 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2621,11 +2717,13 @@ discard block |
||
| 2621 | 2717 | $total_moved = 0; |
| 2622 | 2718 | $total_not_moved = 0; |
| 2623 | 2719 | |
| 2624 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
| 2625 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2720 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
| 2721 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2722 | + } |
|
| 2626 | 2723 | |
| 2627 | - if ($_POST['from'] == $_POST['to']) |
|
| 2628 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2724 | + if ($_POST['from'] == $_POST['to']) { |
|
| 2725 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2726 | + } |
|
| 2629 | 2727 | |
| 2630 | 2728 | if (empty($results)) |
| 2631 | 2729 | { |
@@ -2644,8 +2742,9 @@ discard block |
||
| 2644 | 2742 | $smcFunc['db_free_result']($request); |
| 2645 | 2743 | $total_progress -= $start; |
| 2646 | 2744 | |
| 2647 | - if ($total_progress < 1) |
|
| 2648 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2745 | + if ($total_progress < 1) { |
|
| 2746 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2747 | + } |
|
| 2649 | 2748 | } |
| 2650 | 2749 | |
| 2651 | 2750 | if (empty($results)) |
@@ -2661,9 +2760,9 @@ discard block |
||
| 2661 | 2760 | |
| 2662 | 2761 | automanage_attachments_check_directory(); |
| 2663 | 2762 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
| 2763 | + } else { |
|
| 2764 | + $new_dir = $_POST['to']; |
|
| 2664 | 2765 | } |
| 2665 | - else |
|
| 2666 | - $new_dir = $_POST['to']; |
|
| 2667 | 2766 | |
| 2668 | 2767 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
| 2669 | 2768 | |
@@ -2671,8 +2770,9 @@ discard block |
||
| 2671 | 2770 | while ($break == false) |
| 2672 | 2771 | { |
| 2673 | 2772 | @set_time_limit(300); |
| 2674 | - if (function_exists('apache_reset_timeout')) |
|
| 2675 | - @apache_reset_timeout(); |
|
| 2773 | + if (function_exists('apache_reset_timeout')) { |
|
| 2774 | + @apache_reset_timeout(); |
|
| 2775 | + } |
|
| 2676 | 2776 | |
| 2677 | 2777 | // If limits are set, get the file count and size for the destination folder |
| 2678 | 2778 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2708,13 +2808,15 @@ discard block |
||
| 2708 | 2808 | |
| 2709 | 2809 | if ($smcFunc['db_num_rows']($request) === 0) |
| 2710 | 2810 | { |
| 2711 | - if (empty($current_progress)) |
|
| 2712 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2811 | + if (empty($current_progress)) { |
|
| 2812 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2813 | + } |
|
| 2713 | 2814 | break; |
| 2714 | 2815 | } |
| 2715 | 2816 | |
| 2716 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
| 2717 | - $break = true; |
|
| 2817 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
| 2818 | + $break = true; |
|
| 2819 | + } |
|
| 2718 | 2820 | |
| 2719 | 2821 | // Move them |
| 2720 | 2822 | $moved = array(); |
@@ -2738,8 +2840,9 @@ discard block |
||
| 2738 | 2840 | automanage_attachments_by_space(); |
| 2739 | 2841 | |
| 2740 | 2842 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2741 | - if (!empty($total_not_moved)) |
|
| 2742 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2843 | + if (!empty($total_not_moved)) { |
|
| 2844 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2845 | + } |
|
| 2743 | 2846 | |
| 2744 | 2847 | $dir_files = 0; |
| 2745 | 2848 | $total_moved = 0; |
@@ -2747,8 +2850,7 @@ discard block |
||
| 2747 | 2850 | |
| 2748 | 2851 | $break = false; |
| 2749 | 2852 | break; |
| 2750 | - } |
|
| 2751 | - else |
|
| 2853 | + } else |
|
| 2752 | 2854 | { |
| 2753 | 2855 | // Hmm, not in auto. Time to bail out then... |
| 2754 | 2856 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2763,9 +2865,9 @@ discard block |
||
| 2763 | 2865 | $total_moved++; |
| 2764 | 2866 | $current_progress++; |
| 2765 | 2867 | $moved[] = $row['id_attach']; |
| 2868 | + } else { |
|
| 2869 | + $total_not_moved++; |
|
| 2766 | 2870 | } |
| 2767 | - else |
|
| 2768 | - $total_not_moved++; |
|
| 2769 | 2871 | } |
| 2770 | 2872 | $smcFunc['db_free_result']($request); |
| 2771 | 2873 | |
@@ -2803,13 +2905,15 @@ discard block |
||
| 2803 | 2905 | } |
| 2804 | 2906 | |
| 2805 | 2907 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2806 | - if (!empty($total_not_moved)) |
|
| 2807 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2908 | + if (!empty($total_not_moved)) { |
|
| 2909 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2910 | + } |
|
| 2808 | 2911 | } |
| 2809 | 2912 | |
| 2810 | 2913 | $_SESSION['results'] = $results; |
| 2811 | - if (file_exists($boarddir . '/progress.php')) |
|
| 2812 | - unlink($boarddir . '/progress.php'); |
|
| 2914 | + if (file_exists($boarddir . '/progress.php')) { |
|
| 2915 | + unlink($boarddir . '/progress.php'); |
|
| 2916 | + } |
|
| 2813 | 2917 | |
| 2814 | 2918 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
| 2815 | 2919 | } |
@@ -143,7 +143,7 @@ |
||
| 143 | 143 | * |
| 144 | 144 | * @param string $dir A valid path |
| 145 | 145 | * |
| 146 | - * @return boolean If this was successful or not. |
|
| 146 | + * @return boolean|null If this was successful or not. |
|
| 147 | 147 | */ |
| 148 | 148 | public function setCachedir($dir = null) |
| 149 | 149 | { |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * SQLite Cache API class |
@@ -161,8 +162,7 @@ discard block |
||
| 161 | 162 | if (is_null($dir) || !is_writable($dir)) |
| 162 | 163 | { |
| 163 | 164 | $this->cachedir = $cachedir_sqlite; |
| 164 | - } |
|
| 165 | - else |
|
| 165 | + } else |
|
| 166 | 166 | { |
| 167 | 167 | $this->cachedir = $dir; |
| 168 | 168 | } |
@@ -382,7 +382,7 @@ |
||
| 382 | 382 | * @param array $parameters Not used? |
| 383 | 383 | * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated. |
| 384 | 384 | * @param string $error |
| 385 | - * @return boolean Whether or not the operation was successful |
|
| 385 | + * @return false|null Whether or not the operation was successful |
|
| 386 | 386 | */ |
| 387 | 387 | function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal') |
| 388 | 388 | { |
@@ -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'); |
@@ -102,8 +104,9 @@ discard block |
||
| 102 | 104 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 103 | 105 | |
| 104 | 106 | // First - no way do we touch SMF tables. |
| 105 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 106 | - return false; |
|
| 107 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | 111 | // Log that we'll want to remove this on uninstall. |
| 109 | 112 | $db_package_log[] = array('remove_table', $table_name); |
@@ -113,10 +116,11 @@ discard block |
||
| 113 | 116 | if (in_array($full_table_name, $tables)) |
| 114 | 117 | { |
| 115 | 118 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 116 | - if ($if_exists == 'overwrite') |
|
| 117 | - $smcFunc['db_drop_table']($table_name); |
|
| 118 | - else |
|
| 119 | - return $if_exists == 'ignore'; |
|
| 119 | + if ($if_exists == 'overwrite') { |
|
| 120 | + $smcFunc['db_drop_table']($table_name); |
|
| 121 | + } else { |
|
| 122 | + return $if_exists == 'ignore'; |
|
| 123 | + } |
|
| 120 | 124 | } |
| 121 | 125 | |
| 122 | 126 | // If we've got this far - good news - no table exists. We can build our own! |
@@ -134,17 +138,18 @@ discard block |
||
| 134 | 138 | ) |
| 135 | 139 | ); |
| 136 | 140 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
| 141 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 142 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 143 | + } else { |
|
| 144 | + $default = ''; |
|
| 137 | 145 | } |
| 138 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 139 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 140 | - else |
|
| 141 | - $default = ''; |
|
| 142 | 146 | |
| 143 | 147 | // Sort out the size... |
| 144 | 148 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
| 145 | 149 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
| 146 | - if ($size !== null) |
|
| 147 | - $type = $type . '(' . $size . ')'; |
|
| 150 | + if ($size !== null) { |
|
| 151 | + $type = $type . '(' . $size . ')'; |
|
| 152 | + } |
|
| 148 | 153 | |
| 149 | 154 | // Now just put it together! |
| 150 | 155 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -157,19 +162,21 @@ discard block |
||
| 157 | 162 | $columns = implode(',', $index['columns']); |
| 158 | 163 | |
| 159 | 164 | // Primary goes in the table... |
| 160 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 161 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 162 | - else |
|
| 165 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 166 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 167 | + } else |
|
| 163 | 168 | { |
| 164 | - if (empty($index['name'])) |
|
| 165 | - $index['name'] = implode('_', $index['columns']); |
|
| 169 | + if (empty($index['name'])) { |
|
| 170 | + $index['name'] = implode('_', $index['columns']); |
|
| 171 | + } |
|
| 166 | 172 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
| 167 | 173 | } |
| 168 | 174 | } |
| 169 | 175 | |
| 170 | 176 | // No trailing commas! |
| 171 | - if (substr($table_query, -1) == ',') |
|
| 172 | - $table_query = substr($table_query, 0, -1); |
|
| 177 | + if (substr($table_query, -1) == ',') { |
|
| 178 | + $table_query = substr($table_query, 0, -1); |
|
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | $table_query .= ')'; |
| 175 | 182 | |
@@ -180,12 +187,13 @@ discard block |
||
| 180 | 187 | ) |
| 181 | 188 | ); |
| 182 | 189 | // And the indexes... |
| 183 | - foreach ($index_queries as $query) |
|
| 184 | - $smcFunc['db_query']('', $query, |
|
| 190 | + foreach ($index_queries as $query) { |
|
| 191 | + $smcFunc['db_query']('', $query, |
|
| 185 | 192 | array( |
| 186 | 193 | 'security_override' => true, |
| 187 | 194 | ) |
| 188 | 195 | ); |
| 196 | + } |
|
| 189 | 197 | |
| 190 | 198 | // Go, go power rangers! |
| 191 | 199 | $smcFunc['db_transaction']('commit'); |
@@ -213,8 +221,9 @@ discard block |
||
| 213 | 221 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 214 | 222 | |
| 215 | 223 | // God no - dropping one of these = bad. |
| 216 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 217 | - return false; |
|
| 224 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 218 | 227 | |
| 219 | 228 | // Does it exist? |
| 220 | 229 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -272,21 +281,24 @@ discard block |
||
| 272 | 281 | |
| 273 | 282 | // Does it exist - if so don't add it again! |
| 274 | 283 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 275 | - foreach ($columns as $column) |
|
| 276 | - if ($column == $column_info['name']) |
|
| 284 | + foreach ($columns as $column) { |
|
| 285 | + if ($column == $column_info['name']) |
|
| 277 | 286 | { |
| 278 | 287 | // If we're going to overwrite then use change column. |
| 279 | 288 | if ($if_exists == 'update') |
| 280 | 289 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 281 | - else |
|
| 282 | - return false; |
|
| 290 | + } |
|
| 291 | + else { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 283 | 294 | } |
| 284 | 295 | |
| 285 | 296 | // Get the specifics... |
| 286 | 297 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 287 | 298 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 288 | - if ($size !== null) |
|
| 289 | - $type = $type . '(' . $size . ')'; |
|
| 299 | + if ($size !== null) { |
|
| 300 | + $type = $type . '(' . $size . ')'; |
|
| 301 | + } |
|
| 290 | 302 | |
| 291 | 303 | // Now add the thing! |
| 292 | 304 | $query = ' |
@@ -301,11 +313,12 @@ discard block |
||
| 301 | 313 | // If there's more attributes they need to be done via a change on PostgreSQL. |
| 302 | 314 | unset($column_info['type'], $column_info['size']); |
| 303 | 315 | |
| 304 | - if (count($column_info) != 1) |
|
| 305 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 306 | - else |
|
| 307 | - return true; |
|
| 308 | -} |
|
| 316 | + if (count($column_info) != 1) { |
|
| 317 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 318 | + } else { |
|
| 319 | + return true; |
|
| 320 | + } |
|
| 321 | + } |
|
| 309 | 322 | |
| 310 | 323 | /** |
| 311 | 324 | * Removes a column. |
@@ -324,8 +337,8 @@ discard block |
||
| 324 | 337 | |
| 325 | 338 | // Does it exist? |
| 326 | 339 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 327 | - foreach ($columns as $column) |
|
| 328 | - if ($column['name'] == $column_name) |
|
| 340 | + foreach ($columns as $column) { |
|
| 341 | + if ($column['name'] == $column_name) |
|
| 329 | 342 | { |
| 330 | 343 | // If there is an auto we need remove it! |
| 331 | 344 | if ($column['auto']) |
@@ -335,6 +348,7 @@ discard block |
||
| 335 | 348 | 'security_override' => true, |
| 336 | 349 | ) |
| 337 | 350 | ); |
| 351 | + } |
|
| 338 | 352 | |
| 339 | 353 | $smcFunc['db_query']('', ' |
| 340 | 354 | ALTER TABLE ' . $table_name . ' |
@@ -368,13 +382,15 @@ discard block |
||
| 368 | 382 | // Check it does exist! |
| 369 | 383 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 370 | 384 | $old_info = null; |
| 371 | - foreach ($columns as $column) |
|
| 372 | - if ($column['name'] == $old_column) |
|
| 385 | + foreach ($columns as $column) { |
|
| 386 | + if ($column['name'] == $old_column) |
|
| 373 | 387 | $old_info = $column; |
| 388 | + } |
|
| 374 | 389 | |
| 375 | 390 | // Nothing? |
| 376 | - if ($old_info == null) |
|
| 377 | - return false; |
|
| 391 | + if ($old_info == null) { |
|
| 392 | + return false; |
|
| 393 | + } |
|
| 378 | 394 | |
| 379 | 395 | // Now we check each bit individually and ALTER as required. |
| 380 | 396 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -431,8 +447,9 @@ discard block |
||
| 431 | 447 | { |
| 432 | 448 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 433 | 449 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 434 | - if ($size !== null) |
|
| 435 | - $type = $type . '(' . $size . ')'; |
|
| 450 | + if ($size !== null) { |
|
| 451 | + $type = $type . '(' . $size . ')'; |
|
| 452 | + } |
|
| 436 | 453 | |
| 437 | 454 | // The alter is a pain. |
| 438 | 455 | $smcFunc['db_transaction']('begin'); |
@@ -526,21 +543,23 @@ discard block |
||
| 526 | 543 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 527 | 544 | |
| 528 | 545 | // No columns = no index. |
| 529 | - if (empty($index_info['columns'])) |
|
| 530 | - return false; |
|
| 546 | + if (empty($index_info['columns'])) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 531 | 549 | $columns = implode(',', $index_info['columns']); |
| 532 | 550 | |
| 533 | 551 | // No name - make it up! |
| 534 | 552 | if (empty($index_info['name'])) |
| 535 | 553 | { |
| 536 | 554 | // No need for primary. |
| 537 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 538 | - $index_info['name'] = ''; |
|
| 539 | - else |
|
| 540 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 555 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 556 | + $index_info['name'] = ''; |
|
| 557 | + } else { |
|
| 558 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 559 | + } |
|
| 560 | + } else { |
|
| 561 | + $index_info['name'] = $table_name . $index_info['name']; |
|
| 541 | 562 | } |
| 542 | - else |
|
| 543 | - $index_info['name'] = $table_name . $index_info['name']; |
|
| 544 | 563 | |
| 545 | 564 | // Log that we are going to want to remove this! |
| 546 | 565 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -553,10 +572,11 @@ discard block |
||
| 553 | 572 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 554 | 573 | { |
| 555 | 574 | // If we want to overwrite simply remove the current one then continue. |
| 556 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 557 | - return false; |
|
| 558 | - else |
|
| 559 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 575 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 576 | + return false; |
|
| 577 | + } else { |
|
| 578 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 579 | + } |
|
| 560 | 580 | } |
| 561 | 581 | } |
| 562 | 582 | |
@@ -570,8 +590,7 @@ discard block |
||
| 570 | 590 | 'security_override' => true, |
| 571 | 591 | ) |
| 572 | 592 | ); |
| 573 | - } |
|
| 574 | - else |
|
| 593 | + } else |
|
| 575 | 594 | { |
| 576 | 595 | $smcFunc['db_query']('', ' |
| 577 | 596 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -599,8 +618,9 @@ discard block |
||
| 599 | 618 | |
| 600 | 619 | // Better exist! |
| 601 | 620 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
| 602 | - if ($index_name != 'primary') |
|
| 603 | - $index_name = $table_name . '_' . $index_name; |
|
| 621 | + if ($index_name != 'primary') { |
|
| 622 | + $index_name = $table_name . '_' . $index_name; |
|
| 623 | + } |
|
| 604 | 624 | |
| 605 | 625 | foreach ($indexes as $index) |
| 606 | 626 | { |
@@ -664,8 +684,7 @@ discard block |
||
| 664 | 684 | 'datetime' => 'timestamp without time zone', |
| 665 | 685 | 'timestamp' => 'timestamp without time zone', |
| 666 | 686 | ); |
| 667 | - } |
|
| 668 | - else |
|
| 687 | + } else |
|
| 669 | 688 | { |
| 670 | 689 | $types = array( |
| 671 | 690 | 'character varying' => 'varchar', |
@@ -681,14 +700,16 @@ discard block |
||
| 681 | 700 | // Got it? Change it! |
| 682 | 701 | if (isset($types[$type_name])) |
| 683 | 702 | { |
| 684 | - if ($type_name == 'tinytext') |
|
| 685 | - $type_size = 255; |
|
| 703 | + if ($type_name == 'tinytext') { |
|
| 704 | + $type_size = 255; |
|
| 705 | + } |
|
| 686 | 706 | $type_name = $types[$type_name]; |
| 687 | 707 | } |
| 688 | 708 | |
| 689 | 709 | // Only char fields got size |
| 690 | - if (strpos($type_name, 'char') === false) |
|
| 691 | - $type_size = null; |
|
| 710 | + if (strpos($type_name, 'char') === false) { |
|
| 711 | + $type_size = null; |
|
| 712 | + } |
|
| 692 | 713 | |
| 693 | 714 | |
| 694 | 715 | return array($type_name, $type_size); |
@@ -742,8 +763,7 @@ discard block |
||
| 742 | 763 | if (!$detail) |
| 743 | 764 | { |
| 744 | 765 | $columns[] = $row['column_name']; |
| 745 | - } |
|
| 746 | - else |
|
| 766 | + } else |
|
| 747 | 767 | { |
| 748 | 768 | $auto = false; |
| 749 | 769 | // What is the default? |
@@ -751,11 +771,11 @@ discard block |
||
| 751 | 771 | { |
| 752 | 772 | $default = null; |
| 753 | 773 | $auto = true; |
| 774 | + } elseif (trim($row['column_default']) != '') { |
|
| 775 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 776 | + } else { |
|
| 777 | + $default = null; |
|
| 754 | 778 | } |
| 755 | - elseif (trim($row['column_default']) != '') |
|
| 756 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 757 | - else |
|
| 758 | - $default = null; |
|
| 759 | 779 | |
| 760 | 780 | // Make the type generic. |
| 761 | 781 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -806,26 +826,30 @@ discard block |
||
| 806 | 826 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 807 | 827 | { |
| 808 | 828 | // Try get the columns that make it up. |
| 809 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 810 | - continue; |
|
| 829 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 830 | + continue; |
|
| 831 | + } |
|
| 811 | 832 | |
| 812 | 833 | $columns = explode(',', $matches[1]); |
| 813 | 834 | |
| 814 | - if (empty($columns)) |
|
| 815 | - continue; |
|
| 835 | + if (empty($columns)) { |
|
| 836 | + continue; |
|
| 837 | + } |
|
| 816 | 838 | |
| 817 | - foreach ($columns as $k => $v) |
|
| 818 | - $columns[$k] = trim($v); |
|
| 839 | + foreach ($columns as $k => $v) { |
|
| 840 | + $columns[$k] = trim($v); |
|
| 841 | + } |
|
| 819 | 842 | |
| 820 | 843 | // Fix up the name to be consistent cross databases |
| 821 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
| 822 | - $row['name'] = 'PRIMARY'; |
|
| 823 | - else |
|
| 824 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 844 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
| 845 | + $row['name'] = 'PRIMARY'; |
|
| 846 | + } else { |
|
| 847 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 848 | + } |
|
| 825 | 849 | |
| 826 | - if (!$detail) |
|
| 827 | - $indexes[] = $row['name']; |
|
| 828 | - else |
|
| 850 | + if (!$detail) { |
|
| 851 | + $indexes[] = $row['name']; |
|
| 852 | + } else |
|
| 829 | 853 | { |
| 830 | 854 | $indexes[$row['name']] = array( |
| 831 | 855 | 'name' => $row['name'], |
@@ -2262,9 +2262,9 @@ discard block |
||
| 2262 | 2262 | * |
| 2263 | 2263 | * @uses the template_include() function to include the file. |
| 2264 | 2264 | * @param string $template_name The name of the template to load |
| 2265 | - * @param array|string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2265 | + * @param string $style_sheets The name of a single stylesheet or an array of names of stylesheets to load |
|
| 2266 | 2266 | * @param bool $fatal If true, dies with an error message if the template cannot be found |
| 2267 | - * @return boolean Whether or not the template was loaded |
|
| 2267 | + * @return boolean|null Whether or not the template was loaded |
|
| 2268 | 2268 | */ |
| 2269 | 2269 | function loadTemplate($template_name, $style_sheets = array(), $fatal = true) |
| 2270 | 2270 | { |
@@ -2447,7 +2447,7 @@ discard block |
||
| 2447 | 2447 | * - all code added with this function is added to the same <style> tag so do make sure your css is valid! |
| 2448 | 2448 | * |
| 2449 | 2449 | * @param string $css Some css code |
| 2450 | - * @return void|bool Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2450 | + * @return false|null Adds the CSS to the $context['css_header'] array or returns if no CSS is specified |
|
| 2451 | 2451 | */ |
| 2452 | 2452 | function addInlineCss($css) |
| 2453 | 2453 | { |
@@ -2463,7 +2463,7 @@ discard block |
||
| 2463 | 2463 | /** |
| 2464 | 2464 | * Add a Javascript file for output later |
| 2465 | 2465 | * |
| 2466 | - * @param string $filename The name of the file to load |
|
| 2466 | + * @param string $fileName The name of the file to load |
|
| 2467 | 2467 | * @param array $params An array of parameter info |
| 2468 | 2468 | * Keys are the following: |
| 2469 | 2469 | * - ['external'] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file |
@@ -2561,7 +2561,7 @@ discard block |
||
| 2561 | 2561 | * |
| 2562 | 2562 | * @param string $javascript Some JS code |
| 2563 | 2563 | * @param bool $defer Whether the script should load in <head> or before the closing <html> tag |
| 2564 | - * @return void|bool Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2564 | + * @return false|null Adds the code to one of the $context['javascript_inline'] arrays or returns if no JS was specified |
|
| 2565 | 2565 | */ |
| 2566 | 2566 | function addInlineJavaScript($javascript, $defer = false) |
| 2567 | 2567 | { |
@@ -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 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
| 25 | 26 | global $cache_enable, $sourcedir, $context; |
| 26 | 27 | |
| 27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
| 28 | - if (!empty($db_character_set)) |
|
| 29 | - $smcFunc['db_query']('', ' |
|
| 29 | + if (!empty($db_character_set)) { |
|
| 30 | + $smcFunc['db_query']('', ' |
|
| 30 | 31 | SET NAMES {string:db_character_set}', |
| 31 | 32 | array( |
| 32 | 33 | 'db_character_set' => $db_character_set, |
| 33 | 34 | ) |
| 34 | 35 | ); |
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // We need some caching support, maybe. |
| 37 | 39 | loadCacheAccelerator(); |
@@ -46,27 +48,35 @@ discard block |
||
| 46 | 48 | ) |
| 47 | 49 | ); |
| 48 | 50 | $modSettings = array(); |
| 49 | - if (!$request) |
|
| 50 | - display_db_error(); |
|
| 51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
| 52 | - $modSettings[$row[0]] = $row[1]; |
|
| 51 | + if (!$request) { |
|
| 52 | + display_db_error(); |
|
| 53 | + } |
|
| 54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
| 55 | + $modSettings[$row[0]] = $row[1]; |
|
| 56 | + } |
|
| 53 | 57 | $smcFunc['db_free_result']($request); |
| 54 | 58 | |
| 55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
| 56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
| 57 | - $modSettings['defaultMaxTopics'] = 20; |
|
| 58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
| 59 | - $modSettings['defaultMaxMessages'] = 15; |
|
| 60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
| 61 | - $modSettings['defaultMaxMembers'] = 30; |
|
| 62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
| 63 | - $modSettings['defaultMaxListItems'] = 15; |
|
| 60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
| 61 | + $modSettings['defaultMaxTopics'] = 20; |
|
| 62 | + } |
|
| 63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
| 64 | + $modSettings['defaultMaxMessages'] = 15; |
|
| 65 | + } |
|
| 66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
| 67 | + $modSettings['defaultMaxMembers'] = 30; |
|
| 68 | + } |
|
| 69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
| 70 | + $modSettings['defaultMaxListItems'] = 15; |
|
| 71 | + } |
|
| 64 | 72 | |
| 65 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
| 66 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 73 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
| 74 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
| 75 | + } |
|
| 67 | 76 | |
| 68 | - if (!empty($cache_enable)) |
|
| 69 | - cache_put_data('modSettings', $modSettings, 90); |
|
| 77 | + if (!empty($cache_enable)) { |
|
| 78 | + cache_put_data('modSettings', $modSettings, 90); |
|
| 79 | + } |
|
| 70 | 80 | } |
| 71 | 81 | |
| 72 | 82 | $modSettings['cache_enable'] = $cache_enable; |
@@ -86,8 +96,9 @@ discard block |
||
| 86 | 96 | }; |
| 87 | 97 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
| 88 | 98 | { |
| 89 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
| 90 | - return $string; |
|
| 99 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
| 100 | + return $string; |
|
| 101 | + } |
|
| 91 | 102 | |
| 92 | 103 | $i = 0; |
| 93 | 104 | $len = strlen($string); |
@@ -99,18 +110,15 @@ discard block |
||
| 99 | 110 | { |
| 100 | 111 | $new_string .= $string[$i]; |
| 101 | 112 | $i++; |
| 102 | - } |
|
| 103 | - elseif ($ord < 224) |
|
| 113 | + } elseif ($ord < 224) |
|
| 104 | 114 | { |
| 105 | 115 | $new_string .= $string[$i] . $string[$i + 1]; |
| 106 | 116 | $i += 2; |
| 107 | - } |
|
| 108 | - elseif ($ord < 240) |
|
| 117 | + } elseif ($ord < 240) |
|
| 109 | 118 | { |
| 110 | 119 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
| 111 | 120 | $i += 3; |
| 112 | - } |
|
| 113 | - elseif ($ord < 248) |
|
| 121 | + } elseif ($ord < 248) |
|
| 114 | 122 | { |
| 115 | 123 | // Magic happens. |
| 116 | 124 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -154,8 +162,7 @@ discard block |
||
| 154 | 162 | { |
| 155 | 163 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
| 156 | 164 | return is_int($result) ? $result + $offset : false; |
| 157 | - } |
|
| 158 | - else |
|
| 165 | + } else |
|
| 159 | 166 | { |
| 160 | 167 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
| 161 | 168 | $needle_size = count($needle_arr); |
@@ -164,8 +171,9 @@ discard block |
||
| 164 | 171 | while ((int) $result === $result) |
| 165 | 172 | { |
| 166 | 173 | $offset += $result; |
| 167 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
| 168 | - return $offset; |
|
| 174 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
| 175 | + return $offset; |
|
| 176 | + } |
|
| 169 | 177 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
| 170 | 178 | } |
| 171 | 179 | return false; |
@@ -203,8 +211,9 @@ discard block |
||
| 203 | 211 | $string = $ent_check($string); |
| 204 | 212 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
| 205 | 213 | $string = $matches[0]; |
| 206 | - while (strlen($string) > $length) |
|
| 207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 214 | + while (strlen($string) > $length) { |
|
| 215 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
| 216 | + } |
|
| 208 | 217 | return $string; |
| 209 | 218 | }, |
| 210 | 219 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -214,23 +223,25 @@ discard block |
||
| 214 | 223 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
| 215 | 224 | { |
| 216 | 225 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
| 217 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
| 218 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 226 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
| 227 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
| 228 | + } |
|
| 219 | 229 | return implode('', $words); |
| 220 | 230 | } : 'ucwords', |
| 221 | 231 | ); |
| 222 | 232 | |
| 223 | 233 | // Setting the timezone is a requirement for some functions. |
| 224 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
| 225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
| 226 | - else |
|
| 234 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
| 235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
| 236 | + } else |
|
| 227 | 237 | { |
| 228 | 238 | // Get PHP's default timezone, if set |
| 229 | 239 | $ini_tz = ini_get('date.timezone'); |
| 230 | - if (!empty($ini_tz)) |
|
| 231 | - $modSettings['default_timezone'] = $ini_tz; |
|
| 232 | - else |
|
| 233 | - $modSettings['default_timezone'] = ''; |
|
| 240 | + if (!empty($ini_tz)) { |
|
| 241 | + $modSettings['default_timezone'] = $ini_tz; |
|
| 242 | + } else { |
|
| 243 | + $modSettings['default_timezone'] = ''; |
|
| 244 | + } |
|
| 234 | 245 | |
| 235 | 246 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
| 236 | 247 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -248,22 +259,26 @@ discard block |
||
| 248 | 259 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
| 249 | 260 | { |
| 250 | 261 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
| 251 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
| 252 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 253 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
| 254 | - $modSettings['load_average'] = (float) $matches[1]; |
|
| 255 | - else |
|
| 256 | - unset($modSettings['load_average']); |
|
| 262 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
| 263 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 264 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
| 265 | + $modSettings['load_average'] = (float) $matches[1]; |
|
| 266 | + } else { |
|
| 267 | + unset($modSettings['load_average']); |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 259 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 270 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 271 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
| 272 | + } |
|
| 260 | 273 | } |
| 261 | 274 | |
| 262 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
| 263 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 275 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
| 276 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
| 277 | + } |
|
| 264 | 278 | |
| 265 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
| 266 | - display_loadavg_error(); |
|
| 279 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
| 280 | + display_loadavg_error(); |
|
| 281 | + } |
|
| 267 | 282 | } |
| 268 | 283 | |
| 269 | 284 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -284,8 +299,9 @@ discard block |
||
| 284 | 299 | if (defined('SMF_INTEGRATION_SETTINGS')) |
| 285 | 300 | { |
| 286 | 301 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
| 287 | - foreach ($integration_settings as $hook => $function) |
|
| 288 | - add_integration_function($hook, $function, '', false); |
|
| 302 | + foreach ($integration_settings as $hook => $function) { |
|
| 303 | + add_integration_function($hook, $function, '', false); |
|
| 304 | + } |
|
| 289 | 305 | } |
| 290 | 306 | |
| 291 | 307 | // Any files to pre include? |
@@ -295,8 +311,9 @@ discard block |
||
| 295 | 311 | foreach ($pre_includes as $include) |
| 296 | 312 | { |
| 297 | 313 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 298 | - if (file_exists($include)) |
|
| 299 | - require_once($include); |
|
| 314 | + if (file_exists($include)) { |
|
| 315 | + require_once($include); |
|
| 316 | + } |
|
| 300 | 317 | } |
| 301 | 318 | } |
| 302 | 319 | |
@@ -400,27 +417,28 @@ discard block |
||
| 400 | 417 | break; |
| 401 | 418 | } |
| 402 | 419 | } |
| 420 | + } else { |
|
| 421 | + $id_member = 0; |
|
| 403 | 422 | } |
| 404 | - else |
|
| 405 | - $id_member = 0; |
|
| 406 | 423 | |
| 407 | 424 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
| 408 | 425 | { |
| 409 | 426 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
| 410 | 427 | |
| 411 | - if (empty($cookie_data)) |
|
| 412 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 428 | + if (empty($cookie_data)) { |
|
| 429 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
| 430 | + } |
|
| 413 | 431 | |
| 414 | 432 | list ($id_member, $password) = $cookie_data; |
| 415 | 433 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
| 416 | - } |
|
| 417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 434 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
| 418 | 435 | { |
| 419 | 436 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
| 420 | 437 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
| 421 | 438 | |
| 422 | - if (empty($cookie_data)) |
|
| 423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 439 | + if (empty($cookie_data)) { |
|
| 440 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
| 441 | + } |
|
| 424 | 442 | |
| 425 | 443 | list ($id_member, $password, $login_span) = $cookie_data; |
| 426 | 444 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +463,34 @@ discard block |
||
| 445 | 463 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
| 446 | 464 | $smcFunc['db_free_result']($request); |
| 447 | 465 | |
| 448 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
| 449 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 466 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
| 467 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
| 468 | + } |
|
| 450 | 469 | |
| 451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 471 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 472 | + } |
|
| 453 | 473 | } |
| 454 | 474 | |
| 455 | 475 | // Did we find 'im? If not, junk it. |
| 456 | 476 | if (!empty($user_settings)) |
| 457 | 477 | { |
| 458 | 478 | // As much as the password should be right, we can assume the integration set things up. |
| 459 | - if (!empty($already_verified) && $already_verified === true) |
|
| 460 | - $check = true; |
|
| 479 | + if (!empty($already_verified) && $already_verified === true) { |
|
| 480 | + $check = true; |
|
| 481 | + } |
|
| 461 | 482 | // SHA-512 hash should be 128 characters long. |
| 462 | - elseif (strlen($password) == 128) |
|
| 463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 464 | - else |
|
| 465 | - $check = false; |
|
| 483 | + elseif (strlen($password) == 128) { |
|
| 484 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
| 485 | + } else { |
|
| 486 | + $check = false; |
|
| 487 | + } |
|
| 466 | 488 | |
| 467 | 489 | // Wrong password or not activated - either way, you're going nowhere. |
| 468 | 490 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
| 491 | + } else { |
|
| 492 | + $id_member = 0; |
|
| 469 | 493 | } |
| 470 | - else |
|
| 471 | - $id_member = 0; |
|
| 472 | 494 | |
| 473 | 495 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
| 474 | 496 | if (!$id_member) |
@@ -492,8 +514,9 @@ discard block |
||
| 492 | 514 | |
| 493 | 515 | list ($tfamember, $tfasecret) = $tfa_data; |
| 494 | 516 | |
| 495 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
| 496 | - $tfasecret = null; |
|
| 517 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
| 518 | + $tfasecret = null; |
|
| 519 | + } |
|
| 497 | 520 | } |
| 498 | 521 | |
| 499 | 522 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -513,10 +536,12 @@ discard block |
||
| 513 | 536 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
| 514 | 537 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
| 515 | 538 | { |
| 516 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
| 539 | + if ($modSettings['tfa_mode'] == 2) { |
|
| 540 | + //only do this if we are just forcing SOME membergroups |
|
| 517 | 541 | { |
| 518 | 542 | //Build an array of ALL user membergroups. |
| 519 | 543 | $full_groups = array($user_settings['id_group']); |
| 544 | + } |
|
| 520 | 545 | if (!empty($user_settings['additional_groups'])) |
| 521 | 546 | { |
| 522 | 547 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -536,15 +561,17 @@ discard block |
||
| 536 | 561 | ); |
| 537 | 562 | $row = $smcFunc['db_fetch_assoc']($request); |
| 538 | 563 | $smcFunc['db_free_result']($request); |
| 564 | + } else { |
|
| 565 | + $row['total'] = 1; |
|
| 539 | 566 | } |
| 540 | - else |
|
| 541 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
| 567 | + //simplifies logics in the next "if" |
|
| 542 | 568 | |
| 543 | 569 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
| 544 | 570 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
| 545 | 571 | |
| 546 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
| 547 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
| 572 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
| 573 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
| 574 | + } |
|
| 548 | 575 | } |
| 549 | 576 | } |
| 550 | 577 | |
@@ -581,33 +608,37 @@ discard block |
||
| 581 | 608 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
| 582 | 609 | $user_settings['last_login'] = time(); |
| 583 | 610 | |
| 584 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 585 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 611 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 612 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
| 613 | + } |
|
| 586 | 614 | |
| 587 | - if (!empty($modSettings['cache_enable'])) |
|
| 588 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 615 | + if (!empty($modSettings['cache_enable'])) { |
|
| 616 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
| 617 | + } |
|
| 589 | 618 | } |
| 619 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
| 620 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 590 | 621 | } |
| 591 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
| 592 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
| 593 | 622 | |
| 594 | 623 | $username = $user_settings['member_name']; |
| 595 | 624 | |
| 596 | - if (empty($user_settings['additional_groups'])) |
|
| 597 | - $user_info = array( |
|
| 625 | + if (empty($user_settings['additional_groups'])) { |
|
| 626 | + $user_info = array( |
|
| 598 | 627 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
| 599 | 628 | ); |
| 600 | - else |
|
| 601 | - $user_info = array( |
|
| 629 | + } else { |
|
| 630 | + $user_info = array( |
|
| 602 | 631 | 'groups' => array_merge( |
| 603 | 632 | array($user_settings['id_group'], $user_settings['id_post_group']), |
| 604 | 633 | explode(',', $user_settings['additional_groups']) |
| 605 | 634 | ) |
| 606 | 635 | ); |
| 636 | + } |
|
| 607 | 637 | |
| 608 | 638 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
| 609 | - foreach ($user_info['groups'] as $k => $v) |
|
| 610 | - $user_info['groups'][$k] = (int) $v; |
|
| 639 | + foreach ($user_info['groups'] as $k => $v) { |
|
| 640 | + $user_info['groups'][$k] = (int) $v; |
|
| 641 | + } |
|
| 611 | 642 | |
| 612 | 643 | // This is a logged in user, so definitely not a spider. |
| 613 | 644 | $user_info['possibly_robot'] = false; |
@@ -621,8 +652,7 @@ discard block |
||
| 621 | 652 | $time_system = new DateTime('now', $tz_system); |
| 622 | 653 | $time_user = new DateTime('now', $tz_user); |
| 623 | 654 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
| 624 | - } |
|
| 625 | - else |
|
| 655 | + } else |
|
| 626 | 656 | { |
| 627 | 657 | // !!! Compatibility. |
| 628 | 658 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -636,8 +666,9 @@ discard block |
||
| 636 | 666 | $user_info = array('groups' => array(-1)); |
| 637 | 667 | $user_settings = array(); |
| 638 | 668 | |
| 639 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
| 640 | - $_COOKIE[$cookiename] = ''; |
|
| 669 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
| 670 | + $_COOKIE[$cookiename] = ''; |
|
| 671 | + } |
|
| 641 | 672 | |
| 642 | 673 | // Expire the 2FA cookie |
| 643 | 674 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -654,19 +685,20 @@ discard block |
||
| 654 | 685 | } |
| 655 | 686 | |
| 656 | 687 | // Create a login token if it doesn't exist yet. |
| 657 | - if (!isset($_SESSION['token']['post-login'])) |
|
| 658 | - createToken('login'); |
|
| 659 | - else |
|
| 660 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 688 | + if (!isset($_SESSION['token']['post-login'])) { |
|
| 689 | + createToken('login'); |
|
| 690 | + } else { |
|
| 691 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
| 692 | + } |
|
| 661 | 693 | |
| 662 | 694 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
| 663 | 695 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
| 664 | 696 | { |
| 665 | 697 | require_once($sourcedir . '/ManageSearchEngines.php'); |
| 666 | 698 | $user_info['possibly_robot'] = SpiderCheck(); |
| 699 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
| 700 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 667 | 701 | } |
| 668 | - elseif (!empty($modSettings['spider_mode'])) |
|
| 669 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
| 670 | 702 | // If we haven't turned on proper spider hunts then have a guess! |
| 671 | 703 | else |
| 672 | 704 | { |
@@ -714,8 +746,9 @@ discard block |
||
| 714 | 746 | $user_info['groups'] = array_unique($user_info['groups']); |
| 715 | 747 | |
| 716 | 748 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
| 717 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
| 718 | - unset($user_info['ignoreboards'][$tmp]); |
|
| 749 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
| 750 | + unset($user_info['ignoreboards'][$tmp]); |
|
| 751 | + } |
|
| 719 | 752 | |
| 720 | 753 | // Allow the user to change their language. |
| 721 | 754 | if (!empty($modSettings['userLanguage'])) |
@@ -728,31 +761,36 @@ discard block |
||
| 728 | 761 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
| 729 | 762 | |
| 730 | 763 | // Make it permanent for members. |
| 731 | - if (!empty($user_info['id'])) |
|
| 732 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 733 | - else |
|
| 734 | - $_SESSION['language'] = $user_info['language']; |
|
| 764 | + if (!empty($user_info['id'])) { |
|
| 765 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
| 766 | + } else { |
|
| 767 | + $_SESSION['language'] = $user_info['language']; |
|
| 768 | + } |
|
| 769 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
| 770 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 735 | 771 | } |
| 736 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
| 737 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
| 738 | 772 | } |
| 739 | 773 | |
| 740 | 774 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
| 741 | - if ($user_info['is_admin']) |
|
| 742 | - $user_info['query_see_board'] = '1=1'; |
|
| 775 | + if ($user_info['is_admin']) { |
|
| 776 | + $user_info['query_see_board'] = '1=1'; |
|
| 777 | + } |
|
| 743 | 778 | // Otherwise just the groups in $user_info['groups']. |
| 744 | - else |
|
| 745 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
| 779 | + else { |
|
| 780 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
| 781 | + } |
|
| 746 | 782 | |
| 747 | 783 | // Build the list of boards they WANT to see. |
| 748 | 784 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
| 749 | 785 | |
| 750 | 786 | // If they aren't ignoring any boards then they want to see all the boards they can see |
| 751 | - if (empty($user_info['ignoreboards'])) |
|
| 752 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 787 | + if (empty($user_info['ignoreboards'])) { |
|
| 788 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
| 789 | + } |
|
| 753 | 790 | // Ok I guess they don't want to see all the boards |
| 754 | - else |
|
| 755 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 791 | + else { |
|
| 792 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
| 793 | + } |
|
| 756 | 794 | |
| 757 | 795 | call_integration_hook('integrate_user_info'); |
| 758 | 796 | } |
@@ -810,9 +848,9 @@ discard block |
||
| 810 | 848 | } |
| 811 | 849 | |
| 812 | 850 | // Remember redirection is the key to avoiding fallout from your bosses. |
| 813 | - if (!empty($topic)) |
|
| 814 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 815 | - else |
|
| 851 | + if (!empty($topic)) { |
|
| 852 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
| 853 | + } else |
|
| 816 | 854 | { |
| 817 | 855 | loadPermissions(); |
| 818 | 856 | loadTheme(); |
@@ -830,10 +868,11 @@ discard block |
||
| 830 | 868 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 831 | 869 | { |
| 832 | 870 | // @todo SLOW? |
| 833 | - if (!empty($topic)) |
|
| 834 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 835 | - else |
|
| 836 | - $temp = cache_get_data('board-' . $board, 120); |
|
| 871 | + if (!empty($topic)) { |
|
| 872 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
| 873 | + } else { |
|
| 874 | + $temp = cache_get_data('board-' . $board, 120); |
|
| 875 | + } |
|
| 837 | 876 | |
| 838 | 877 | if (!empty($temp)) |
| 839 | 878 | { |
@@ -871,8 +910,9 @@ discard block |
||
| 871 | 910 | $row = $smcFunc['db_fetch_assoc']($request); |
| 872 | 911 | |
| 873 | 912 | // Set the current board. |
| 874 | - if (!empty($row['id_board'])) |
|
| 875 | - $board = $row['id_board']; |
|
| 913 | + if (!empty($row['id_board'])) { |
|
| 914 | + $board = $row['id_board']; |
|
| 915 | + } |
|
| 876 | 916 | |
| 877 | 917 | // Basic operating information. (globals... :/) |
| 878 | 918 | $board_info = array( |
@@ -908,21 +948,23 @@ discard block |
||
| 908 | 948 | |
| 909 | 949 | do |
| 910 | 950 | { |
| 911 | - if (!empty($row['id_moderator'])) |
|
| 912 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
| 951 | + if (!empty($row['id_moderator'])) { |
|
| 952 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
| 913 | 953 | 'id' => $row['id_moderator'], |
| 914 | 954 | 'name' => $row['real_name'], |
| 915 | 955 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 916 | 956 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 917 | 957 | ); |
| 958 | + } |
|
| 918 | 959 | |
| 919 | - if (!empty($row['id_moderator_group'])) |
|
| 920 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 960 | + if (!empty($row['id_moderator_group'])) { |
|
| 961 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
| 921 | 962 | 'id' => $row['id_moderator_group'], |
| 922 | 963 | 'name' => $row['group_name'], |
| 923 | 964 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 924 | 965 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 925 | 966 | ); |
| 967 | + } |
|
| 926 | 968 | } |
| 927 | 969 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
| 928 | 970 | |
@@ -954,12 +996,12 @@ discard block |
||
| 954 | 996 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
| 955 | 997 | { |
| 956 | 998 | // @todo SLOW? |
| 957 | - if (!empty($topic)) |
|
| 958 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 999 | + if (!empty($topic)) { |
|
| 1000 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
| 1001 | + } |
|
| 959 | 1002 | cache_put_data('board-' . $board, $board_info, 120); |
| 960 | 1003 | } |
| 961 | - } |
|
| 962 | - else |
|
| 1004 | + } else |
|
| 963 | 1005 | { |
| 964 | 1006 | // Otherwise the topic is invalid, there are no moderators, etc. |
| 965 | 1007 | $board_info = array( |
@@ -973,8 +1015,9 @@ discard block |
||
| 973 | 1015 | $smcFunc['db_free_result']($request); |
| 974 | 1016 | } |
| 975 | 1017 | |
| 976 | - if (!empty($topic)) |
|
| 977 | - $_GET['board'] = (int) $board; |
|
| 1018 | + if (!empty($topic)) { |
|
| 1019 | + $_GET['board'] = (int) $board; |
|
| 1020 | + } |
|
| 978 | 1021 | |
| 979 | 1022 | if (!empty($board)) |
| 980 | 1023 | { |
@@ -984,10 +1027,12 @@ discard block |
||
| 984 | 1027 | // Now check if the user is a moderator. |
| 985 | 1028 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
| 986 | 1029 | |
| 987 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
| 988 | - $board_info['error'] = 'access'; |
|
| 989 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
| 990 | - $board_info['error'] = 'access'; |
|
| 1030 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
| 1031 | + $board_info['error'] = 'access'; |
|
| 1032 | + } |
|
| 1033 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
| 1034 | + $board_info['error'] = 'access'; |
|
| 1035 | + } |
|
| 991 | 1036 | |
| 992 | 1037 | // Build up the linktree. |
| 993 | 1038 | $context['linktree'] = array_merge( |
@@ -1010,8 +1055,9 @@ discard block |
||
| 1010 | 1055 | $context['current_board'] = $board; |
| 1011 | 1056 | |
| 1012 | 1057 | // No posting in redirection boards! |
| 1013 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
| 1014 | - $board_info['error'] == 'post_in_redirect'; |
|
| 1058 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
| 1059 | + $board_info['error'] == 'post_in_redirect'; |
|
| 1060 | + } |
|
| 1015 | 1061 | |
| 1016 | 1062 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
| 1017 | 1063 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1037,24 +1083,23 @@ discard block |
||
| 1037 | 1083 | ob_end_clean(); |
| 1038 | 1084 | header('HTTP/1.1 403 Forbidden'); |
| 1039 | 1085 | die; |
| 1040 | - } |
|
| 1041 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1086 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
| 1042 | 1087 | { |
| 1043 | 1088 | // Slightly different error message here... |
| 1044 | 1089 | fatal_lang_error('cannot_post_redirect', false); |
| 1045 | - } |
|
| 1046 | - elseif ($user_info['is_guest']) |
|
| 1090 | + } elseif ($user_info['is_guest']) |
|
| 1047 | 1091 | { |
| 1048 | 1092 | loadLanguage('Errors'); |
| 1049 | 1093 | is_not_guest($txt['topic_gone']); |
| 1094 | + } else { |
|
| 1095 | + fatal_lang_error('topic_gone', false); |
|
| 1050 | 1096 | } |
| 1051 | - else |
|
| 1052 | - fatal_lang_error('topic_gone', false); |
|
| 1053 | 1097 | } |
| 1054 | 1098 | |
| 1055 | - if ($user_info['is_mod']) |
|
| 1056 | - $user_info['groups'][] = 3; |
|
| 1057 | -} |
|
| 1099 | + if ($user_info['is_mod']) { |
|
| 1100 | + $user_info['groups'][] = 3; |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1058 | 1103 | |
| 1059 | 1104 | /** |
| 1060 | 1105 | * Load this user's permissions. |
@@ -1075,8 +1120,9 @@ discard block |
||
| 1075 | 1120 | asort($cache_groups); |
| 1076 | 1121 | $cache_groups = implode(',', $cache_groups); |
| 1077 | 1122 | // If it's a spider then cache it different. |
| 1078 | - if ($user_info['possibly_robot']) |
|
| 1079 | - $cache_groups .= '-spider'; |
|
| 1123 | + if ($user_info['possibly_robot']) { |
|
| 1124 | + $cache_groups .= '-spider'; |
|
| 1125 | + } |
|
| 1080 | 1126 | |
| 1081 | 1127 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
| 1082 | 1128 | { |
@@ -1084,9 +1130,9 @@ discard block |
||
| 1084 | 1130 | banPermissions(); |
| 1085 | 1131 | |
| 1086 | 1132 | return; |
| 1133 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
| 1134 | + list ($user_info['permissions'], $removals) = $temp; |
|
| 1087 | 1135 | } |
| 1088 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
| 1089 | - list ($user_info['permissions'], $removals) = $temp; |
|
| 1090 | 1136 | } |
| 1091 | 1137 | |
| 1092 | 1138 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1108,23 +1154,26 @@ discard block |
||
| 1108 | 1154 | $removals = array(); |
| 1109 | 1155 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1110 | 1156 | { |
| 1111 | - if (empty($row['add_deny'])) |
|
| 1112 | - $removals[] = $row['permission']; |
|
| 1113 | - else |
|
| 1114 | - $user_info['permissions'][] = $row['permission']; |
|
| 1157 | + if (empty($row['add_deny'])) { |
|
| 1158 | + $removals[] = $row['permission']; |
|
| 1159 | + } else { |
|
| 1160 | + $user_info['permissions'][] = $row['permission']; |
|
| 1161 | + } |
|
| 1115 | 1162 | } |
| 1116 | 1163 | $smcFunc['db_free_result']($request); |
| 1117 | 1164 | |
| 1118 | - if (isset($cache_groups)) |
|
| 1119 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1165 | + if (isset($cache_groups)) { |
|
| 1166 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
| 1167 | + } |
|
| 1120 | 1168 | } |
| 1121 | 1169 | |
| 1122 | 1170 | // Get the board permissions. |
| 1123 | 1171 | if (!empty($board)) |
| 1124 | 1172 | { |
| 1125 | 1173 | // Make sure the board (if any) has been loaded by loadBoard(). |
| 1126 | - if (!isset($board_info['profile'])) |
|
| 1127 | - fatal_lang_error('no_board'); |
|
| 1174 | + if (!isset($board_info['profile'])) { |
|
| 1175 | + fatal_lang_error('no_board'); |
|
| 1176 | + } |
|
| 1128 | 1177 | |
| 1129 | 1178 | $request = $smcFunc['db_query']('', ' |
| 1130 | 1179 | SELECT permission, add_deny |
@@ -1140,20 +1189,23 @@ discard block |
||
| 1140 | 1189 | ); |
| 1141 | 1190 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1142 | 1191 | { |
| 1143 | - if (empty($row['add_deny'])) |
|
| 1144 | - $removals[] = $row['permission']; |
|
| 1145 | - else |
|
| 1146 | - $user_info['permissions'][] = $row['permission']; |
|
| 1192 | + if (empty($row['add_deny'])) { |
|
| 1193 | + $removals[] = $row['permission']; |
|
| 1194 | + } else { |
|
| 1195 | + $user_info['permissions'][] = $row['permission']; |
|
| 1196 | + } |
|
| 1147 | 1197 | } |
| 1148 | 1198 | $smcFunc['db_free_result']($request); |
| 1149 | 1199 | } |
| 1150 | 1200 | |
| 1151 | 1201 | // Remove all the permissions they shouldn't have ;). |
| 1152 | - if (!empty($modSettings['permission_enable_deny'])) |
|
| 1153 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1202 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
| 1203 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
| 1204 | + } |
|
| 1154 | 1205 | |
| 1155 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
| 1156 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1206 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
| 1207 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
| 1208 | + } |
|
| 1157 | 1209 | |
| 1158 | 1210 | // Banned? Watch, don't touch.. |
| 1159 | 1211 | banPermissions(); |
@@ -1165,17 +1217,18 @@ discard block |
||
| 1165 | 1217 | { |
| 1166 | 1218 | require_once($sourcedir . '/Subs-Auth.php'); |
| 1167 | 1219 | rebuildModCache(); |
| 1220 | + } else { |
|
| 1221 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1168 | 1222 | } |
| 1169 | - else |
|
| 1170 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
| 1171 | 1223 | |
| 1172 | 1224 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
| 1173 | 1225 | // For example this drastically simplifies certain changes to the profile area. |
| 1174 | 1226 | $user_info['permissions'][] = 'is_not_guest'; |
| 1175 | 1227 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
| 1176 | 1228 | $user_info['permissions'][] = 'profile_view_own'; |
| 1177 | - if (in_array('profile_view', $user_info['permissions'])) |
|
| 1178 | - $user_info['permissions'][] = 'profile_view_any'; |
|
| 1229 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
| 1230 | + $user_info['permissions'][] = 'profile_view_any'; |
|
| 1231 | + } |
|
| 1179 | 1232 | } |
| 1180 | 1233 | } |
| 1181 | 1234 | |
@@ -1193,8 +1246,9 @@ discard block |
||
| 1193 | 1246 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
| 1194 | 1247 | |
| 1195 | 1248 | // Can't just look for no users :P. |
| 1196 | - if (empty($users)) |
|
| 1197 | - return array(); |
|
| 1249 | + if (empty($users)) { |
|
| 1250 | + return array(); |
|
| 1251 | + } |
|
| 1198 | 1252 | |
| 1199 | 1253 | // Pass the set value |
| 1200 | 1254 | $context['loadMemberContext_set'] = $set; |
@@ -1209,8 +1263,9 @@ discard block |
||
| 1209 | 1263 | for ($i = 0, $n = count($users); $i < $n; $i++) |
| 1210 | 1264 | { |
| 1211 | 1265 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
| 1212 | - if ($data == null) |
|
| 1213 | - continue; |
|
| 1266 | + if ($data == null) { |
|
| 1267 | + continue; |
|
| 1268 | + } |
|
| 1214 | 1269 | |
| 1215 | 1270 | $loaded_ids[] = $data['id_member']; |
| 1216 | 1271 | $user_profile[$data['id_member']] = $data; |
@@ -1277,13 +1332,16 @@ discard block |
||
| 1277 | 1332 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
| 1278 | 1333 | |
| 1279 | 1334 | // Take care of proxying avatar if required, do this here for maximum reach |
| 1280 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
| 1281 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1335 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
| 1336 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
| 1337 | + } |
|
| 1282 | 1338 | |
| 1283 | - if (isset($row['member_ip'])) |
|
| 1284 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1285 | - if (isset($row['member_ip2'])) |
|
| 1286 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1339 | + if (isset($row['member_ip'])) { |
|
| 1340 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
| 1341 | + } |
|
| 1342 | + if (isset($row['member_ip2'])) { |
|
| 1343 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
| 1344 | + } |
|
| 1287 | 1345 | $new_loaded_ids[] = $row['id_member']; |
| 1288 | 1346 | $loaded_ids[] = $row['id_member']; |
| 1289 | 1347 | $row['options'] = array(); |
@@ -1302,8 +1360,9 @@ discard block |
||
| 1302 | 1360 | 'loaded_ids' => $new_loaded_ids, |
| 1303 | 1361 | ) |
| 1304 | 1362 | ); |
| 1305 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1306 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1363 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1364 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
| 1365 | + } |
|
| 1307 | 1366 | $smcFunc['db_free_result']($request); |
| 1308 | 1367 | } |
| 1309 | 1368 | |
@@ -1314,10 +1373,11 @@ discard block |
||
| 1314 | 1373 | { |
| 1315 | 1374 | foreach ($loaded_ids as $a_member) |
| 1316 | 1375 | { |
| 1317 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
| 1318 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1319 | - else |
|
| 1320 | - $groups = array($user_profile[$a_member]['id_group']); |
|
| 1376 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
| 1377 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
| 1378 | + } else { |
|
| 1379 | + $groups = array($user_profile[$a_member]['id_group']); |
|
| 1380 | + } |
|
| 1321 | 1381 | |
| 1322 | 1382 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
| 1323 | 1383 | |
@@ -1330,8 +1390,9 @@ discard block |
||
| 1330 | 1390 | |
| 1331 | 1391 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
| 1332 | 1392 | { |
| 1333 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
| 1334 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1393 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
| 1394 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
| 1395 | + } |
|
| 1335 | 1396 | } |
| 1336 | 1397 | |
| 1337 | 1398 | // Are we loading any moderators? If so, fix their group data... |
@@ -1357,14 +1418,17 @@ discard block |
||
| 1357 | 1418 | foreach ($temp_mods as $id) |
| 1358 | 1419 | { |
| 1359 | 1420 | // By popular demand, don't show admins or global moderators as moderators. |
| 1360 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
| 1361 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1421 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
| 1422 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
| 1423 | + } |
|
| 1362 | 1424 | |
| 1363 | 1425 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
| 1364 | - if (!empty($row['icons'])) |
|
| 1365 | - $user_profile[$id]['icons'] = $row['icons']; |
|
| 1366 | - if (!empty($row['member_group_color'])) |
|
| 1367 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1426 | + if (!empty($row['icons'])) { |
|
| 1427 | + $user_profile[$id]['icons'] = $row['icons']; |
|
| 1428 | + } |
|
| 1429 | + if (!empty($row['member_group_color'])) { |
|
| 1430 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
| 1431 | + } |
|
| 1368 | 1432 | } |
| 1369 | 1433 | } |
| 1370 | 1434 | |
@@ -1386,12 +1450,14 @@ discard block |
||
| 1386 | 1450 | static $loadedLanguages = array(); |
| 1387 | 1451 | |
| 1388 | 1452 | // If this person's data is already loaded, skip it. |
| 1389 | - if (isset($dataLoaded[$user])) |
|
| 1390 | - return true; |
|
| 1453 | + if (isset($dataLoaded[$user])) { |
|
| 1454 | + return true; |
|
| 1455 | + } |
|
| 1391 | 1456 | |
| 1392 | 1457 | // We can't load guests or members not loaded by loadMemberData()! |
| 1393 | - if ($user == 0) |
|
| 1394 | - return false; |
|
| 1458 | + if ($user == 0) { |
|
| 1459 | + return false; |
|
| 1460 | + } |
|
| 1395 | 1461 | if (!isset($user_profile[$user])) |
| 1396 | 1462 | { |
| 1397 | 1463 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1417,12 +1483,16 @@ discard block |
||
| 1417 | 1483 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
| 1418 | 1484 | |
| 1419 | 1485 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
| 1420 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
| 1486 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
| 1487 | + //icon is set and exists |
|
| 1421 | 1488 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1422 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
| 1489 | + } elseif (isset($profile['icons'][1])) { |
|
| 1490 | + //icon is set and doesn't exist, fallback to default |
|
| 1423 | 1491 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
| 1424 | - else //not set, bye bye |
|
| 1492 | + } else { |
|
| 1493 | + //not set, bye bye |
|
| 1425 | 1494 | $group_icon_url = ''; |
| 1495 | + } |
|
| 1426 | 1496 | |
| 1427 | 1497 | // These minimal values are always loaded |
| 1428 | 1498 | $memberContext[$user] = array( |
@@ -1441,8 +1511,9 @@ discard block |
||
| 1441 | 1511 | if ($context['loadMemberContext_set'] != 'minimal') |
| 1442 | 1512 | { |
| 1443 | 1513 | // Go the extra mile and load the user's native language name. |
| 1444 | - if (empty($loadedLanguages)) |
|
| 1445 | - $loadedLanguages = getLanguages(); |
|
| 1514 | + if (empty($loadedLanguages)) { |
|
| 1515 | + $loadedLanguages = getLanguages(); |
|
| 1516 | + } |
|
| 1446 | 1517 | |
| 1447 | 1518 | $memberContext[$user] += array( |
| 1448 | 1519 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1496,31 +1567,33 @@ discard block |
||
| 1496 | 1567 | { |
| 1497 | 1568 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
| 1498 | 1569 | { |
| 1499 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
| 1500 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1501 | - else |
|
| 1502 | - $image = get_gravatar_url($profile['email_address']); |
|
| 1503 | - } |
|
| 1504 | - else |
|
| 1570 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
| 1571 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
| 1572 | + } else { |
|
| 1573 | + $image = get_gravatar_url($profile['email_address']); |
|
| 1574 | + } |
|
| 1575 | + } else |
|
| 1505 | 1576 | { |
| 1506 | 1577 | // So it's stored in the member table? |
| 1507 | 1578 | if (!empty($profile['avatar'])) |
| 1508 | 1579 | { |
| 1509 | 1580 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
| 1581 | + } elseif (!empty($profile['filename'])) { |
|
| 1582 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1510 | 1583 | } |
| 1511 | - elseif (!empty($profile['filename'])) |
|
| 1512 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
| 1513 | 1584 | // Right... no avatar...use the default one |
| 1514 | - else |
|
| 1515 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1585 | + else { |
|
| 1586 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 1587 | + } |
|
| 1516 | 1588 | } |
| 1517 | - if (!empty($image)) |
|
| 1518 | - $memberContext[$user]['avatar'] = array( |
|
| 1589 | + if (!empty($image)) { |
|
| 1590 | + $memberContext[$user]['avatar'] = array( |
|
| 1519 | 1591 | 'name' => $profile['avatar'], |
| 1520 | 1592 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
| 1521 | 1593 | 'href' => $image, |
| 1522 | 1594 | 'url' => $image, |
| 1523 | 1595 | ); |
| 1596 | + } |
|
| 1524 | 1597 | } |
| 1525 | 1598 | |
| 1526 | 1599 | // Are we also loading the members custom fields into context? |
@@ -1528,35 +1601,41 @@ discard block |
||
| 1528 | 1601 | { |
| 1529 | 1602 | $memberContext[$user]['custom_fields'] = array(); |
| 1530 | 1603 | |
| 1531 | - if (!isset($context['display_fields'])) |
|
| 1532 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1604 | + if (!isset($context['display_fields'])) { |
|
| 1605 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
| 1606 | + } |
|
| 1533 | 1607 | |
| 1534 | 1608 | foreach ($context['display_fields'] as $custom) |
| 1535 | 1609 | { |
| 1536 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
| 1537 | - continue; |
|
| 1610 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
| 1611 | + continue; |
|
| 1612 | + } |
|
| 1538 | 1613 | |
| 1539 | 1614 | $value = $profile['options'][$custom['col_name']]; |
| 1540 | 1615 | |
| 1541 | 1616 | // Don't show the "disabled" option for the "gender" field. |
| 1542 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
| 1543 | - continue; |
|
| 1617 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
| 1618 | + continue; |
|
| 1619 | + } |
|
| 1544 | 1620 | |
| 1545 | 1621 | // BBC? |
| 1546 | - if ($custom['bbc']) |
|
| 1547 | - $value = parse_bbc($value); |
|
| 1622 | + if ($custom['bbc']) { |
|
| 1623 | + $value = parse_bbc($value); |
|
| 1624 | + } |
|
| 1548 | 1625 | // ... or checkbox? |
| 1549 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
| 1550 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1626 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
| 1627 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
| 1628 | + } |
|
| 1551 | 1629 | |
| 1552 | 1630 | // Enclosing the user input within some other text? |
| 1553 | - if (!empty($custom['enclose'])) |
|
| 1554 | - $value = strtr($custom['enclose'], array( |
|
| 1631 | + if (!empty($custom['enclose'])) { |
|
| 1632 | + $value = strtr($custom['enclose'], array( |
|
| 1555 | 1633 | '{SCRIPTURL}' => $scripturl, |
| 1556 | 1634 | '{IMAGES_URL}' => $settings['images_url'], |
| 1557 | 1635 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1558 | 1636 | '{INPUT}' => $value, |
| 1559 | 1637 | )); |
| 1638 | + } |
|
| 1560 | 1639 | |
| 1561 | 1640 | $memberContext[$user]['custom_fields'][] = array( |
| 1562 | 1641 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1583,8 +1662,9 @@ discard block |
||
| 1583 | 1662 | global $smcFunc, $txt, $scripturl, $settings; |
| 1584 | 1663 | |
| 1585 | 1664 | // Do not waste my time... |
| 1586 | - if (empty($users) || empty($params)) |
|
| 1587 | - return false; |
|
| 1665 | + if (empty($users) || empty($params)) { |
|
| 1666 | + return false; |
|
| 1667 | + } |
|
| 1588 | 1668 | |
| 1589 | 1669 | // Make sure it's an array. |
| 1590 | 1670 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1608,31 +1688,36 @@ discard block |
||
| 1608 | 1688 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1609 | 1689 | { |
| 1610 | 1690 | // BBC? |
| 1611 | - if (!empty($row['bbc'])) |
|
| 1612 | - $row['value'] = parse_bbc($row['value']); |
|
| 1691 | + if (!empty($row['bbc'])) { |
|
| 1692 | + $row['value'] = parse_bbc($row['value']); |
|
| 1693 | + } |
|
| 1613 | 1694 | |
| 1614 | 1695 | // ... or checkbox? |
| 1615 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
| 1616 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1696 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
| 1697 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
| 1698 | + } |
|
| 1617 | 1699 | |
| 1618 | 1700 | // Enclosing the user input within some other text? |
| 1619 | - if (!empty($row['enclose'])) |
|
| 1620 | - $row['value'] = strtr($row['enclose'], array( |
|
| 1701 | + if (!empty($row['enclose'])) { |
|
| 1702 | + $row['value'] = strtr($row['enclose'], array( |
|
| 1621 | 1703 | '{SCRIPTURL}' => $scripturl, |
| 1622 | 1704 | '{IMAGES_URL}' => $settings['images_url'], |
| 1623 | 1705 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1624 | 1706 | '{INPUT}' => un_htmlspecialchars($row['value']), |
| 1625 | 1707 | )); |
| 1708 | + } |
|
| 1626 | 1709 | |
| 1627 | 1710 | // Send a simple array if there is just 1 param |
| 1628 | - if (count($params) == 1) |
|
| 1629 | - $return[$row['id_member']] = $row; |
|
| 1711 | + if (count($params) == 1) { |
|
| 1712 | + $return[$row['id_member']] = $row; |
|
| 1713 | + } |
|
| 1630 | 1714 | |
| 1631 | 1715 | // More than 1? knock yourself out... |
| 1632 | 1716 | else |
| 1633 | 1717 | { |
| 1634 | - if (!isset($return[$row['id_member']])) |
|
| 1635 | - $return[$row['id_member']] = array(); |
|
| 1718 | + if (!isset($return[$row['id_member']])) { |
|
| 1719 | + $return[$row['id_member']] = array(); |
|
| 1720 | + } |
|
| 1636 | 1721 | |
| 1637 | 1722 | $return[$row['id_member']][$row['variable']] = $row; |
| 1638 | 1723 | } |
@@ -1666,8 +1751,9 @@ discard block |
||
| 1666 | 1751 | global $context; |
| 1667 | 1752 | |
| 1668 | 1753 | // Don't know any browser! |
| 1669 | - if (empty($context['browser'])) |
|
| 1670 | - detectBrowser(); |
|
| 1754 | + if (empty($context['browser'])) { |
|
| 1755 | + detectBrowser(); |
|
| 1756 | + } |
|
| 1671 | 1757 | |
| 1672 | 1758 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
| 1673 | 1759 | } |
@@ -1685,8 +1771,9 @@ discard block |
||
| 1685 | 1771 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
| 1686 | 1772 | |
| 1687 | 1773 | // The theme was specified by parameter. |
| 1688 | - if (!empty($id_theme)) |
|
| 1689 | - $id_theme = (int) $id_theme; |
|
| 1774 | + if (!empty($id_theme)) { |
|
| 1775 | + $id_theme = (int) $id_theme; |
|
| 1776 | + } |
|
| 1690 | 1777 | // The theme was specified by REQUEST. |
| 1691 | 1778 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
| 1692 | 1779 | { |
@@ -1694,51 +1781,58 @@ discard block |
||
| 1694 | 1781 | $_SESSION['id_theme'] = $id_theme; |
| 1695 | 1782 | } |
| 1696 | 1783 | // The theme was specified by REQUEST... previously. |
| 1697 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
| 1698 | - $id_theme = (int) $_SESSION['id_theme']; |
|
| 1784 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
| 1785 | + $id_theme = (int) $_SESSION['id_theme']; |
|
| 1786 | + } |
|
| 1699 | 1787 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
| 1700 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
| 1701 | - $id_theme = $user_info['theme']; |
|
| 1788 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
| 1789 | + $id_theme = $user_info['theme']; |
|
| 1790 | + } |
|
| 1702 | 1791 | // The theme was specified by the board. |
| 1703 | - elseif (!empty($board_info['theme'])) |
|
| 1704 | - $id_theme = $board_info['theme']; |
|
| 1792 | + elseif (!empty($board_info['theme'])) { |
|
| 1793 | + $id_theme = $board_info['theme']; |
|
| 1794 | + } |
|
| 1705 | 1795 | // The theme is the forum's default. |
| 1706 | - else |
|
| 1707 | - $id_theme = $modSettings['theme_guests']; |
|
| 1796 | + else { |
|
| 1797 | + $id_theme = $modSettings['theme_guests']; |
|
| 1798 | + } |
|
| 1708 | 1799 | |
| 1709 | 1800 | // Verify the id_theme... no foul play. |
| 1710 | 1801 | // Always allow the board specific theme, if they are overriding. |
| 1711 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
| 1712 | - $id_theme = $board_info['theme']; |
|
| 1802 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
| 1803 | + $id_theme = $board_info['theme']; |
|
| 1804 | + } |
|
| 1713 | 1805 | // If they have specified a particular theme to use with SSI allow it to be used. |
| 1714 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
| 1715 | - $id_theme = (int) $id_theme; |
|
| 1716 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1806 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
| 1807 | + $id_theme = (int) $id_theme; |
|
| 1808 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
| 1717 | 1809 | { |
| 1718 | 1810 | $themes = explode(',', $modSettings['enableThemes']); |
| 1719 | - if (!in_array($id_theme, $themes)) |
|
| 1720 | - $id_theme = $modSettings['theme_guests']; |
|
| 1721 | - else |
|
| 1811 | + if (!in_array($id_theme, $themes)) { |
|
| 1812 | + $id_theme = $modSettings['theme_guests']; |
|
| 1813 | + } else { |
|
| 1814 | + $id_theme = (int) $id_theme; |
|
| 1815 | + } |
|
| 1816 | + } else { |
|
| 1722 | 1817 | $id_theme = (int) $id_theme; |
| 1723 | 1818 | } |
| 1724 | - else |
|
| 1725 | - $id_theme = (int) $id_theme; |
|
| 1726 | 1819 | |
| 1727 | 1820 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
| 1728 | 1821 | |
| 1729 | 1822 | // Disable image proxy if we don't have SSL enabled |
| 1730 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
| 1731 | - $image_proxy_enabled = false; |
|
| 1823 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
| 1824 | + $image_proxy_enabled = false; |
|
| 1825 | + } |
|
| 1732 | 1826 | |
| 1733 | 1827 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
| 1734 | 1828 | { |
| 1735 | 1829 | $themeData = $temp; |
| 1736 | 1830 | $flag = true; |
| 1831 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
| 1832 | + $themeData = $temp + array($member => array()); |
|
| 1833 | + } else { |
|
| 1834 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1737 | 1835 | } |
| 1738 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
| 1739 | - $themeData = $temp + array($member => array()); |
|
| 1740 | - else |
|
| 1741 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
| 1742 | 1836 | |
| 1743 | 1837 | if (empty($flag)) |
| 1744 | 1838 | { |
@@ -1757,31 +1851,37 @@ discard block |
||
| 1757 | 1851 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1758 | 1852 | { |
| 1759 | 1853 | // There are just things we shouldn't be able to change as members. |
| 1760 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
| 1761 | - continue; |
|
| 1854 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
| 1855 | + continue; |
|
| 1856 | + } |
|
| 1762 | 1857 | |
| 1763 | 1858 | // If this is the theme_dir of the default theme, store it. |
| 1764 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
| 1765 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1859 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
| 1860 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
| 1861 | + } |
|
| 1766 | 1862 | |
| 1767 | 1863 | // If this isn't set yet, is a theme option, or is not the default theme.. |
| 1768 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
| 1769 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1864 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
| 1865 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
| 1866 | + } |
|
| 1770 | 1867 | } |
| 1771 | 1868 | $smcFunc['db_free_result']($result); |
| 1772 | 1869 | |
| 1773 | - if (!empty($themeData[-1])) |
|
| 1774 | - foreach ($themeData[-1] as $k => $v) |
|
| 1870 | + if (!empty($themeData[-1])) { |
|
| 1871 | + foreach ($themeData[-1] as $k => $v) |
|
| 1775 | 1872 | { |
| 1776 | 1873 | if (!isset($themeData[$member][$k])) |
| 1777 | 1874 | $themeData[$member][$k] = $v; |
| 1875 | + } |
|
| 1778 | 1876 | } |
| 1779 | 1877 | |
| 1780 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 1781 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1878 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 1879 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
| 1880 | + } |
|
| 1782 | 1881 | // Only if we didn't already load that part of the cache... |
| 1783 | - elseif (!isset($temp)) |
|
| 1784 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1882 | + elseif (!isset($temp)) { |
|
| 1883 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
| 1884 | + } |
|
| 1785 | 1885 | } |
| 1786 | 1886 | |
| 1787 | 1887 | $settings = $themeData[0]; |
@@ -1798,20 +1898,24 @@ discard block |
||
| 1798 | 1898 | $settings['template_dirs'][] = $settings['theme_dir']; |
| 1799 | 1899 | |
| 1800 | 1900 | // Based on theme (if there is one). |
| 1801 | - if (!empty($settings['base_theme_dir'])) |
|
| 1802 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1901 | + if (!empty($settings['base_theme_dir'])) { |
|
| 1902 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
| 1903 | + } |
|
| 1803 | 1904 | |
| 1804 | 1905 | // Lastly the default theme. |
| 1805 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
| 1806 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1906 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
| 1907 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
| 1908 | + } |
|
| 1807 | 1909 | |
| 1808 | - if (!$initialize) |
|
| 1809 | - return; |
|
| 1910 | + if (!$initialize) { |
|
| 1911 | + return; |
|
| 1912 | + } |
|
| 1810 | 1913 | |
| 1811 | 1914 | // Check to see if we're forcing SSL |
| 1812 | 1915 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
| 1813 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
| 1814 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1916 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
| 1917 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
| 1918 | + } |
|
| 1815 | 1919 | |
| 1816 | 1920 | // Check to see if they're accessing it from the wrong place. |
| 1817 | 1921 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1819,8 +1923,9 @@ discard block |
||
| 1819 | 1923 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
| 1820 | 1924 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
| 1821 | 1925 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
| 1822 | - if ($temp != '/') |
|
| 1823 | - $detected_url .= $temp; |
|
| 1926 | + if ($temp != '/') { |
|
| 1927 | + $detected_url .= $temp; |
|
| 1928 | + } |
|
| 1824 | 1929 | } |
| 1825 | 1930 | if (isset($detected_url) && $detected_url != $boardurl) |
| 1826 | 1931 | { |
@@ -1832,8 +1937,9 @@ discard block |
||
| 1832 | 1937 | foreach ($aliases as $alias) |
| 1833 | 1938 | { |
| 1834 | 1939 | // Rip off all the boring parts, spaces, etc. |
| 1835 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
| 1836 | - $do_fix = true; |
|
| 1940 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
| 1941 | + $do_fix = true; |
|
| 1942 | + } |
|
| 1837 | 1943 | } |
| 1838 | 1944 | } |
| 1839 | 1945 | |
@@ -1841,20 +1947,22 @@ discard block |
||
| 1841 | 1947 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
| 1842 | 1948 | { |
| 1843 | 1949 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
| 1844 | - if (empty($_GET)) |
|
| 1845 | - redirectexit('wwwRedirect'); |
|
| 1846 | - else |
|
| 1950 | + if (empty($_GET)) { |
|
| 1951 | + redirectexit('wwwRedirect'); |
|
| 1952 | + } else |
|
| 1847 | 1953 | { |
| 1848 | 1954 | list ($k, $v) = each($_GET); |
| 1849 | 1955 | |
| 1850 | - if ($k != 'wwwRedirect') |
|
| 1851 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1956 | + if ($k != 'wwwRedirect') { |
|
| 1957 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
| 1958 | + } |
|
| 1852 | 1959 | } |
| 1853 | 1960 | } |
| 1854 | 1961 | |
| 1855 | 1962 | // #3 is just a check for SSL... |
| 1856 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
| 1857 | - $do_fix = true; |
|
| 1963 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
| 1964 | + $do_fix = true; |
|
| 1965 | + } |
|
| 1858 | 1966 | |
| 1859 | 1967 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
| 1860 | 1968 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1888,8 +1996,9 @@ discard block |
||
| 1888 | 1996 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
| 1889 | 1997 | } |
| 1890 | 1998 | } |
| 1891 | - foreach ($context['linktree'] as $k => $dummy) |
|
| 1892 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 1999 | + foreach ($context['linktree'] as $k => $dummy) { |
|
| 2000 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
| 2001 | + } |
|
| 1893 | 2002 | } |
| 1894 | 2003 | } |
| 1895 | 2004 | // Set up the contextual user array. |
@@ -1908,16 +2017,16 @@ discard block |
||
| 1908 | 2017 | 'email' => $user_info['email'], |
| 1909 | 2018 | 'ignoreusers' => $user_info['ignoreusers'], |
| 1910 | 2019 | ); |
| 1911 | - if (!$context['user']['is_guest']) |
|
| 1912 | - $context['user']['name'] = $user_info['name']; |
|
| 1913 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
| 1914 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2020 | + if (!$context['user']['is_guest']) { |
|
| 2021 | + $context['user']['name'] = $user_info['name']; |
|
| 2022 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
| 2023 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2024 | + } |
|
| 1915 | 2025 | |
| 1916 | 2026 | // Determine the current smiley set. |
| 1917 | 2027 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
| 1918 | 2028 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
| 1919 | - } |
|
| 1920 | - else |
|
| 2029 | + } else |
|
| 1921 | 2030 | { |
| 1922 | 2031 | $context['user'] = array( |
| 1923 | 2032 | 'id' => -1, |
@@ -1933,18 +2042,24 @@ discard block |
||
| 1933 | 2042 | } |
| 1934 | 2043 | |
| 1935 | 2044 | // Some basic information... |
| 1936 | - if (!isset($context['html_headers'])) |
|
| 1937 | - $context['html_headers'] = ''; |
|
| 1938 | - if (!isset($context['javascript_files'])) |
|
| 1939 | - $context['javascript_files'] = array(); |
|
| 1940 | - if (!isset($context['css_files'])) |
|
| 1941 | - $context['css_files'] = array(); |
|
| 1942 | - if (!isset($context['css_header'])) |
|
| 1943 | - $context['css_header'] = array(); |
|
| 1944 | - if (!isset($context['javascript_inline'])) |
|
| 1945 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 1946 | - if (!isset($context['javascript_vars'])) |
|
| 1947 | - $context['javascript_vars'] = array(); |
|
| 2045 | + if (!isset($context['html_headers'])) { |
|
| 2046 | + $context['html_headers'] = ''; |
|
| 2047 | + } |
|
| 2048 | + if (!isset($context['javascript_files'])) { |
|
| 2049 | + $context['javascript_files'] = array(); |
|
| 2050 | + } |
|
| 2051 | + if (!isset($context['css_files'])) { |
|
| 2052 | + $context['css_files'] = array(); |
|
| 2053 | + } |
|
| 2054 | + if (!isset($context['css_header'])) { |
|
| 2055 | + $context['css_header'] = array(); |
|
| 2056 | + } |
|
| 2057 | + if (!isset($context['javascript_inline'])) { |
|
| 2058 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
| 2059 | + } |
|
| 2060 | + if (!isset($context['javascript_vars'])) { |
|
| 2061 | + $context['javascript_vars'] = array(); |
|
| 2062 | + } |
|
| 1948 | 2063 | |
| 1949 | 2064 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
| 1950 | 2065 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1956,8 +2071,9 @@ discard block |
||
| 1956 | 2071 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
| 1957 | 2072 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
| 1958 | 2073 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
| 1959 | - if (isset($modSettings['load_average'])) |
|
| 1960 | - $context['load_average'] = $modSettings['load_average']; |
|
| 2074 | + if (isset($modSettings['load_average'])) { |
|
| 2075 | + $context['load_average'] = $modSettings['load_average']; |
|
| 2076 | + } |
|
| 1961 | 2077 | |
| 1962 | 2078 | // Detect the browser. This is separated out because it's also used in attachment downloads |
| 1963 | 2079 | detectBrowser(); |
@@ -1971,8 +2087,9 @@ discard block |
||
| 1971 | 2087 | // This allows sticking some HTML on the page output - useful for controls. |
| 1972 | 2088 | $context['insert_after_template'] = ''; |
| 1973 | 2089 | |
| 1974 | - if (!isset($txt)) |
|
| 1975 | - $txt = array(); |
|
| 2090 | + if (!isset($txt)) { |
|
| 2091 | + $txt = array(); |
|
| 2092 | + } |
|
| 1976 | 2093 | |
| 1977 | 2094 | $simpleActions = array( |
| 1978 | 2095 | 'findmember', |
@@ -2018,9 +2135,10 @@ discard block |
||
| 2018 | 2135 | |
| 2019 | 2136 | // See if theres any extra param to check. |
| 2020 | 2137 | $requiresXML = false; |
| 2021 | - foreach ($extraParams as $key => $extra) |
|
| 2022 | - if (isset($_REQUEST[$extra])) |
|
| 2138 | + foreach ($extraParams as $key => $extra) { |
|
| 2139 | + if (isset($_REQUEST[$extra])) |
|
| 2023 | 2140 | $requiresXML = true; |
| 2141 | + } |
|
| 2024 | 2142 | |
| 2025 | 2143 | // Output is fully XML, so no need for the index template. |
| 2026 | 2144 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2035,37 +2153,39 @@ discard block |
||
| 2035 | 2153 | { |
| 2036 | 2154 | loadLanguage('index+Modifications'); |
| 2037 | 2155 | $context['template_layers'] = array(); |
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - else |
|
| 2156 | + } else |
|
| 2041 | 2157 | { |
| 2042 | 2158 | // Custom templates to load, or just default? |
| 2043 | - if (isset($settings['theme_templates'])) |
|
| 2044 | - $templates = explode(',', $settings['theme_templates']); |
|
| 2045 | - else |
|
| 2046 | - $templates = array('index'); |
|
| 2159 | + if (isset($settings['theme_templates'])) { |
|
| 2160 | + $templates = explode(',', $settings['theme_templates']); |
|
| 2161 | + } else { |
|
| 2162 | + $templates = array('index'); |
|
| 2163 | + } |
|
| 2047 | 2164 | |
| 2048 | 2165 | // Load each template... |
| 2049 | - foreach ($templates as $template) |
|
| 2050 | - loadTemplate($template); |
|
| 2166 | + foreach ($templates as $template) { |
|
| 2167 | + loadTemplate($template); |
|
| 2168 | + } |
|
| 2051 | 2169 | |
| 2052 | 2170 | // ...and attempt to load their associated language files. |
| 2053 | 2171 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
| 2054 | 2172 | loadLanguage($required_files, '', false); |
| 2055 | 2173 | |
| 2056 | 2174 | // Custom template layers? |
| 2057 | - if (isset($settings['theme_layers'])) |
|
| 2058 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2059 | - else |
|
| 2060 | - $context['template_layers'] = array('html', 'body'); |
|
| 2175 | + if (isset($settings['theme_layers'])) { |
|
| 2176 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
| 2177 | + } else { |
|
| 2178 | + $context['template_layers'] = array('html', 'body'); |
|
| 2179 | + } |
|
| 2061 | 2180 | } |
| 2062 | 2181 | |
| 2063 | 2182 | // Initialize the theme. |
| 2064 | 2183 | loadSubTemplate('init', 'ignore'); |
| 2065 | 2184 | |
| 2066 | 2185 | // Allow overriding the board wide time/number formats. |
| 2067 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
| 2068 | - $user_info['time_format'] = $txt['time_format']; |
|
| 2186 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
| 2187 | + $user_info['time_format'] = $txt['time_format']; |
|
| 2188 | + } |
|
| 2069 | 2189 | |
| 2070 | 2190 | // Set the character set from the template. |
| 2071 | 2191 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2073,12 +2193,14 @@ discard block |
||
| 2073 | 2193 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
| 2074 | 2194 | |
| 2075 | 2195 | // Guests may still need a name. |
| 2076 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
| 2077 | - $context['user']['name'] = $txt['guest_title']; |
|
| 2196 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
| 2197 | + $context['user']['name'] = $txt['guest_title']; |
|
| 2198 | + } |
|
| 2078 | 2199 | |
| 2079 | 2200 | // Any theme-related strings that need to be loaded? |
| 2080 | - if (!empty($settings['require_theme_strings'])) |
|
| 2081 | - loadLanguage('ThemeStrings', '', false); |
|
| 2201 | + if (!empty($settings['require_theme_strings'])) { |
|
| 2202 | + loadLanguage('ThemeStrings', '', false); |
|
| 2203 | + } |
|
| 2082 | 2204 | |
| 2083 | 2205 | // Make a special URL for the language. |
| 2084 | 2206 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2089,8 +2211,9 @@ discard block |
||
| 2089 | 2211 | // Here is my luvly Responsive CSS |
| 2090 | 2212 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
| 2091 | 2213 | |
| 2092 | - if ($context['right_to_left']) |
|
| 2093 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2214 | + if ($context['right_to_left']) { |
|
| 2215 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
| 2216 | + } |
|
| 2094 | 2217 | |
| 2095 | 2218 | // We allow theme variants, because we're cool. |
| 2096 | 2219 | $context['theme_variant'] = ''; |
@@ -2098,14 +2221,17 @@ discard block |
||
| 2098 | 2221 | if (!empty($settings['theme_variants'])) |
| 2099 | 2222 | { |
| 2100 | 2223 | // Overriding - for previews and that ilk. |
| 2101 | - if (!empty($_REQUEST['variant'])) |
|
| 2102 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2224 | + if (!empty($_REQUEST['variant'])) { |
|
| 2225 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
| 2226 | + } |
|
| 2103 | 2227 | // User selection? |
| 2104 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
| 2105 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2228 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
| 2229 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
| 2230 | + } |
|
| 2106 | 2231 | // If not a user variant, select the default. |
| 2107 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
| 2108 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2232 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
| 2233 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
| 2234 | + } |
|
| 2109 | 2235 | |
| 2110 | 2236 | // Do this to keep things easier in the templates. |
| 2111 | 2237 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2114,20 +2240,23 @@ discard block |
||
| 2114 | 2240 | if (!empty($context['theme_variant'])) |
| 2115 | 2241 | { |
| 2116 | 2242 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
| 2117 | - if ($context['right_to_left']) |
|
| 2118 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2243 | + if ($context['right_to_left']) { |
|
| 2244 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
| 2245 | + } |
|
| 2119 | 2246 | } |
| 2120 | 2247 | } |
| 2121 | 2248 | |
| 2122 | 2249 | // Let's be compatible with old themes! |
| 2123 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
| 2124 | - $context['template_layers'] = array('main'); |
|
| 2250 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
| 2251 | + $context['template_layers'] = array('main'); |
|
| 2252 | + } |
|
| 2125 | 2253 | |
| 2126 | 2254 | $context['tabindex'] = 1; |
| 2127 | 2255 | |
| 2128 | 2256 | // Compatibility. |
| 2129 | - if (!isset($settings['theme_version'])) |
|
| 2130 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2257 | + if (!isset($settings['theme_version'])) { |
|
| 2258 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
| 2259 | + } |
|
| 2131 | 2260 | |
| 2132 | 2261 | // Default JS variables for use in every theme |
| 2133 | 2262 | $context['javascript_vars'] = array( |
@@ -2146,18 +2275,18 @@ discard block |
||
| 2146 | 2275 | ); |
| 2147 | 2276 | |
| 2148 | 2277 | // Add the JQuery library to the list of files to load. |
| 2149 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
| 2150 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2151 | - |
|
| 2152 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
| 2153 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2154 | - |
|
| 2155 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
| 2156 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2278 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
| 2279 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2280 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
| 2281 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
| 2282 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
| 2283 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
| 2284 | + } |
|
| 2157 | 2285 | |
| 2158 | 2286 | // Auto loading? template_javascript() will take care of the local half of this. |
| 2159 | - else |
|
| 2160 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2287 | + else { |
|
| 2288 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
| 2289 | + } |
|
| 2161 | 2290 | |
| 2162 | 2291 | // Queue our JQuery plugins! |
| 2163 | 2292 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2180,12 +2309,12 @@ discard block |
||
| 2180 | 2309 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 2181 | 2310 | |
| 2182 | 2311 | // What to do, what to do?! |
| 2183 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
| 2184 | - AutoTask(); |
|
| 2185 | - else |
|
| 2186 | - ReduceMailQueue(); |
|
| 2187 | - } |
|
| 2188 | - else |
|
| 2312 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
| 2313 | + AutoTask(); |
|
| 2314 | + } else { |
|
| 2315 | + ReduceMailQueue(); |
|
| 2316 | + } |
|
| 2317 | + } else |
|
| 2189 | 2318 | { |
| 2190 | 2319 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
| 2191 | 2320 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2236,8 +2365,9 @@ discard block |
||
| 2236 | 2365 | foreach ($theme_includes as $include) |
| 2237 | 2366 | { |
| 2238 | 2367 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
| 2239 | - if (file_exists($include)) |
|
| 2240 | - require_once($include); |
|
| 2368 | + if (file_exists($include)) { |
|
| 2369 | + require_once($include); |
|
| 2370 | + } |
|
| 2241 | 2371 | } |
| 2242 | 2372 | } |
| 2243 | 2373 | |
@@ -2267,16 +2397,19 @@ discard block |
||
| 2267 | 2397 | // Do any style sheets first, cause we're easy with those. |
| 2268 | 2398 | if (!empty($style_sheets)) |
| 2269 | 2399 | { |
| 2270 | - if (!is_array($style_sheets)) |
|
| 2271 | - $style_sheets = array($style_sheets); |
|
| 2400 | + if (!is_array($style_sheets)) { |
|
| 2401 | + $style_sheets = array($style_sheets); |
|
| 2402 | + } |
|
| 2272 | 2403 | |
| 2273 | - foreach ($style_sheets as $sheet) |
|
| 2274 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2404 | + foreach ($style_sheets as $sheet) { |
|
| 2405 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
| 2406 | + } |
|
| 2275 | 2407 | } |
| 2276 | 2408 | |
| 2277 | 2409 | // No template to load? |
| 2278 | - if ($template_name === false) |
|
| 2279 | - return true; |
|
| 2410 | + if ($template_name === false) { |
|
| 2411 | + return true; |
|
| 2412 | + } |
|
| 2280 | 2413 | |
| 2281 | 2414 | $loaded = false; |
| 2282 | 2415 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2291,12 +2424,14 @@ discard block |
||
| 2291 | 2424 | |
| 2292 | 2425 | if ($loaded) |
| 2293 | 2426 | { |
| 2294 | - if ($db_show_debug === true) |
|
| 2295 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2427 | + if ($db_show_debug === true) { |
|
| 2428 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
| 2429 | + } |
|
| 2296 | 2430 | |
| 2297 | 2431 | // If they have specified an initialization function for this template, go ahead and call it now. |
| 2298 | - if (function_exists('template_' . $template_name . '_init')) |
|
| 2299 | - call_user_func('template_' . $template_name . '_init'); |
|
| 2432 | + if (function_exists('template_' . $template_name . '_init')) { |
|
| 2433 | + call_user_func('template_' . $template_name . '_init'); |
|
| 2434 | + } |
|
| 2300 | 2435 | } |
| 2301 | 2436 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
| 2302 | 2437 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2316,13 +2451,14 @@ discard block |
||
| 2316 | 2451 | loadTemplate($template_name); |
| 2317 | 2452 | } |
| 2318 | 2453 | // Cause an error otherwise. |
| 2319 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
| 2320 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2321 | - elseif ($fatal) |
|
| 2322 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2323 | - else |
|
| 2324 | - return false; |
|
| 2325 | -} |
|
| 2454 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
| 2455 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
| 2456 | + } elseif ($fatal) { |
|
| 2457 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
| 2458 | + } else { |
|
| 2459 | + return false; |
|
| 2460 | + } |
|
| 2461 | + } |
|
| 2326 | 2462 | |
| 2327 | 2463 | /** |
| 2328 | 2464 | * Load a sub-template. |
@@ -2340,17 +2476,19 @@ discard block |
||
| 2340 | 2476 | { |
| 2341 | 2477 | global $context, $txt, $db_show_debug; |
| 2342 | 2478 | |
| 2343 | - if ($db_show_debug === true) |
|
| 2344 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2479 | + if ($db_show_debug === true) { |
|
| 2480 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
| 2481 | + } |
|
| 2345 | 2482 | |
| 2346 | 2483 | // Figure out what the template function is named. |
| 2347 | 2484 | $theme_function = 'template_' . $sub_template_name; |
| 2348 | - if (function_exists($theme_function)) |
|
| 2349 | - $theme_function(); |
|
| 2350 | - elseif ($fatal === false) |
|
| 2351 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2352 | - elseif ($fatal !== 'ignore') |
|
| 2353 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2485 | + if (function_exists($theme_function)) { |
|
| 2486 | + $theme_function(); |
|
| 2487 | + } elseif ($fatal === false) { |
|
| 2488 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
| 2489 | + } elseif ($fatal !== 'ignore') { |
|
| 2490 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
| 2491 | + } |
|
| 2354 | 2492 | |
| 2355 | 2493 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
| 2356 | 2494 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2387,8 +2525,9 @@ discard block |
||
| 2387 | 2525 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2388 | 2526 | |
| 2389 | 2527 | // If this is an external file, automatically set this to false. |
| 2390 | - if (!empty($params['external'])) |
|
| 2391 | - $params['minimize'] = false; |
|
| 2528 | + if (!empty($params['external'])) { |
|
| 2529 | + $params['minimize'] = false; |
|
| 2530 | + } |
|
| 2392 | 2531 | |
| 2393 | 2532 | // Account for shorthand like admin.css?alp21 filenames |
| 2394 | 2533 | $has_seed = strpos($fileName, '.css?'); |
@@ -2405,13 +2544,10 @@ discard block |
||
| 2405 | 2544 | { |
| 2406 | 2545 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2407 | 2546 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2547 | + } else { |
|
| 2548 | + $fileUrl = false; |
|
| 2408 | 2549 | } |
| 2409 | - |
|
| 2410 | - else |
|
| 2411 | - $fileUrl = false; |
|
| 2412 | - } |
|
| 2413 | - |
|
| 2414 | - else |
|
| 2550 | + } else |
|
| 2415 | 2551 | { |
| 2416 | 2552 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2417 | 2553 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2426,12 +2562,14 @@ discard block |
||
| 2426 | 2562 | } |
| 2427 | 2563 | |
| 2428 | 2564 | // Add it to the array for use in the template |
| 2429 | - if (!empty($fileName)) |
|
| 2430 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2565 | + if (!empty($fileName)) { |
|
| 2566 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2567 | + } |
|
| 2431 | 2568 | |
| 2432 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
| 2433 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2434 | -} |
|
| 2569 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
| 2570 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2435 | 2573 | |
| 2436 | 2574 | /** |
| 2437 | 2575 | * Add a block of inline css code to be executed later |
@@ -2448,8 +2586,9 @@ discard block |
||
| 2448 | 2586 | global $context; |
| 2449 | 2587 | |
| 2450 | 2588 | // Gotta add something... |
| 2451 | - if (empty($css)) |
|
| 2452 | - return false; |
|
| 2589 | + if (empty($css)) { |
|
| 2590 | + return false; |
|
| 2591 | + } |
|
| 2453 | 2592 | |
| 2454 | 2593 | $context['css_header'][] = $css; |
| 2455 | 2594 | } |
@@ -2484,8 +2623,9 @@ discard block |
||
| 2484 | 2623 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
| 2485 | 2624 | |
| 2486 | 2625 | // If this is an external file, automatically set this to false. |
| 2487 | - if (!empty($params['external'])) |
|
| 2488 | - $params['minimize'] = false; |
|
| 2626 | + if (!empty($params['external'])) { |
|
| 2627 | + $params['minimize'] = false; |
|
| 2628 | + } |
|
| 2489 | 2629 | |
| 2490 | 2630 | // Account for shorthand like admin.js?alp21 filenames |
| 2491 | 2631 | $has_seed = strpos($fileName, '.js?'); |
@@ -2502,16 +2642,12 @@ discard block |
||
| 2502 | 2642 | { |
| 2503 | 2643 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2504 | 2644 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2505 | - } |
|
| 2506 | - |
|
| 2507 | - else |
|
| 2645 | + } else |
|
| 2508 | 2646 | { |
| 2509 | 2647 | $fileUrl = false; |
| 2510 | 2648 | $filePath = false; |
| 2511 | 2649 | } |
| 2512 | - } |
|
| 2513 | - |
|
| 2514 | - else |
|
| 2650 | + } else |
|
| 2515 | 2651 | { |
| 2516 | 2652 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
| 2517 | 2653 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2526,9 +2662,10 @@ discard block |
||
| 2526 | 2662 | } |
| 2527 | 2663 | |
| 2528 | 2664 | // Add it to the array for use in the template |
| 2529 | - if (!empty($fileName)) |
|
| 2530 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2531 | -} |
|
| 2665 | + if (!empty($fileName)) { |
|
| 2666 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
| 2667 | + } |
|
| 2668 | + } |
|
| 2532 | 2669 | |
| 2533 | 2670 | /** |
| 2534 | 2671 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2542,9 +2679,10 @@ discard block |
||
| 2542 | 2679 | { |
| 2543 | 2680 | global $context; |
| 2544 | 2681 | |
| 2545 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
| 2546 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2547 | -} |
|
| 2682 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
| 2683 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
| 2684 | + } |
|
| 2685 | + } |
|
| 2548 | 2686 | |
| 2549 | 2687 | /** |
| 2550 | 2688 | * Add a block of inline Javascript code to be executed later |
@@ -2561,8 +2699,9 @@ discard block |
||
| 2561 | 2699 | { |
| 2562 | 2700 | global $context; |
| 2563 | 2701 | |
| 2564 | - if (empty($javascript)) |
|
| 2565 | - return false; |
|
| 2702 | + if (empty($javascript)) { |
|
| 2703 | + return false; |
|
| 2704 | + } |
|
| 2566 | 2705 | |
| 2567 | 2706 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
| 2568 | 2707 | } |
@@ -2583,15 +2722,18 @@ discard block |
||
| 2583 | 2722 | static $already_loaded = array(); |
| 2584 | 2723 | |
| 2585 | 2724 | // Default to the user's language. |
| 2586 | - if ($lang == '') |
|
| 2587 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2725 | + if ($lang == '') { |
|
| 2726 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
| 2727 | + } |
|
| 2588 | 2728 | |
| 2589 | 2729 | // Do we want the English version of language file as fallback? |
| 2590 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
| 2591 | - loadLanguage($template_name, 'english', false); |
|
| 2730 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
| 2731 | + loadLanguage($template_name, 'english', false); |
|
| 2732 | + } |
|
| 2592 | 2733 | |
| 2593 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
| 2594 | - return $lang; |
|
| 2734 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
| 2735 | + return $lang; |
|
| 2736 | + } |
|
| 2595 | 2737 | |
| 2596 | 2738 | // Make sure we have $settings - if not we're in trouble and need to find it! |
| 2597 | 2739 | if (empty($settings['default_theme_dir'])) |
@@ -2602,8 +2744,9 @@ discard block |
||
| 2602 | 2744 | |
| 2603 | 2745 | // What theme are we in? |
| 2604 | 2746 | $theme_name = basename($settings['theme_url']); |
| 2605 | - if (empty($theme_name)) |
|
| 2606 | - $theme_name = 'unknown'; |
|
| 2747 | + if (empty($theme_name)) { |
|
| 2748 | + $theme_name = 'unknown'; |
|
| 2749 | + } |
|
| 2607 | 2750 | |
| 2608 | 2751 | // For each file open it up and write it out! |
| 2609 | 2752 | foreach (explode('+', $template_name) as $template) |
@@ -2645,8 +2788,9 @@ discard block |
||
| 2645 | 2788 | $found = true; |
| 2646 | 2789 | |
| 2647 | 2790 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
| 2648 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
| 2649 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2791 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
| 2792 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
| 2793 | + } |
|
| 2650 | 2794 | |
| 2651 | 2795 | break; |
| 2652 | 2796 | } |
@@ -2686,8 +2830,9 @@ discard block |
||
| 2686 | 2830 | } |
| 2687 | 2831 | |
| 2688 | 2832 | // Keep track of what we're up to soldier. |
| 2689 | - if ($db_show_debug === true) |
|
| 2690 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2833 | + if ($db_show_debug === true) { |
|
| 2834 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
| 2835 | + } |
|
| 2691 | 2836 | |
| 2692 | 2837 | // Remember what we have loaded, and in which language. |
| 2693 | 2838 | $already_loaded[$template_name] = $lang; |
@@ -2733,8 +2878,9 @@ discard block |
||
| 2733 | 2878 | ) |
| 2734 | 2879 | ); |
| 2735 | 2880 | // In the EXTREMELY unlikely event this happens, give an error message. |
| 2736 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
| 2737 | - fatal_lang_error('parent_not_found', 'critical'); |
|
| 2881 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
| 2882 | + fatal_lang_error('parent_not_found', 'critical'); |
|
| 2883 | + } |
|
| 2738 | 2884 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 2739 | 2885 | { |
| 2740 | 2886 | if (!isset($boards[$row['id_board']])) |
@@ -2751,8 +2897,8 @@ discard block |
||
| 2751 | 2897 | ); |
| 2752 | 2898 | } |
| 2753 | 2899 | // If a moderator exists for this board, add that moderator for all children too. |
| 2754 | - if (!empty($row['id_moderator'])) |
|
| 2755 | - foreach ($boards as $id => $dummy) |
|
| 2900 | + if (!empty($row['id_moderator'])) { |
|
| 2901 | + foreach ($boards as $id => $dummy) |
|
| 2756 | 2902 | { |
| 2757 | 2903 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
| 2758 | 2904 | 'id' => $row['id_moderator'], |
@@ -2760,11 +2906,12 @@ discard block |
||
| 2760 | 2906 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
| 2761 | 2907 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
| 2762 | 2908 | ); |
| 2909 | + } |
|
| 2763 | 2910 | } |
| 2764 | 2911 | |
| 2765 | 2912 | // If a moderator group exists for this board, add that moderator group for all children too |
| 2766 | - if (!empty($row['id_moderator_group'])) |
|
| 2767 | - foreach ($boards as $id => $dummy) |
|
| 2913 | + if (!empty($row['id_moderator_group'])) { |
|
| 2914 | + foreach ($boards as $id => $dummy) |
|
| 2768 | 2915 | { |
| 2769 | 2916 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
| 2770 | 2917 | 'id' => $row['id_moderator_group'], |
@@ -2772,6 +2919,7 @@ discard block |
||
| 2772 | 2919 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
| 2773 | 2920 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
| 2774 | 2921 | ); |
| 2922 | + } |
|
| 2775 | 2923 | } |
| 2776 | 2924 | } |
| 2777 | 2925 | $smcFunc['db_free_result']($result); |
@@ -2798,23 +2946,27 @@ discard block |
||
| 2798 | 2946 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
| 2799 | 2947 | { |
| 2800 | 2948 | // If we don't have our ucwords function defined yet, let's load the settings data. |
| 2801 | - if (empty($smcFunc['ucwords'])) |
|
| 2802 | - reloadSettings(); |
|
| 2949 | + if (empty($smcFunc['ucwords'])) { |
|
| 2950 | + reloadSettings(); |
|
| 2951 | + } |
|
| 2803 | 2952 | |
| 2804 | 2953 | // If we don't have our theme information yet, let's get it. |
| 2805 | - if (empty($settings['default_theme_dir'])) |
|
| 2806 | - loadTheme(0, false); |
|
| 2954 | + if (empty($settings['default_theme_dir'])) { |
|
| 2955 | + loadTheme(0, false); |
|
| 2956 | + } |
|
| 2807 | 2957 | |
| 2808 | 2958 | // Default language directories to try. |
| 2809 | 2959 | $language_directories = array( |
| 2810 | 2960 | $settings['default_theme_dir'] . '/languages', |
| 2811 | 2961 | ); |
| 2812 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
| 2813 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2962 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
| 2963 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
| 2964 | + } |
|
| 2814 | 2965 | |
| 2815 | 2966 | // We possibly have a base theme directory. |
| 2816 | - if (!empty($settings['base_theme_dir'])) |
|
| 2817 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2967 | + if (!empty($settings['base_theme_dir'])) { |
|
| 2968 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
| 2969 | + } |
|
| 2818 | 2970 | |
| 2819 | 2971 | // Remove any duplicates. |
| 2820 | 2972 | $language_directories = array_unique($language_directories); |
@@ -2828,20 +2980,21 @@ discard block |
||
| 2828 | 2980 | foreach ($language_directories as $language_dir) |
| 2829 | 2981 | { |
| 2830 | 2982 | // Can't look in here... doesn't exist! |
| 2831 | - if (!file_exists($language_dir)) |
|
| 2832 | - continue; |
|
| 2983 | + if (!file_exists($language_dir)) { |
|
| 2984 | + continue; |
|
| 2985 | + } |
|
| 2833 | 2986 | |
| 2834 | 2987 | $dir = dir($language_dir); |
| 2835 | 2988 | while ($entry = $dir->read()) |
| 2836 | 2989 | { |
| 2837 | 2990 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
| 2838 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
| 2839 | - continue; |
|
| 2840 | - |
|
| 2841 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
| 2842 | - $langName = $langList[$matches[1]]; |
|
| 2991 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
| 2992 | + continue; |
|
| 2993 | + } |
|
| 2843 | 2994 | |
| 2844 | - else |
|
| 2995 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
| 2996 | + $langName = $langList[$matches[1]]; |
|
| 2997 | + } else |
|
| 2845 | 2998 | { |
| 2846 | 2999 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
| 2847 | 3000 | |
@@ -2882,12 +3035,14 @@ discard block |
||
| 2882 | 3035 | } |
| 2883 | 3036 | |
| 2884 | 3037 | // Do we need to store the lang list? |
| 2885 | - if (empty($langList)) |
|
| 2886 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3038 | + if (empty($langList)) { |
|
| 3039 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
| 3040 | + } |
|
| 2887 | 3041 | |
| 2888 | 3042 | // Let's cash in on this deal. |
| 2889 | - if (!empty($modSettings['cache_enable'])) |
|
| 2890 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3043 | + if (!empty($modSettings['cache_enable'])) { |
|
| 3044 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
| 3045 | + } |
|
| 2891 | 3046 | } |
| 2892 | 3047 | |
| 2893 | 3048 | return $context['languages']; |
@@ -2910,8 +3065,9 @@ discard block |
||
| 2910 | 3065 | global $modSettings, $options, $txt; |
| 2911 | 3066 | static $censor_vulgar = null, $censor_proper; |
| 2912 | 3067 | |
| 2913 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
| 2914 | - return $text; |
|
| 3068 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
| 3069 | + return $text; |
|
| 3070 | + } |
|
| 2915 | 3071 | |
| 2916 | 3072 | // If they haven't yet been loaded, load them. |
| 2917 | 3073 | if ($censor_vulgar == null) |
@@ -2939,9 +3095,9 @@ discard block |
||
| 2939 | 3095 | { |
| 2940 | 3096 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
| 2941 | 3097 | $text = $func($censor_vulgar, $censor_proper, $text); |
| 3098 | + } else { |
|
| 3099 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2942 | 3100 | } |
| 2943 | - else |
|
| 2944 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
| 2945 | 3101 | |
| 2946 | 3102 | return $text; |
| 2947 | 3103 | } |
@@ -2967,38 +3123,42 @@ discard block |
||
| 2967 | 3123 | @ini_set('track_errors', '1'); |
| 2968 | 3124 | |
| 2969 | 3125 | // Don't include the file more than once, if $once is true. |
| 2970 | - if ($once && in_array($filename, $templates)) |
|
| 2971 | - return; |
|
| 3126 | + if ($once && in_array($filename, $templates)) { |
|
| 3127 | + return; |
|
| 3128 | + } |
|
| 2972 | 3129 | // Add this file to the include list, whether $once is true or not. |
| 2973 | - else |
|
| 2974 | - $templates[] = $filename; |
|
| 3130 | + else { |
|
| 3131 | + $templates[] = $filename; |
|
| 3132 | + } |
|
| 2975 | 3133 | |
| 2976 | 3134 | // Are we going to use eval? |
| 2977 | 3135 | if (empty($modSettings['disableTemplateEval'])) |
| 2978 | 3136 | { |
| 2979 | 3137 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
| 2980 | 3138 | $settings['current_include_filename'] = $filename; |
| 2981 | - } |
|
| 2982 | - else |
|
| 3139 | + } else |
|
| 2983 | 3140 | { |
| 2984 | 3141 | $file_found = file_exists($filename); |
| 2985 | 3142 | |
| 2986 | - if ($once && $file_found) |
|
| 2987 | - require_once($filename); |
|
| 2988 | - elseif ($file_found) |
|
| 2989 | - require($filename); |
|
| 3143 | + if ($once && $file_found) { |
|
| 3144 | + require_once($filename); |
|
| 3145 | + } elseif ($file_found) { |
|
| 3146 | + require($filename); |
|
| 3147 | + } |
|
| 2990 | 3148 | } |
| 2991 | 3149 | |
| 2992 | 3150 | if ($file_found !== true) |
| 2993 | 3151 | { |
| 2994 | 3152 | ob_end_clean(); |
| 2995 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
| 2996 | - @ob_start('ob_gzhandler'); |
|
| 2997 | - else |
|
| 2998 | - ob_start(); |
|
| 3153 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
| 3154 | + @ob_start('ob_gzhandler'); |
|
| 3155 | + } else { |
|
| 3156 | + ob_start(); |
|
| 3157 | + } |
|
| 2999 | 3158 | |
| 3000 | - if (isset($_GET['debug'])) |
|
| 3001 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3159 | + if (isset($_GET['debug'])) { |
|
| 3160 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
| 3161 | + } |
|
| 3002 | 3162 | |
| 3003 | 3163 | // Don't cache error pages!! |
| 3004 | 3164 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3017,12 +3177,13 @@ discard block |
||
| 3017 | 3177 | echo '<!DOCTYPE html> |
| 3018 | 3178 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
| 3019 | 3179 | <head>'; |
| 3020 | - if (isset($context['character_set'])) |
|
| 3021 | - echo ' |
|
| 3180 | + if (isset($context['character_set'])) { |
|
| 3181 | + echo ' |
|
| 3022 | 3182 | <meta charset="', $context['character_set'], '">'; |
| 3183 | + } |
|
| 3023 | 3184 | |
| 3024 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
| 3025 | - echo ' |
|
| 3185 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
| 3186 | + echo ' |
|
| 3026 | 3187 | <title>', $mtitle, '</title> |
| 3027 | 3188 | </head> |
| 3028 | 3189 | <body> |
@@ -3030,8 +3191,8 @@ discard block |
||
| 3030 | 3191 | ', $mmessage, ' |
| 3031 | 3192 | </body> |
| 3032 | 3193 | </html>'; |
| 3033 | - elseif (!allowedTo('admin_forum')) |
|
| 3034 | - echo ' |
|
| 3194 | + } elseif (!allowedTo('admin_forum')) { |
|
| 3195 | + echo ' |
|
| 3035 | 3196 | <title>', $txt['template_parse_error'], '</title> |
| 3036 | 3197 | </head> |
| 3037 | 3198 | <body> |
@@ -3039,16 +3200,18 @@ discard block |
||
| 3039 | 3200 | ', $txt['template_parse_error_message'], ' |
| 3040 | 3201 | </body> |
| 3041 | 3202 | </html>'; |
| 3042 | - else |
|
| 3203 | + } else |
|
| 3043 | 3204 | { |
| 3044 | 3205 | require_once($sourcedir . '/Subs-Package.php'); |
| 3045 | 3206 | |
| 3046 | 3207 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3047 | 3208 | $error_array = error_get_last(); |
| 3048 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
| 3049 | - $error = $error_array['message']; |
|
| 3050 | - if (empty($error)) |
|
| 3051 | - $error = $txt['template_parse_errmsg']; |
|
| 3209 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
| 3210 | + $error = $error_array['message']; |
|
| 3211 | + } |
|
| 3212 | + if (empty($error)) { |
|
| 3213 | + $error = $txt['template_parse_errmsg']; |
|
| 3214 | + } |
|
| 3052 | 3215 | |
| 3053 | 3216 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
| 3054 | 3217 | |
@@ -3059,11 +3222,12 @@ discard block |
||
| 3059 | 3222 | <h3>', $txt['template_parse_error'], '</h3> |
| 3060 | 3223 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
| 3061 | 3224 | |
| 3062 | - if (!empty($error)) |
|
| 3063 | - echo ' |
|
| 3225 | + if (!empty($error)) { |
|
| 3226 | + echo ' |
|
| 3064 | 3227 | <hr> |
| 3065 | 3228 | |
| 3066 | 3229 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
| 3230 | + } |
|
| 3067 | 3231 | |
| 3068 | 3232 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
| 3069 | 3233 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3073,10 +3237,11 @@ discard block |
||
| 3073 | 3237 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
| 3074 | 3238 | |
| 3075 | 3239 | // Fix the PHP code stuff... |
| 3076 | - if (!isBrowser('gecko')) |
|
| 3077 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3078 | - else |
|
| 3079 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3240 | + if (!isBrowser('gecko')) { |
|
| 3241 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
| 3242 | + } else { |
|
| 3243 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
| 3244 | + } |
|
| 3080 | 3245 | |
| 3081 | 3246 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
| 3082 | 3247 | $j = -1; |
@@ -3084,8 +3249,9 @@ discard block |
||
| 3084 | 3249 | { |
| 3085 | 3250 | $j++; |
| 3086 | 3251 | |
| 3087 | - if (substr_count($line, '<br>') == 0) |
|
| 3088 | - continue; |
|
| 3252 | + if (substr_count($line, '<br>') == 0) { |
|
| 3253 | + continue; |
|
| 3254 | + } |
|
| 3089 | 3255 | |
| 3090 | 3256 | $n = substr_count($line, '<br>'); |
| 3091 | 3257 | for ($i = 0; $i < $n; $i++) |
@@ -3104,38 +3270,42 @@ discard block |
||
| 3104 | 3270 | // Figure out what the color coding was before... |
| 3105 | 3271 | $line = max($match[1] - 9, 1); |
| 3106 | 3272 | $last_line = ''; |
| 3107 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
| 3108 | - if (strpos($data2[$line2], '<') !== false) |
|
| 3273 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
| 3274 | + if (strpos($data2[$line2], '<') !== false) |
|
| 3109 | 3275 | { |
| 3110 | 3276 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
| 3111 | 3277 | $last_line = $color_match[1]; |
| 3278 | + } |
|
| 3112 | 3279 | break; |
| 3113 | 3280 | } |
| 3114 | 3281 | |
| 3115 | 3282 | // Show the relevant lines... |
| 3116 | 3283 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
| 3117 | 3284 | { |
| 3118 | - if ($line == $match[1]) |
|
| 3119 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3285 | + if ($line == $match[1]) { |
|
| 3286 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
| 3287 | + } |
|
| 3120 | 3288 | |
| 3121 | 3289 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
| 3122 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
| 3123 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3290 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
| 3291 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
| 3292 | + } |
|
| 3124 | 3293 | |
| 3125 | 3294 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
| 3126 | 3295 | { |
| 3127 | 3296 | $last_line = $color_match[1]; |
| 3128 | 3297 | echo '</', substr($last_line, 1, 4), '>'; |
| 3298 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
| 3299 | + $last_line = ''; |
|
| 3300 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
| 3301 | + echo '</', substr($last_line, 1, 4), '>'; |
|
| 3129 | 3302 | } |
| 3130 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
| 3131 | - $last_line = ''; |
|
| 3132 | - elseif ($last_line != '' && $data2[$line] != '') |
|
| 3133 | - echo '</', substr($last_line, 1, 4), '>'; |
|
| 3134 | 3303 | |
| 3135 | - if ($line == $match[1]) |
|
| 3136 | - echo '</pre></div><pre style="margin: 0;">'; |
|
| 3137 | - else |
|
| 3138 | - echo "\n"; |
|
| 3304 | + if ($line == $match[1]) { |
|
| 3305 | + echo '</pre></div><pre style="margin: 0;">'; |
|
| 3306 | + } else { |
|
| 3307 | + echo "\n"; |
|
| 3308 | + } |
|
| 3139 | 3309 | } |
| 3140 | 3310 | |
| 3141 | 3311 | echo '</pre></div>'; |
@@ -3159,8 +3329,9 @@ discard block |
||
| 3159 | 3329 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
| 3160 | 3330 | |
| 3161 | 3331 | // Figure out what type of database we are using. |
| 3162 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
| 3163 | - $db_type = 'mysql'; |
|
| 3332 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
| 3333 | + $db_type = 'mysql'; |
|
| 3334 | + } |
|
| 3164 | 3335 | |
| 3165 | 3336 | // Load the file for the database. |
| 3166 | 3337 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3168,8 +3339,9 @@ discard block |
||
| 3168 | 3339 | $db_options = array(); |
| 3169 | 3340 | |
| 3170 | 3341 | // Add in the port if needed |
| 3171 | - if (!empty($db_port)) |
|
| 3172 | - $db_options['port'] = $db_port; |
|
| 3342 | + if (!empty($db_port)) { |
|
| 3343 | + $db_options['port'] = $db_port; |
|
| 3344 | + } |
|
| 3173 | 3345 | |
| 3174 | 3346 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
| 3175 | 3347 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3188,13 +3360,15 @@ discard block |
||
| 3188 | 3360 | } |
| 3189 | 3361 | |
| 3190 | 3362 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
| 3191 | - if (!$db_connection) |
|
| 3192 | - display_db_error(); |
|
| 3363 | + if (!$db_connection) { |
|
| 3364 | + display_db_error(); |
|
| 3365 | + } |
|
| 3193 | 3366 | |
| 3194 | 3367 | // If in SSI mode fix up the prefix. |
| 3195 | - if (SMF == 'SSI') |
|
| 3196 | - db_fix_prefix($db_prefix, $db_name); |
|
| 3197 | -} |
|
| 3368 | + if (SMF == 'SSI') { |
|
| 3369 | + db_fix_prefix($db_prefix, $db_name); |
|
| 3370 | + } |
|
| 3371 | + } |
|
| 3198 | 3372 | |
| 3199 | 3373 | /** |
| 3200 | 3374 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3208,10 +3382,11 @@ discard block |
||
| 3208 | 3382 | global $sourcedir, $cacheAPI, $cache_accelerator; |
| 3209 | 3383 | |
| 3210 | 3384 | // Not overriding this and we have a cacheAPI, send it back. |
| 3211 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
| 3212 | - return $cacheAPI; |
|
| 3213 | - elseif (is_null($cacheAPI)) |
|
| 3214 | - $cacheAPI = false; |
|
| 3385 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
| 3386 | + return $cacheAPI; |
|
| 3387 | + } elseif (is_null($cacheAPI)) { |
|
| 3388 | + $cacheAPI = false; |
|
| 3389 | + } |
|
| 3215 | 3390 | |
| 3216 | 3391 | // Make sure our class is in session. |
| 3217 | 3392 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3232,8 +3407,9 @@ discard block |
||
| 3232 | 3407 | if (!$testAPI->isSupported()) |
| 3233 | 3408 | { |
| 3234 | 3409 | // Can we save ourselves? |
| 3235 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
| 3236 | - return loadCacheAccelerator(null, false); |
|
| 3410 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
| 3411 | + return loadCacheAccelerator(null, false); |
|
| 3412 | + } |
|
| 3237 | 3413 | return false; |
| 3238 | 3414 | } |
| 3239 | 3415 | |
@@ -3245,9 +3421,9 @@ discard block |
||
| 3245 | 3421 | { |
| 3246 | 3422 | $cacheAPI = $testAPI; |
| 3247 | 3423 | return $cacheAPI; |
| 3424 | + } else { |
|
| 3425 | + return $testAPI; |
|
| 3248 | 3426 | } |
| 3249 | - else |
|
| 3250 | - return $testAPI; |
|
| 3251 | 3427 | } |
| 3252 | 3428 | } |
| 3253 | 3429 | |
@@ -3267,8 +3443,9 @@ discard block |
||
| 3267 | 3443 | |
| 3268 | 3444 | // @todo Why are we doing this if caching is disabled? |
| 3269 | 3445 | |
| 3270 | - if (function_exists('call_integration_hook')) |
|
| 3271 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3446 | + if (function_exists('call_integration_hook')) { |
|
| 3447 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
| 3448 | + } |
|
| 3272 | 3449 | |
| 3273 | 3450 | /* Refresh the cache if either: |
| 3274 | 3451 | 1. Caching is disabled. |
@@ -3282,16 +3459,19 @@ discard block |
||
| 3282 | 3459 | require_once($sourcedir . '/' . $file); |
| 3283 | 3460 | $cache_block = call_user_func_array($function, $params); |
| 3284 | 3461 | |
| 3285 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
| 3286 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3462 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
| 3463 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
| 3464 | + } |
|
| 3287 | 3465 | } |
| 3288 | 3466 | |
| 3289 | 3467 | // Some cached data may need a freshening up after retrieval. |
| 3290 | - if (!empty($cache_block['post_retri_eval'])) |
|
| 3291 | - eval($cache_block['post_retri_eval']); |
|
| 3468 | + if (!empty($cache_block['post_retri_eval'])) { |
|
| 3469 | + eval($cache_block['post_retri_eval']); |
|
| 3470 | + } |
|
| 3292 | 3471 | |
| 3293 | - if (function_exists('call_integration_hook')) |
|
| 3294 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3472 | + if (function_exists('call_integration_hook')) { |
|
| 3473 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
| 3474 | + } |
|
| 3295 | 3475 | |
| 3296 | 3476 | return $cache_block['data']; |
| 3297 | 3477 | } |
@@ -3318,8 +3498,9 @@ discard block |
||
| 3318 | 3498 | global $cache_enable, $cacheAPI; |
| 3319 | 3499 | global $cache_hits, $cache_count, $db_show_debug; |
| 3320 | 3500 | |
| 3321 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3322 | - return; |
|
| 3501 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3502 | + return; |
|
| 3503 | + } |
|
| 3323 | 3504 | |
| 3324 | 3505 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3325 | 3506 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3332,12 +3513,14 @@ discard block |
||
| 3332 | 3513 | $value = $value === null ? null : json_encode($value); |
| 3333 | 3514 | $cacheAPI->putData($key, $value, $ttl); |
| 3334 | 3515 | |
| 3335 | - if (function_exists('call_integration_hook')) |
|
| 3336 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3516 | + if (function_exists('call_integration_hook')) { |
|
| 3517 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
| 3518 | + } |
|
| 3337 | 3519 | |
| 3338 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
| 3339 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3340 | -} |
|
| 3520 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
| 3521 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
| 3522 | + } |
|
| 3523 | + } |
|
| 3341 | 3524 | |
| 3342 | 3525 | /** |
| 3343 | 3526 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3353,8 +3536,9 @@ discard block |
||
| 3353 | 3536 | global $cache_enable, $cacheAPI; |
| 3354 | 3537 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
| 3355 | 3538 | |
| 3356 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
| 3357 | - return; |
|
| 3539 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
| 3540 | + return; |
|
| 3541 | + } |
|
| 3358 | 3542 | |
| 3359 | 3543 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
| 3360 | 3544 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3374,16 +3558,18 @@ discard block |
||
| 3374 | 3558 | |
| 3375 | 3559 | if (empty($value)) |
| 3376 | 3560 | { |
| 3377 | - if (!is_array($cache_misses)) |
|
| 3378 | - $cache_misses = array(); |
|
| 3561 | + if (!is_array($cache_misses)) { |
|
| 3562 | + $cache_misses = array(); |
|
| 3563 | + } |
|
| 3379 | 3564 | |
| 3380 | 3565 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
| 3381 | 3566 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
| 3382 | 3567 | } |
| 3383 | 3568 | } |
| 3384 | 3569 | |
| 3385 | - if (function_exists('call_integration_hook') && isset($value)) |
|
| 3386 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3570 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
| 3571 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
| 3572 | + } |
|
| 3387 | 3573 | |
| 3388 | 3574 | return empty($value) ? null : smf_json_decode($value, true); |
| 3389 | 3575 | } |
@@ -3405,8 +3591,9 @@ discard block |
||
| 3405 | 3591 | global $cacheAPI; |
| 3406 | 3592 | |
| 3407 | 3593 | // If we can't get to the API, can't do this. |
| 3408 | - if (empty($cacheAPI)) |
|
| 3409 | - return; |
|
| 3594 | + if (empty($cacheAPI)) { |
|
| 3595 | + return; |
|
| 3596 | + } |
|
| 3410 | 3597 | |
| 3411 | 3598 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
| 3412 | 3599 | $cacheAPI->cleanCache($type); |
@@ -3431,8 +3618,9 @@ discard block |
||
| 3431 | 3618 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
| 3432 | 3619 | |
| 3433 | 3620 | // Come on! |
| 3434 | - if (empty($data)) |
|
| 3435 | - return array(); |
|
| 3621 | + if (empty($data)) { |
|
| 3622 | + return array(); |
|
| 3623 | + } |
|
| 3436 | 3624 | |
| 3437 | 3625 | // Set a nice default var. |
| 3438 | 3626 | $image = ''; |
@@ -3440,11 +3628,11 @@ discard block |
||
| 3440 | 3628 | // Gravatar has been set as mandatory! |
| 3441 | 3629 | if (!empty($modSettings['gravatarOverride'])) |
| 3442 | 3630 | { |
| 3443 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
| 3444 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3445 | - |
|
| 3446 | - else if (!empty($data['email'])) |
|
| 3447 | - $image = get_gravatar_url($data['email']); |
|
| 3631 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
| 3632 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3633 | + } else if (!empty($data['email'])) { |
|
| 3634 | + $image = get_gravatar_url($data['email']); |
|
| 3635 | + } |
|
| 3448 | 3636 | } |
| 3449 | 3637 | |
| 3450 | 3638 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3456,54 +3644,60 @@ discard block |
||
| 3456 | 3644 | // Gravatar. |
| 3457 | 3645 | if (stristr($data['avatar'], 'gravatar://')) |
| 3458 | 3646 | { |
| 3459 | - if ($data['avatar'] == 'gravatar://') |
|
| 3460 | - $image = get_gravatar_url($data['email']); |
|
| 3461 | - |
|
| 3462 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
| 3463 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3647 | + if ($data['avatar'] == 'gravatar://') { |
|
| 3648 | + $image = get_gravatar_url($data['email']); |
|
| 3649 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
| 3650 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
| 3651 | + } |
|
| 3464 | 3652 | } |
| 3465 | 3653 | |
| 3466 | 3654 | // External url. |
| 3467 | 3655 | else |
| 3468 | 3656 | { |
| 3469 | 3657 | // Using ssl? |
| 3470 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
| 3471 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3658 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
| 3659 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
| 3660 | + } |
|
| 3472 | 3661 | |
| 3473 | 3662 | // Just a plain external url. |
| 3474 | - else |
|
| 3475 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3663 | + else { |
|
| 3664 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
| 3665 | + } |
|
| 3476 | 3666 | } |
| 3477 | 3667 | } |
| 3478 | 3668 | |
| 3479 | 3669 | // Perhaps this user has an attachment as avatar... |
| 3480 | - else if (!empty($data['filename'])) |
|
| 3481 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3670 | + else if (!empty($data['filename'])) { |
|
| 3671 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
| 3672 | + } |
|
| 3482 | 3673 | |
| 3483 | 3674 | // Right... no avatar... use our default image. |
| 3484 | - else |
|
| 3485 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3675 | + else { |
|
| 3676 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
| 3677 | + } |
|
| 3486 | 3678 | } |
| 3487 | 3679 | |
| 3488 | 3680 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
| 3489 | 3681 | |
| 3490 | 3682 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
| 3491 | - if (!empty($image)) |
|
| 3492 | - return array( |
|
| 3683 | + if (!empty($image)) { |
|
| 3684 | + return array( |
|
| 3493 | 3685 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
| 3494 | 3686 | 'image' => '<img class="avatar" src="' . $image . '" />', |
| 3495 | 3687 | 'href' => $image, |
| 3496 | 3688 | 'url' => $image, |
| 3497 | 3689 | ); |
| 3690 | + } |
|
| 3498 | 3691 | |
| 3499 | 3692 | // Fallback to make life easier for everyone... |
| 3500 | - else |
|
| 3501 | - return array( |
|
| 3693 | + else { |
|
| 3694 | + return array( |
|
| 3502 | 3695 | 'name' => '', |
| 3503 | 3696 | 'image' => '', |
| 3504 | 3697 | 'href' => '', |
| 3505 | 3698 | 'url' => '', |
| 3506 | 3699 | ); |
| 3507 | -} |
|
| 3700 | + } |
|
| 3701 | + } |
|
| 3508 | 3702 | |
| 3509 | 3703 | ?> |
| 3510 | 3704 | \ No newline at end of file |