@@ -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 | { |
@@ -22,30 +22,32 @@ discard block |
||
| 22 | 22 | <div id="calendar">'; |
| 23 | 23 | |
| 24 | 24 | // Show the mini-blocks if they're enabled. |
| 25 | - if (empty($context['blocks_disabled'])) |
|
| 26 | - echo ' |
|
| 25 | + if (empty($context['blocks_disabled'])) { |
|
| 26 | + echo ' |
|
| 27 | 27 | <div id="month_grid"> |
| 28 | 28 | ', template_show_month_grid('prev', true), ' |
| 29 | 29 | ', template_show_month_grid('current', true), ' |
| 30 | 30 | ', template_show_month_grid('next', true), ' |
| 31 | 31 | </div>'; |
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | // What view are we showing? |
| 34 | - if ($context['calendar_view'] == 'viewlist') |
|
| 35 | - echo ' |
|
| 35 | + if ($context['calendar_view'] == 'viewlist') { |
|
| 36 | + echo ' |
|
| 36 | 37 | <div id="main_grid"> |
| 37 | 38 | ', template_show_upcoming_list('main'), ' |
| 38 | 39 | </div>'; |
| 39 | - elseif ($context['calendar_view'] == 'viewweek') |
|
| 40 | - echo ' |
|
| 40 | + } elseif ($context['calendar_view'] == 'viewweek') { |
|
| 41 | + echo ' |
|
| 41 | 42 | <div id="main_grid"> |
| 42 | 43 | ', template_show_week_grid('main'), ' |
| 43 | 44 | </div>'; |
| 44 | - else |
|
| 45 | - echo ' |
|
| 45 | + } else { |
|
| 46 | + echo ' |
|
| 46 | 47 | <div id="main_grid"> |
| 47 | 48 | ', template_show_month_grid('main'), ' |
| 48 | 49 | </div>'; |
| 50 | + } |
|
| 49 | 51 | |
| 50 | 52 | // Close our wrapper. |
| 51 | 53 | echo ' |
@@ -64,20 +66,22 @@ discard block |
||
| 64 | 66 | global $context, $scripturl, $txt; |
| 65 | 67 | |
| 66 | 68 | // Bail out if we have nothing to work with |
| 67 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 68 | - return false; |
|
| 69 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | // Protect programmer sanity |
| 71 | 74 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
| 72 | 75 | |
| 73 | 76 | // Do we want a title? |
| 74 | - if (empty($calendar_data['disable_title'])) |
|
| 75 | - echo ' |
|
| 77 | + if (empty($calendar_data['disable_title'])) { |
|
| 78 | + echo ' |
|
| 76 | 79 | <div class="cat_bar"> |
| 77 | 80 | <h3 class="catbg centertext largetext"> |
| 78 | 81 | <a href="', $scripturl, '?action=calendar;viewlist;year=', $calendar_data['start_year'], ';month=', $calendar_data['start_month'], ';day=', $calendar_data['start_day'], '">', $txt['calendar_upcoming'], '</a> |
| 79 | 82 | </h3> |
| 80 | 83 | </div>'; |
| 84 | + } |
|
| 81 | 85 | |
| 82 | 86 | // Give the user some controls to work with |
| 83 | 87 | template_calendar_top($calendar_data); |
@@ -100,11 +104,13 @@ discard block |
||
| 100 | 104 | <li class="windowbg"> |
| 101 | 105 | <strong class="event_title">', $event['link'], '</strong>'; |
| 102 | 106 | |
| 103 | - if ($event['can_edit']) |
|
| 104 | - echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
| 107 | + if ($event['can_edit']) { |
|
| 108 | + echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
| 109 | + } |
|
| 105 | 110 | |
| 106 | - if ($event['can_export']) |
|
| 107 | - echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
| 111 | + if ($event['can_export']) { |
|
| 112 | + echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
| 113 | + } |
|
| 108 | 114 | |
| 109 | 115 | echo ' |
| 110 | 116 | <br>'; |
@@ -112,14 +118,14 @@ discard block |
||
| 112 | 118 | if (!empty($event['allday'])) |
| 113 | 119 | { |
| 114 | 120 | 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>' : ''; |
| 115 | - } |
|
| 116 | - else |
|
| 121 | + } else |
|
| 117 | 122 | { |
| 118 | 123 | // Display event info relative to user's local timezone |
| 119 | 124 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
| 120 | 125 | |
| 121 | - if ($event['start_date_local'] != $event['end_date_local']) |
|
| 122 | - echo trim($event['end_date_local']) . ', '; |
|
| 126 | + if ($event['start_date_local'] != $event['end_date_local']) { |
|
| 127 | + echo trim($event['end_date_local']) . ', '; |
|
| 128 | + } |
|
| 123 | 129 | |
| 124 | 130 | echo trim($event['end_time_local']); |
| 125 | 131 | |
@@ -128,23 +134,27 @@ discard block |
||
| 128 | 134 | { |
| 129 | 135 | echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">'; |
| 130 | 136 | |
| 131 | - 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']) |
|
| 132 | - echo trim($event['start_date_orig']), ', '; |
|
| 137 | + 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']) { |
|
| 138 | + echo trim($event['start_date_orig']), ', '; |
|
| 139 | + } |
|
| 133 | 140 | |
| 134 | 141 | echo trim($event['start_time_orig']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
| 135 | 142 | |
| 136 | - if ($event['start_date_orig'] != $event['end_date_orig']) |
|
| 137 | - echo trim($event['end_date_orig']) . ', '; |
|
| 143 | + if ($event['start_date_orig'] != $event['end_date_orig']) { |
|
| 144 | + echo trim($event['end_date_orig']) . ', '; |
|
| 145 | + } |
|
| 138 | 146 | |
| 139 | 147 | echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)'; |
| 140 | 148 | } |
| 141 | 149 | // Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion |
| 142 | - else |
|
| 143 | - echo ' ', $event['tz_abbrev'], '</time>'; |
|
| 150 | + else { |
|
| 151 | + echo ' ', $event['tz_abbrev'], '</time>'; |
|
| 152 | + } |
|
| 144 | 153 | } |
| 145 | 154 | |
| 146 | - if (!empty($event['location'])) |
|
| 147 | - echo '<br>', $event['location']; |
|
| 155 | + if (!empty($event['location'])) { |
|
| 156 | + echo '<br>', $event['location']; |
|
| 157 | + } |
|
| 148 | 158 | |
| 149 | 159 | echo ' |
| 150 | 160 | </li>'; |
@@ -176,8 +186,9 @@ discard block |
||
| 176 | 186 | |
| 177 | 187 | $birthdays = array(); |
| 178 | 188 | |
| 179 | - foreach ($date as $member) |
|
| 180 | - $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
| 189 | + foreach ($date as $member) { |
|
| 190 | + $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
| 191 | + } |
|
| 181 | 192 | |
| 182 | 193 | echo implode(', ', $birthdays); |
| 183 | 194 | |
@@ -208,8 +219,9 @@ discard block |
||
| 208 | 219 | $date_local = $date['date_local']; |
| 209 | 220 | unset($date['date_local']); |
| 210 | 221 | |
| 211 | - foreach ($date as $holiday) |
|
| 212 | - $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
| 222 | + foreach ($date as $holiday) { |
|
| 223 | + $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
| 224 | + } |
|
| 213 | 225 | } |
| 214 | 226 | |
| 215 | 227 | echo implode(', ', $holidays); |
@@ -233,17 +245,19 @@ discard block |
||
| 233 | 245 | global $context, $txt, $scripturl, $modSettings; |
| 234 | 246 | |
| 235 | 247 | // If the grid doesn't exist, no point in proceeding. |
| 236 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 237 | - return false; |
|
| 248 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 249 | + return false; |
|
| 250 | + } |
|
| 238 | 251 | |
| 239 | 252 | // A handy little pointer variable. |
| 240 | 253 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
| 241 | 254 | |
| 242 | 255 | // Some conditions for whether or not we should show the week links *here*. |
| 243 | - 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))) |
|
| 244 | - $show_week_links = true; |
|
| 245 | - else |
|
| 246 | - $show_week_links = false; |
|
| 256 | + 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))) { |
|
| 257 | + $show_week_links = true; |
|
| 258 | + } else { |
|
| 259 | + $show_week_links = false; |
|
| 260 | + } |
|
| 247 | 261 | |
| 248 | 262 | // Assuming that we've not disabled it, show the title block! |
| 249 | 263 | if (empty($calendar_data['disable_title'])) |
@@ -253,18 +267,20 @@ discard block |
||
| 253 | 267 | <h3 class="catbg centertext largetext">'; |
| 254 | 268 | |
| 255 | 269 | // Previous Link: If we're showing prev / next and it's not a mini-calendar. |
| 256 | - if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) |
|
| 257 | - echo ' |
|
| 270 | + if (empty($calendar_data['previous_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) { |
|
| 271 | + echo ' |
|
| 258 | 272 | <span class="floatleft"> |
| 259 | 273 | <a href="', $calendar_data['previous_calendar']['href'], '">«</a> |
| 260 | 274 | </span>'; |
| 275 | + } |
|
| 261 | 276 | |
| 262 | 277 | // Next Link: if we're showing prev / next and it's not a mini-calendar. |
| 263 | - if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) |
|
| 264 | - echo ' |
|
| 278 | + if (empty($calendar_data['next_calendar']['disabled']) && $calendar_data['show_next_prev'] && $is_mini === false) { |
|
| 279 | + echo ' |
|
| 265 | 280 | <span class="floatright"> |
| 266 | 281 | <a href="', $calendar_data['next_calendar']['href'], '">»</a> |
| 267 | 282 | </span>'; |
| 283 | + } |
|
| 268 | 284 | |
| 269 | 285 | // Arguably the most exciting part, the title! |
| 270 | 286 | echo ' |
@@ -274,8 +290,9 @@ discard block |
||
| 274 | 290 | } |
| 275 | 291 | |
| 276 | 292 | // Show the controls on main grids |
| 277 | - if ($is_mini === false) |
|
| 278 | - template_calendar_top($calendar_data); |
|
| 293 | + if ($is_mini === false) { |
|
| 294 | + template_calendar_top($calendar_data); |
|
| 295 | + } |
|
| 279 | 296 | |
| 280 | 297 | // Finally, the main calendar table. |
| 281 | 298 | echo ' |
@@ -288,14 +305,16 @@ discard block |
||
| 288 | 305 | <tr>'; |
| 289 | 306 | |
| 290 | 307 | // If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared! |
| 291 | - if ($show_week_links === true) |
|
| 292 | - echo ' |
|
| 308 | + if ($show_week_links === true) { |
|
| 309 | + echo ' |
|
| 293 | 310 | <th></th>'; |
| 311 | + } |
|
| 294 | 312 | |
| 295 | 313 | // Now, loop through each actual day of the week. |
| 296 | - foreach ($calendar_data['week_days'] as $day) |
|
| 297 | - echo ' |
|
| 314 | + foreach ($calendar_data['week_days'] as $day) { |
|
| 315 | + echo ' |
|
| 298 | 316 | <th class="days" scope="col">', !empty($calendar_data['short_day_titles']) || $is_mini === true ? $txt['days_short'][$day] : $txt['days'][$day], '</th>'; |
| 317 | + } |
|
| 299 | 318 | |
| 300 | 319 | echo ' |
| 301 | 320 | </tr>'; |
@@ -313,11 +332,12 @@ discard block |
||
| 313 | 332 | <tr class="days_wrapper">'; |
| 314 | 333 | |
| 315 | 334 | // This is where we add the actual week link, if enabled on this location. |
| 316 | - if ($show_week_links === true) |
|
| 317 | - echo ' |
|
| 335 | + if ($show_week_links === true) { |
|
| 336 | + echo ' |
|
| 318 | 337 | <td class="windowbg weeks"> |
| 319 | 338 | <a href="', $scripturl, '?action=calendar;viewweek;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $week['days'][0]['day'], '" title="', $txt['calendar_view_week'], '">»</a> |
| 320 | 339 | </td>'; |
| 340 | + } |
|
| 321 | 341 | |
| 322 | 342 | // Now loop through each day in the week we're on. |
| 323 | 343 | foreach ($week['days'] as $day) |
@@ -333,27 +353,29 @@ discard block |
||
| 333 | 353 | // Additional classes are given for events, holidays, and birthdays. |
| 334 | 354 | if (!empty($day['events']) && !empty($calendar_data['highlight']['events'])) |
| 335 | 355 | { |
| 336 | - if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) |
|
| 337 | - $classes[] = 'events'; |
|
| 338 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) |
|
| 339 | - $classes[] = 'events'; |
|
| 356 | + if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) { |
|
| 357 | + $classes[] = 'events'; |
|
| 358 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) { |
|
| 359 | + $classes[] = 'events'; |
|
| 360 | + } |
|
| 340 | 361 | } |
| 341 | 362 | if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays'])) |
| 342 | 363 | { |
| 343 | - if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) |
|
| 344 | - $classes[] = 'holidays'; |
|
| 345 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) |
|
| 346 | - $classes[] = 'holidays'; |
|
| 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'; |
|
| 368 | + } |
|
| 347 | 369 | } |
| 348 | 370 | if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays'])) |
| 349 | 371 | { |
| 350 | - if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) |
|
| 351 | - $classes[] = 'birthdays'; |
|
| 352 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) |
|
| 353 | - $classes[] = 'birthdays'; |
|
| 372 | + if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) { |
|
| 373 | + $classes[] = 'birthdays'; |
|
| 374 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) { |
|
| 375 | + $classes[] = 'birthdays'; |
|
| 376 | + } |
|
| 354 | 377 | } |
| 355 | - } |
|
| 356 | - else |
|
| 378 | + } else |
|
| 357 | 379 | { |
| 358 | 380 | // Default Classes (either compact or comfortable and disabled). |
| 359 | 381 | $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable'; |
@@ -371,25 +393,27 @@ discard block |
||
| 371 | 393 | $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']] . ' ') : ''; |
| 372 | 394 | |
| 373 | 395 | // The actual day number - be it a link, or just plain old text! |
| 374 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
| 375 | - echo ' |
|
| 396 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
| 397 | + echo ' |
|
| 376 | 398 | <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>'; |
| 377 | - elseif ($is_mini) |
|
| 378 | - echo ' |
|
| 399 | + } elseif ($is_mini) { |
|
| 400 | + echo ' |
|
| 379 | 401 | <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>'; |
| 380 | - else |
|
| 381 | - echo ' |
|
| 402 | + } else { |
|
| 403 | + echo ' |
|
| 382 | 404 | <span class="day_text">', $title_prefix, $day['day'], '</span>'; |
| 405 | + } |
|
| 383 | 406 | |
| 384 | 407 | // A lot of stuff, we're not showing on mini-calendars to conserve space. |
| 385 | 408 | if ($is_mini === false) |
| 386 | 409 | { |
| 387 | 410 | // Holidays are always fun, let's show them! |
| 388 | - if (!empty($day['holidays'])) |
|
| 389 | - echo ' |
|
| 411 | + if (!empty($day['holidays'])) { |
|
| 412 | + echo ' |
|
| 390 | 413 | <div class="smalltext holiday"> |
| 391 | 414 | <span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), ' |
| 392 | 415 | </div>'; |
| 416 | + } |
|
| 393 | 417 | |
| 394 | 418 | // Happy Birthday Dear Member! |
| 395 | 419 | if (!empty($day['birthdays'])) |
@@ -407,15 +431,17 @@ discard block |
||
| 407 | 431 | 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) ? '' : ', '; |
| 408 | 432 | |
| 409 | 433 | // 9...10! Let's stop there. |
| 410 | - if ($birthday_count == 10 && $use_js_hide) |
|
| 411 | - // !!TODO - Inline CSS and JavaScript should be moved. |
|
| 434 | + if ($birthday_count == 10 && $use_js_hide) { |
|
| 435 | + // !!TODO - Inline CSS and JavaScript should be moved. |
|
| 412 | 436 | 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;">, '; |
| 437 | + } |
|
| 413 | 438 | |
| 414 | 439 | ++$birthday_count; |
| 415 | 440 | } |
| 416 | - if ($use_js_hide) |
|
| 417 | - echo ' |
|
| 441 | + if ($use_js_hide) { |
|
| 442 | + echo ' |
|
| 418 | 443 | </span>'; |
| 444 | + } |
|
| 419 | 445 | |
| 420 | 446 | echo ' |
| 421 | 447 | </div><!-- .smalltext -->'; |
@@ -426,8 +452,9 @@ discard block |
||
| 426 | 452 | { |
| 427 | 453 | // Sort events by start time (all day events will be listed first) |
| 428 | 454 | uasort($day['events'], function($a, $b) { |
| 429 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 430 | - return 0; |
|
| 455 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
| 456 | + return 0; |
|
| 457 | + } |
|
| 431 | 458 | |
| 432 | 459 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
| 433 | 460 | }); |
@@ -447,20 +474,22 @@ discard block |
||
| 447 | 474 | ', $event['link'], '<br> |
| 448 | 475 | <span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
| 449 | 476 | |
| 450 | - if (!empty($event['start_time_local']) && $event['starts_today'] == true) |
|
| 451 | - echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
| 452 | - elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) |
|
| 453 | - echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
| 454 | - elseif (!empty($event['allday'])) |
|
| 455 | - 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 | + } |
|
| 456 | 484 | |
| 457 | 485 | echo ' |
| 458 | 486 | </span>'; |
| 459 | 487 | |
| 460 | - if (!empty($event['location'])) |
|
| 461 | - echo ' |
|
| 488 | + if (!empty($event['location'])) { |
|
| 489 | + echo ' |
|
| 462 | 490 | <br> |
| 463 | 491 | <span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
| 492 | + } |
|
| 464 | 493 | |
| 465 | 494 | if ($event['can_edit'] || $event['can_export']) |
| 466 | 495 | { |
@@ -468,18 +497,20 @@ discard block |
||
| 468 | 497 | <span class="modify_event_links">'; |
| 469 | 498 | |
| 470 | 499 | // If they can edit the event, show an icon they can click on.... |
| 471 | - if ($event['can_edit']) |
|
| 472 | - echo ' |
|
| 500 | + if ($event['can_edit']) { |
|
| 501 | + echo ' |
|
| 473 | 502 | <a class="modify_event" href="', $event['modify_href'], '"> |
| 474 | 503 | <span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span> |
| 475 | 504 | </a>'; |
| 505 | + } |
|
| 476 | 506 | |
| 477 | 507 | // Exporting! |
| 478 | - if ($event['can_export']) |
|
| 479 | - echo ' |
|
| 508 | + if ($event['can_export']) { |
|
| 509 | + echo ' |
|
| 480 | 510 | <a class="modify_event" href="', $event['export_href'], '"> |
| 481 | 511 | <span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span> |
| 482 | 512 | </a>'; |
| 513 | + } |
|
| 483 | 514 | |
| 484 | 515 | echo ' |
| 485 | 516 | </span><br class="clear">'; |
@@ -498,10 +529,11 @@ discard block |
||
| 498 | 529 | // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days! |
| 499 | 530 | elseif ($is_mini === false) |
| 500 | 531 | { |
| 501 | - if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) |
|
| 502 | - 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>'; |
|
| 503 | - elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) |
|
| 504 | - 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>'; |
|
| 532 | + if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) { |
|
| 533 | + 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>'; |
|
| 534 | + } elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) { |
|
| 535 | + 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>'; |
|
| 536 | + } |
|
| 505 | 537 | } |
| 506 | 538 | |
| 507 | 539 | // Close this day and increase var count. |
@@ -531,8 +563,9 @@ discard block |
||
| 531 | 563 | global $context, $txt, $scripturl, $modSettings; |
| 532 | 564 | |
| 533 | 565 | // We might have no reason to proceed, if the variable isn't there. |
| 534 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
| 535 | - return false; |
|
| 566 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 536 | 569 | |
| 537 | 570 | // Handy pointer. |
| 538 | 571 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -549,22 +582,25 @@ discard block |
||
| 549 | 582 | <h3 class="catbg centertext largetext">'; |
| 550 | 583 | |
| 551 | 584 | // Previous Week Link... |
| 552 | - if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) |
|
| 553 | - echo ' |
|
| 585 | + if (empty($calendar_data['previous_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) { |
|
| 586 | + echo ' |
|
| 554 | 587 | <span class="floatleft"> |
| 555 | 588 | <a href="', $calendar_data['previous_week']['href'], '">«</a> |
| 556 | 589 | </span>'; |
| 590 | + } |
|
| 557 | 591 | |
| 558 | 592 | // Next Week Link... |
| 559 | - if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) |
|
| 560 | - echo ' |
|
| 593 | + if (empty($calendar_data['next_calendar']['disabled']) && !empty($calendar_data['show_next_prev'])) { |
|
| 594 | + echo ' |
|
| 561 | 595 | <span class="floatright"> |
| 562 | 596 | <a href="', $calendar_data['next_week']['href'], '">»</a> |
| 563 | 597 | </span>'; |
| 598 | + } |
|
| 564 | 599 | |
| 565 | 600 | // The Month Title + Week Number... |
| 566 | - if (!empty($calendar_data['week_title'])) |
|
| 567 | - echo $calendar_data['week_title']; |
|
| 601 | + if (!empty($calendar_data['week_title'])) { |
|
| 602 | + echo $calendar_data['week_title']; |
|
| 603 | + } |
|
| 568 | 604 | |
| 569 | 605 | echo ' |
| 570 | 606 | </h3> |
@@ -605,11 +641,12 @@ discard block |
||
| 605 | 641 | <td class="', implode(' ', $classes), ' act_day">'; |
| 606 | 642 | |
| 607 | 643 | // Should the day number be a link? |
| 608 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
| 609 | - echo ' |
|
| 644 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
| 645 | + echo ' |
|
| 610 | 646 | <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>'; |
| 611 | - else |
|
| 612 | - echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
| 647 | + } else { |
|
| 648 | + echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
| 649 | + } |
|
| 613 | 650 | |
| 614 | 651 | echo ' |
| 615 | 652 | </td> |
@@ -620,8 +657,9 @@ discard block |
||
| 620 | 657 | { |
| 621 | 658 | // Sort events by start time (all day events will be listed first) |
| 622 | 659 | uasort($day['events'], function($a, $b) { |
| 623 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
| 624 | - return 0; |
|
| 660 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
| 661 | + return 0; |
|
| 662 | + } |
|
| 625 | 663 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
| 626 | 664 | }); |
| 627 | 665 | |
@@ -635,35 +673,39 @@ discard block |
||
| 635 | 673 | echo $event['link'], '<br> |
| 636 | 674 | <span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
| 637 | 675 | |
| 638 | - if (!empty($event['start_time_local'])) |
|
| 639 | - echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
| 640 | - else |
|
| 641 | - echo $txt['calendar_allday']; |
|
| 676 | + if (!empty($event['start_time_local'])) { |
|
| 677 | + echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
| 678 | + } else { |
|
| 679 | + echo $txt['calendar_allday']; |
|
| 680 | + } |
|
| 642 | 681 | |
| 643 | 682 | echo ' |
| 644 | 683 | </span>'; |
| 645 | 684 | |
| 646 | - if (!empty($event['location'])) |
|
| 647 | - echo '<br> |
|
| 685 | + if (!empty($event['location'])) { |
|
| 686 | + echo '<br> |
|
| 648 | 687 | <span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
| 688 | + } |
|
| 649 | 689 | |
| 650 | 690 | if (!empty($event_icons_needed)) |
| 651 | 691 | { |
| 652 | 692 | echo ' <span class="modify_event_links">'; |
| 653 | 693 | |
| 654 | 694 | // If they can edit the event, show a star they can click on.... |
| 655 | - if (!empty($event['can_edit'])) |
|
| 656 | - echo ' |
|
| 695 | + if (!empty($event['can_edit'])) { |
|
| 696 | + echo ' |
|
| 657 | 697 | <a class="modify_event" href="', $event['modify_href'], '"> |
| 658 | 698 | <span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span> |
| 659 | 699 | </a>'; |
| 700 | + } |
|
| 660 | 701 | |
| 661 | 702 | // Can we export? Sweet. |
| 662 | - if (!empty($event['can_export'])) |
|
| 663 | - echo ' |
|
| 703 | + if (!empty($event['can_export'])) { |
|
| 704 | + echo ' |
|
| 664 | 705 | <a class="modify_event" href="', $event['export_href'], '"> |
| 665 | 706 | <span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span> |
| 666 | 707 | </a>'; |
| 708 | + } |
|
| 667 | 709 | |
| 668 | 710 | echo ' |
| 669 | 711 | </span><br class="clear">'; |
@@ -681,22 +723,23 @@ discard block |
||
| 681 | 723 | </div> |
| 682 | 724 | <br class="clear">'; |
| 683 | 725 | } |
| 684 | - } |
|
| 685 | - else |
|
| 726 | + } else |
|
| 686 | 727 | { |
| 687 | - if (!empty($context['can_post'])) |
|
| 688 | - echo ' |
|
| 728 | + if (!empty($context['can_post'])) { |
|
| 729 | + echo ' |
|
| 689 | 730 | <div class="week_add_event"> |
| 690 | 731 | <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['calendar_post_event'], '</a> |
| 691 | 732 | </div>'; |
| 733 | + } |
|
| 692 | 734 | } |
| 693 | 735 | echo ' |
| 694 | 736 | </td> |
| 695 | 737 | <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">'; |
| 696 | 738 | |
| 697 | 739 | // Show any holidays! |
| 698 | - if (!empty($day['holidays'])) |
|
| 699 | - echo implode('<br>', $day['holidays']); |
|
| 740 | + if (!empty($day['holidays'])) { |
|
| 741 | + echo implode('<br>', $day['holidays']); |
|
| 742 | + } |
|
| 700 | 743 | |
| 701 | 744 | echo ' |
| 702 | 745 | </td> |
@@ -705,11 +748,12 @@ discard block |
||
| 705 | 748 | // Show any birthdays... |
| 706 | 749 | if (!empty($day['birthdays'])) |
| 707 | 750 | { |
| 708 | - foreach ($day['birthdays'] as $member) |
|
| 709 | - echo ' |
|
| 751 | + foreach ($day['birthdays'] as $member) { |
|
| 752 | + echo ' |
|
| 710 | 753 | <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], '</a> |
| 711 | 754 | ', isset($member['age']) ? ' (' . $member['age'] . ')' : '', ' |
| 712 | 755 | ', $member['is_last'] ? '' : '<br>'; |
| 756 | + } |
|
| 713 | 757 | } |
| 714 | 758 | echo ' |
| 715 | 759 | </td> |
@@ -755,26 +799,27 @@ discard block |
||
| 755 | 799 | <input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date"> |
| 756 | 800 | <input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '"> |
| 757 | 801 | </form>'; |
| 758 | - } |
|
| 759 | - else |
|
| 802 | + } else |
|
| 760 | 803 | { |
| 761 | 804 | echo' |
| 762 | 805 | <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '"> |
| 763 | 806 | <select name="month" id="input_month">'; |
| 764 | 807 | |
| 765 | 808 | // Show a select box with all the months. |
| 766 | - foreach ($txt['months_short'] as $number => $month) |
|
| 767 | - echo ' |
|
| 809 | + foreach ($txt['months_short'] as $number => $month) { |
|
| 810 | + echo ' |
|
| 768 | 811 | <option value="', $number, '"', $number == $context['current_month'] ? ' selected' : '', '>', $month, '</option>'; |
| 812 | + } |
|
| 769 | 813 | |
| 770 | 814 | echo ' |
| 771 | 815 | </select> |
| 772 | 816 | <select name="year">'; |
| 773 | 817 | |
| 774 | 818 | // Show a link for every year... |
| 775 | - for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++) |
|
| 776 | - echo ' |
|
| 819 | + for ($year = $context['calendar_resources']['min_year']; $year <= $context['calendar_resources']['max_year']; $year++) { |
|
| 820 | + echo ' |
|
| 777 | 821 | <option value="', $year, '"', $year == $context['current_year'] ? ' selected' : '', '>', $year, '</option>'; |
| 822 | + } |
|
| 778 | 823 | |
| 779 | 824 | echo ' |
| 780 | 825 | </select> |
@@ -796,9 +841,10 @@ discard block |
||
| 796 | 841 | echo ' |
| 797 | 842 | <form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">'; |
| 798 | 843 | |
| 799 | - if (!empty($context['event']['new'])) |
|
| 800 | - echo ' |
|
| 844 | + if (!empty($context['event']['new'])) { |
|
| 845 | + echo ' |
|
| 801 | 846 | <input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
| 847 | + } |
|
| 802 | 848 | |
| 803 | 849 | // Start the main table. |
| 804 | 850 | echo ' |
@@ -809,8 +855,8 @@ discard block |
||
| 809 | 855 | </h3> |
| 810 | 856 | </div>'; |
| 811 | 857 | |
| 812 | - if (!empty($context['post_error']['messages'])) |
|
| 813 | - echo ' |
|
| 858 | + if (!empty($context['post_error']['messages'])) { |
|
| 859 | + echo ' |
|
| 814 | 860 | <div class="errorbox"> |
| 815 | 861 | <dl class="event_error"> |
| 816 | 862 | <dt> |
@@ -821,6 +867,7 @@ discard block |
||
| 821 | 867 | </dt> |
| 822 | 868 | </dl> |
| 823 | 869 | </div>'; |
| 870 | + } |
|
| 824 | 871 | |
| 825 | 872 | echo ' |
| 826 | 873 | <div class="roundframe noup"> |
@@ -848,9 +895,10 @@ discard block |
||
| 848 | 895 | echo ' |
| 849 | 896 | <optgroup label="', $category['name'], '">'; |
| 850 | 897 | |
| 851 | - foreach ($category['boards'] as $board) |
|
| 852 | - echo ' |
|
| 898 | + foreach ($category['boards'] as $board) { |
|
| 899 | + echo ' |
|
| 853 | 900 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], '</option>'; |
| 901 | + } |
|
| 854 | 902 | echo ' |
| 855 | 903 | </optgroup>'; |
| 856 | 904 | } |
@@ -886,9 +934,10 @@ discard block |
||
| 886 | 934 | <span class="label">', $txt['calendar_timezone'], '</span> |
| 887 | 935 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
| 888 | 936 | |
| 889 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
| 890 | - echo ' |
|
| 937 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
| 938 | + echo ' |
|
| 891 | 939 | <option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
| 940 | + } |
|
| 892 | 941 | |
| 893 | 942 | echo ' |
| 894 | 943 | </select> |
@@ -904,9 +953,10 @@ discard block |
||
| 904 | 953 | <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">'; |
| 905 | 954 | |
| 906 | 955 | // Delete button? |
| 907 | - if (empty($context['event']['new'])) |
|
| 908 | - echo ' |
|
| 956 | + if (empty($context['event']['new'])) { |
|
| 957 | + echo ' |
|
| 909 | 958 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">'; |
| 959 | + } |
|
| 910 | 960 | |
| 911 | 961 | echo ' |
| 912 | 962 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -934,9 +984,10 @@ discard block |
||
| 934 | 984 | echo ' |
| 935 | 985 | <td style="padding-', $alt ? 'right' : 'left', ': 1.5em;">'; |
| 936 | 986 | |
| 937 | - foreach ($v as $i) |
|
| 938 | - echo ' |
|
| 987 | + foreach ($v as $i) { |
|
| 988 | + echo ' |
|
| 939 | 989 | <img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '"><br>'; |
| 990 | + } |
|
| 940 | 991 | |
| 941 | 992 | echo ' |
| 942 | 993 | </td>'; |
@@ -957,9 +1008,10 @@ discard block |
||
| 957 | 1008 | |
| 958 | 1009 | foreach ($context['clockicons'] as $t => $v) |
| 959 | 1010 | { |
| 960 | - foreach ($v as $i) |
|
| 961 | - echo ' |
|
| 1011 | + foreach ($v as $i) { |
|
| 1012 | + echo ' |
|
| 962 | 1013 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 1014 | + } |
|
| 963 | 1015 | } |
| 964 | 1016 | |
| 965 | 1017 | echo ' |
@@ -984,13 +1036,14 @@ discard block |
||
| 984 | 1036 | |
| 985 | 1037 | foreach ($context['clockicons'] as $t => $v) |
| 986 | 1038 | { |
| 987 | - foreach ($v as $i) |
|
| 988 | - echo ' |
|
| 1039 | + foreach ($v as $i) { |
|
| 1040 | + echo ' |
|
| 989 | 1041 | if (', $t, ' >= ', $i, ') |
| 990 | 1042 | { |
| 991 | 1043 | turnon.push("', $t, '_', $i, '"); |
| 992 | 1044 | ', $t, ' -= ', $i, '; |
| 993 | 1045 | }'; |
| 1046 | + } |
|
| 994 | 1047 | } |
| 995 | 1048 | |
| 996 | 1049 | echo ' |
@@ -1034,9 +1087,10 @@ discard block |
||
| 1034 | 1087 | <tr class="windowbg"> |
| 1035 | 1088 | <td>'; |
| 1036 | 1089 | |
| 1037 | - foreach ($v as $i) |
|
| 1038 | - echo ' |
|
| 1090 | + foreach ($v as $i) { |
|
| 1091 | + echo ' |
|
| 1039 | 1092 | <img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">'; |
| 1093 | + } |
|
| 1040 | 1094 | |
| 1041 | 1095 | echo ' |
| 1042 | 1096 | </td> |
@@ -1058,9 +1112,10 @@ discard block |
||
| 1058 | 1112 | |
| 1059 | 1113 | foreach ($context['clockicons'] as $t => $v) |
| 1060 | 1114 | { |
| 1061 | - foreach ($v as $i) |
|
| 1062 | - echo ' |
|
| 1115 | + foreach ($v as $i) { |
|
| 1116 | + echo ' |
|
| 1063 | 1117 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 1118 | + } |
|
| 1064 | 1119 | } |
| 1065 | 1120 | |
| 1066 | 1121 | echo ' |
@@ -1077,13 +1132,14 @@ discard block |
||
| 1077 | 1132 | |
| 1078 | 1133 | foreach ($context['clockicons'] as $t => $v) |
| 1079 | 1134 | { |
| 1080 | - foreach ($v as $i) |
|
| 1081 | - echo ' |
|
| 1135 | + foreach ($v as $i) { |
|
| 1136 | + echo ' |
|
| 1082 | 1137 | if (', $t, ' >= ', $i, ') |
| 1083 | 1138 | { |
| 1084 | 1139 | turnon.push("', $t, '_', $i, '"); |
| 1085 | 1140 | ', $t, ' -= ', $i, '; |
| 1086 | 1141 | }'; |
| 1142 | + } |
|
| 1087 | 1143 | } |
| 1088 | 1144 | |
| 1089 | 1145 | echo ' |
@@ -1127,9 +1183,10 @@ discard block |
||
| 1127 | 1183 | <tr class="windowbg"> |
| 1128 | 1184 | <td>'; |
| 1129 | 1185 | |
| 1130 | - foreach ($v as $i) |
|
| 1131 | - echo ' |
|
| 1186 | + foreach ($v as $i) { |
|
| 1187 | + echo ' |
|
| 1132 | 1188 | <img src="', $context['offimg'], '" alt="" id="', $t, '_', $i, '" style="padding: 2px;">'; |
| 1189 | + } |
|
| 1133 | 1190 | |
| 1134 | 1191 | echo ' |
| 1135 | 1192 | </td> |
@@ -1145,9 +1202,10 @@ discard block |
||
| 1145 | 1202 | |
| 1146 | 1203 | foreach ($context['clockicons'] as $t => $v) |
| 1147 | 1204 | { |
| 1148 | - foreach ($v as $i) |
|
| 1149 | - echo ' |
|
| 1205 | + foreach ($v as $i) { |
|
| 1206 | + echo ' |
|
| 1150 | 1207 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
| 1208 | + } |
|
| 1151 | 1209 | } |
| 1152 | 1210 | |
| 1153 | 1211 | echo ' |
@@ -1168,13 +1226,14 @@ discard block |
||
| 1168 | 1226 | |
| 1169 | 1227 | foreach ($context['clockicons'] as $t => $v) |
| 1170 | 1228 | { |
| 1171 | - foreach ($v as $i) |
|
| 1172 | - echo ' |
|
| 1229 | + foreach ($v as $i) { |
|
| 1230 | + echo ' |
|
| 1173 | 1231 | if (', $t, ' >= ', $i, ') |
| 1174 | 1232 | { |
| 1175 | 1233 | turnon.push("', $t, '_', $i, '"); |
| 1176 | 1234 | ', $t, ' -= ', $i, '; |
| 1177 | 1235 | }'; |
| 1236 | + } |
|
| 1178 | 1237 | } |
| 1179 | 1238 | |
| 1180 | 1239 | echo ' |
@@ -1218,9 +1277,10 @@ discard block |
||
| 1218 | 1277 | <tr class="windowbg"> |
| 1219 | 1278 | <td>'; |
| 1220 | 1279 | |
| 1221 | - foreach ($v as $i) |
|
| 1222 | - echo ' |
|
| 1280 | + foreach ($v as $i) { |
|
| 1281 | + echo ' |
|
| 1223 | 1282 | <img src="', $i ? $context['onimg'] : $context['offimg'], '" alt="" style="padding: 2px;">'; |
| 1283 | + } |
|
| 1224 | 1284 | |
| 1225 | 1285 | echo ' |
| 1226 | 1286 | </td> |
@@ -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 | { |
@@ -841,13 +841,13 @@ discard block |
||
| 841 | 841 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
| 842 | 842 | if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
| 843 | 843 | $upcontext['warning'] = ' |
| 844 | - '. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br> |
|
| 844 | + '. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) . '<br> |
|
| 845 | 845 | <ul> |
| 846 | - <li>'. $txt['upgrade_boarddir'] .' ' . $boarddir . '</li> |
|
| 847 | - <li>'. $txt['upgrade_sourcedir'] .' ' . $boarddir . '</li> |
|
| 848 | - <li>'. $txt['upgrade_cachedir'] .' ' . $cachedir_temp . '</li> |
|
| 846 | + <li>'. $txt['upgrade_boarddir'] . ' ' . $boarddir . '</li> |
|
| 847 | + <li>'. $txt['upgrade_sourcedir'] . ' ' . $boarddir . '</li> |
|
| 848 | + <li>'. $txt['upgrade_cachedir'] . ' ' . $cachedir_temp . '</li> |
|
| 849 | 849 | </ul> |
| 850 | - '. $txt['upgrade_incorrect_settings'] .''; |
|
| 850 | + '. $txt['upgrade_incorrect_settings'] . ''; |
|
| 851 | 851 | |
| 852 | 852 | // Confirm mbstring is loaded... |
| 853 | 853 | if (!extension_loaded('mbstring')) |
@@ -1781,7 +1781,7 @@ discard block |
||
| 1781 | 1781 | |
| 1782 | 1782 | // Our custom error handler - does nothing but does stop public errors from XML! |
| 1783 | 1783 | set_error_handler( |
| 1784 | - function ($errno, $errstr, $errfile, $errline) use ($support_js) |
|
| 1784 | + function($errno, $errstr, $errfile, $errline) use ($support_js) |
|
| 1785 | 1785 | { |
| 1786 | 1786 | if ($support_js) |
| 1787 | 1787 | return true; |
@@ -2109,13 +2109,13 @@ discard block |
||
| 2109 | 2109 | |
| 2110 | 2110 | // Otherwise we have to display this somewhere appropriate if possible. |
| 2111 | 2111 | $upcontext['forced_error_message'] = ' |
| 2112 | - <strong>'. $txt['upgrade_unsuccessful'] .'</strong><br> |
|
| 2112 | + <strong>'. $txt['upgrade_unsuccessful'] . '</strong><br> |
|
| 2113 | 2113 | |
| 2114 | 2114 | <div style="margin: 2ex;"> |
| 2115 | - '. $txt['upgrade_thisquery'] .' |
|
| 2115 | + '. $txt['upgrade_thisquery'] . ' |
|
| 2116 | 2116 | <blockquote><pre>' . nl2br(htmlspecialchars(trim($string))) . ';</pre></blockquote> |
| 2117 | 2117 | |
| 2118 | - '. $txt['upgrade_causerror'] .' |
|
| 2118 | + '. $txt['upgrade_causerror'] . ' |
|
| 2119 | 2119 | <blockquote>' . nl2br(htmlspecialchars($db_error_message)) . '</blockquote> |
| 2120 | 2120 | </div> |
| 2121 | 2121 | |
@@ -2780,94 +2780,94 @@ discard block |
||
| 2780 | 2780 | // Translation table for the character sets not native for MySQL. |
| 2781 | 2781 | $translation_tables = array( |
| 2782 | 2782 | 'windows-1255' => array( |
| 2783 | - '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
| 2784 | - '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
| 2785 | - '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
| 2786 | - '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
| 2787 | - '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
| 2788 | - '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
| 2789 | - '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792', |
|
| 2790 | - '0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF', |
|
| 2791 | - '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
| 2792 | - '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
| 2793 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2794 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2795 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2796 | - '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
| 2797 | - '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
| 2798 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2799 | - '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
| 2800 | - '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
| 2801 | - '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
| 2802 | - '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
| 2803 | - '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
| 2804 | - '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
| 2805 | - '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
| 2806 | - '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
| 2807 | - '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
| 2808 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2809 | - '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
| 2810 | - '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2811 | - '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
| 2812 | - '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
| 2813 | - '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
| 2814 | - '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
| 2815 | - '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
| 2816 | - '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
| 2817 | - '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
| 2818 | - '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
| 2819 | - '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
| 2820 | - '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
| 2821 | - '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
| 2822 | - '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
| 2823 | - '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
| 2824 | - '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
| 2783 | + '0x81' => '\'\'', '0x8A' => '\'\'', '0x8C' => '\'\'', |
|
| 2784 | + '0x8D' => '\'\'', '0x8E' => '\'\'', '0x8F' => '\'\'', |
|
| 2785 | + '0x90' => '\'\'', '0x9A' => '\'\'', '0x9C' => '\'\'', |
|
| 2786 | + '0x9D' => '\'\'', '0x9E' => '\'\'', '0x9F' => '\'\'', |
|
| 2787 | + '0xCA' => '\'\'', '0xD9' => '\'\'', '0xDA' => '\'\'', |
|
| 2788 | + '0xDB' => '\'\'', '0xDC' => '\'\'', '0xDD' => '\'\'', |
|
| 2789 | + '0xDE' => '\'\'', '0xDF' => '\'\'', '0xFB' => '0xD792', |
|
| 2790 | + '0xFC' => '0xE282AC', '0xFF' => '0xD6B2', '0xC2' => '0xFF', |
|
| 2791 | + '0x80' => '0xFC', '0xE2' => '0xFB', '0xA0' => '0xC2A0', |
|
| 2792 | + '0xA1' => '0xC2A1', '0xA2' => '0xC2A2', '0xA3' => '0xC2A3', |
|
| 2793 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2794 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2795 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2796 | + '0xAF' => '0xC2AF', '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', |
|
| 2797 | + '0xB2' => '0xC2B2', '0xB3' => '0xC2B3', '0xB4' => '0xC2B4', |
|
| 2798 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2799 | + '0xB8' => '0xC2B8', '0xB9' => '0xC2B9', '0xBB' => '0xC2BB', |
|
| 2800 | + '0xBC' => '0xC2BC', '0xBD' => '0xC2BD', '0xBE' => '0xC2BE', |
|
| 2801 | + '0xBF' => '0xC2BF', '0xD7' => '0xD7B3', '0xD1' => '0xD781', |
|
| 2802 | + '0xD4' => '0xD7B0', '0xD5' => '0xD7B1', '0xD6' => '0xD7B2', |
|
| 2803 | + '0xE0' => '0xD790', '0xEA' => '0xD79A', '0xEC' => '0xD79C', |
|
| 2804 | + '0xED' => '0xD79D', '0xEE' => '0xD79E', '0xEF' => '0xD79F', |
|
| 2805 | + '0xF0' => '0xD7A0', '0xF1' => '0xD7A1', '0xF2' => '0xD7A2', |
|
| 2806 | + '0xF3' => '0xD7A3', '0xF5' => '0xD7A5', '0xF6' => '0xD7A6', |
|
| 2807 | + '0xF7' => '0xD7A7', '0xF8' => '0xD7A8', '0xF9' => '0xD7A9', |
|
| 2808 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2809 | + '0x86' => '0xE280A0', '0x87' => '0xE280A1', '0x89' => '0xE280B0', |
|
| 2810 | + '0x8B' => '0xE280B9', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2811 | + '0x95' => '0xE280A2', '0x97' => '0xE28094', '0x99' => '0xE284A2', |
|
| 2812 | + '0xC0' => '0xD6B0', '0xC1' => '0xD6B1', '0xC3' => '0xD6B3', |
|
| 2813 | + '0xC4' => '0xD6B4', '0xC5' => '0xD6B5', '0xC6' => '0xD6B6', |
|
| 2814 | + '0xC7' => '0xD6B7', '0xC8' => '0xD6B8', '0xC9' => '0xD6B9', |
|
| 2815 | + '0xCB' => '0xD6BB', '0xCC' => '0xD6BC', '0xCD' => '0xD6BD', |
|
| 2816 | + '0xCE' => '0xD6BE', '0xCF' => '0xD6BF', '0xD0' => '0xD780', |
|
| 2817 | + '0xD2' => '0xD782', '0xE3' => '0xD793', '0xE4' => '0xD794', |
|
| 2818 | + '0xE5' => '0xD795', '0xE7' => '0xD797', '0xE9' => '0xD799', |
|
| 2819 | + '0xFD' => '0xE2808E', '0xFE' => '0xE2808F', '0x92' => '0xE28099', |
|
| 2820 | + '0x83' => '0xC692', '0xD3' => '0xD783', '0x88' => '0xCB86', |
|
| 2821 | + '0x98' => '0xCB9C', '0x91' => '0xE28098', '0x96' => '0xE28093', |
|
| 2822 | + '0xBA' => '0xC3B7', '0x9B' => '0xE280BA', '0xAA' => '0xC397', |
|
| 2823 | + '0xA4' => '0xE282AA', '0xE1' => '0xD791', '0xE6' => '0xD796', |
|
| 2824 | + '0xE8' => '0xD798', '0xEB' => '0xD79B', '0xF4' => '0xD7A4', |
|
| 2825 | 2825 | '0xFA' => '0xD7AA', |
| 2826 | 2826 | ), |
| 2827 | 2827 | 'windows-1253' => array( |
| 2828 | - '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
| 2829 | - '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
| 2830 | - '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
| 2831 | - '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
| 2832 | - '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
| 2833 | - '0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E', |
|
| 2834 | - '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
| 2835 | - '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
| 2836 | - '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
| 2837 | - '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
| 2838 | - '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
| 2839 | - '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
| 2840 | - '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
| 2841 | - '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
| 2842 | - '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2843 | - '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2844 | - '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2845 | - '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
| 2846 | - '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2847 | - '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
| 2848 | - '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2849 | - '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
| 2850 | - '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
| 2851 | - '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
| 2852 | - '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2853 | - '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
| 2854 | - '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
| 2855 | - '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
| 2856 | - '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
| 2857 | - '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
| 2858 | - '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
| 2859 | - '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
| 2860 | - '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
| 2861 | - '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
| 2862 | - '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
| 2863 | - '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
| 2864 | - '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
| 2865 | - '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
| 2866 | - '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
| 2867 | - '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
| 2868 | - '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
| 2869 | - '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
| 2870 | - '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', |
|
| 2828 | + '0x81' => '\'\'', '0x88' => '\'\'', '0x8A' => '\'\'', |
|
| 2829 | + '0x8C' => '\'\'', '0x8D' => '\'\'', '0x8E' => '\'\'', |
|
| 2830 | + '0x8F' => '\'\'', '0x90' => '\'\'', '0x98' => '\'\'', |
|
| 2831 | + '0x9A' => '\'\'', '0x9C' => '\'\'', '0x9D' => '\'\'', |
|
| 2832 | + '0x9E' => '\'\'', '0x9F' => '\'\'', '0xAA' => '\'\'', |
|
| 2833 | + '0xD2' => '0xE282AC', '0xFF' => '0xCE92', '0xCE' => '0xCE9E', |
|
| 2834 | + '0xB8' => '0xCE88', '0xBA' => '0xCE8A', '0xBC' => '0xCE8C', |
|
| 2835 | + '0xBE' => '0xCE8E', '0xBF' => '0xCE8F', '0xC0' => '0xCE90', |
|
| 2836 | + '0xC8' => '0xCE98', '0xCA' => '0xCE9A', '0xCC' => '0xCE9C', |
|
| 2837 | + '0xCD' => '0xCE9D', '0xCF' => '0xCE9F', '0xDA' => '0xCEAA', |
|
| 2838 | + '0xE8' => '0xCEB8', '0xEA' => '0xCEBA', '0xEC' => '0xCEBC', |
|
| 2839 | + '0xEE' => '0xCEBE', '0xEF' => '0xCEBF', '0xC2' => '0xFF', |
|
| 2840 | + '0xBD' => '0xC2BD', '0xED' => '0xCEBD', '0xB2' => '0xC2B2', |
|
| 2841 | + '0xA0' => '0xC2A0', '0xA3' => '0xC2A3', '0xA4' => '0xC2A4', |
|
| 2842 | + '0xA5' => '0xC2A5', '0xA6' => '0xC2A6', '0xA7' => '0xC2A7', |
|
| 2843 | + '0xA8' => '0xC2A8', '0xA9' => '0xC2A9', '0xAB' => '0xC2AB', |
|
| 2844 | + '0xAC' => '0xC2AC', '0xAD' => '0xC2AD', '0xAE' => '0xC2AE', |
|
| 2845 | + '0xB0' => '0xC2B0', '0xB1' => '0xC2B1', '0xB3' => '0xC2B3', |
|
| 2846 | + '0xB5' => '0xC2B5', '0xB6' => '0xC2B6', '0xB7' => '0xC2B7', |
|
| 2847 | + '0xBB' => '0xC2BB', '0xE2' => '0xCEB2', '0x80' => '0xD2', |
|
| 2848 | + '0x82' => '0xE2809A', '0x84' => '0xE2809E', '0x85' => '0xE280A6', |
|
| 2849 | + '0x86' => '0xE280A0', '0xA1' => '0xCE85', '0xA2' => '0xCE86', |
|
| 2850 | + '0x87' => '0xE280A1', '0x89' => '0xE280B0', '0xB9' => '0xCE89', |
|
| 2851 | + '0x8B' => '0xE280B9', '0x91' => '0xE28098', '0x99' => '0xE284A2', |
|
| 2852 | + '0x92' => '0xE28099', '0x93' => '0xE2809C', '0x94' => '0xE2809D', |
|
| 2853 | + '0x95' => '0xE280A2', '0x96' => '0xE28093', '0x97' => '0xE28094', |
|
| 2854 | + '0x9B' => '0xE280BA', '0xAF' => '0xE28095', '0xB4' => '0xCE84', |
|
| 2855 | + '0xC1' => '0xCE91', '0xC3' => '0xCE93', '0xC4' => '0xCE94', |
|
| 2856 | + '0xC5' => '0xCE95', '0xC6' => '0xCE96', '0x83' => '0xC692', |
|
| 2857 | + '0xC7' => '0xCE97', '0xC9' => '0xCE99', '0xCB' => '0xCE9B', |
|
| 2858 | + '0xD0' => '0xCEA0', '0xD1' => '0xCEA1', '0xD3' => '0xCEA3', |
|
| 2859 | + '0xD4' => '0xCEA4', '0xD5' => '0xCEA5', '0xD6' => '0xCEA6', |
|
| 2860 | + '0xD7' => '0xCEA7', '0xD8' => '0xCEA8', '0xD9' => '0xCEA9', |
|
| 2861 | + '0xDB' => '0xCEAB', '0xDC' => '0xCEAC', '0xDD' => '0xCEAD', |
|
| 2862 | + '0xDE' => '0xCEAE', '0xDF' => '0xCEAF', '0xE0' => '0xCEB0', |
|
| 2863 | + '0xE1' => '0xCEB1', '0xE3' => '0xCEB3', '0xE4' => '0xCEB4', |
|
| 2864 | + '0xE5' => '0xCEB5', '0xE6' => '0xCEB6', '0xE7' => '0xCEB7', |
|
| 2865 | + '0xE9' => '0xCEB9', '0xEB' => '0xCEBB', '0xF0' => '0xCF80', |
|
| 2866 | + '0xF1' => '0xCF81', '0xF2' => '0xCF82', '0xF3' => '0xCF83', |
|
| 2867 | + '0xF4' => '0xCF84', '0xF5' => '0xCF85', '0xF6' => '0xCF86', |
|
| 2868 | + '0xF7' => '0xCF87', '0xF8' => '0xCF88', '0xF9' => '0xCF89', |
|
| 2869 | + '0xFA' => '0xCF8A', '0xFB' => '0xCF8B', '0xFC' => '0xCF8C', |
|
| 2870 | + '0xFD' => '0xCF8D', '0xFE' => '0xCF8E', |
|
| 2871 | 2871 | ), |
| 2872 | 2872 | ); |
| 2873 | 2873 | |
@@ -3081,7 +3081,7 @@ discard block |
||
| 3081 | 3081 | |
| 3082 | 3082 | if ($upcontext['dropping_index'] && $command_line) |
| 3083 | 3083 | { |
| 3084 | - echo "\n" . '', $txt['upgrade_fulltext_error'] ,''; |
|
| 3084 | + echo "\n" . '', $txt['upgrade_fulltext_error'], ''; |
|
| 3085 | 3085 | flush(); |
| 3086 | 3086 | } |
| 3087 | 3087 | } |
@@ -3425,7 +3425,7 @@ discard block |
||
| 3425 | 3425 | { |
| 3426 | 3426 | echo ' |
| 3427 | 3427 | <div class="error"> |
| 3428 | - <p>', $txt['upgrade_writable_files'] ,'</p> |
|
| 3428 | + <p>', $txt['upgrade_writable_files'], '</p> |
|
| 3429 | 3429 | <ul class="error_content"> |
| 3430 | 3430 | <li>' . implode('</li> |
| 3431 | 3431 | <li>', $upcontext['chmod']['files']) . '</li> |
@@ -3791,12 +3791,12 @@ discard block |
||
| 3791 | 3791 | <div class="errorbox"> |
| 3792 | 3792 | <h3>', $txt['upgrade_warning'], '</h3> |
| 3793 | 3793 | <p>', sprintf($txt['upgrade_time_user'], $upcontext['user']['name']), '</p> |
| 3794 | - <p>', sprintf($txt[$agoTxt], $ago_seconds, $ago_minutes, $ago_hours), '</p> |
|
| 3794 | + <p>', sprintf($txt[$agoTxt], $ago_seconds, $ago_minutes, $ago_hours), '</p> |
|
| 3795 | 3795 | <p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>'; |
| 3796 | 3796 | |
| 3797 | 3797 | if ($updated < 600) |
| 3798 | 3798 | echo ' |
| 3799 | - <p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>'; |
|
| 3799 | + <p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_run_script2'], '</p>'; |
|
| 3800 | 3800 | |
| 3801 | 3801 | if ($updated > $upcontext['inactive_timeout']) |
| 3802 | 3802 | echo ' |
@@ -3905,7 +3905,7 @@ discard block |
||
| 3905 | 3905 | if (!empty($upcontext['upgrade_options_warning'])) |
| 3906 | 3906 | echo ' |
| 3907 | 3907 | <div class="errorbox"> |
| 3908 | - <h3>', $txt['upgrade_warning'] ,'</h3> |
|
| 3908 | + <h3>', $txt['upgrade_warning'], '</h3> |
|
| 3909 | 3909 | ', $upcontext['upgrade_options_warning'], ' |
| 3910 | 3910 | </div>'; |
| 3911 | 3911 | |
@@ -3969,7 +3969,7 @@ discard block |
||
| 3969 | 3969 | echo ' |
| 3970 | 3970 | <form action="', $upcontext['form_url'], '" name="upform" id="upform" method="post"> |
| 3971 | 3971 | <input type="hidden" name="backup_done" id="backup_done" value="0"> |
| 3972 | - <strong>', sprintf($txt['upgrade_completedtables_outof'], $upcontext['cur_table_num'], $upcontext['table_count']) ,'</strong> |
|
| 3972 | + <strong>', sprintf($txt['upgrade_completedtables_outof'], $upcontext['cur_table_num'], $upcontext['table_count']), '</strong> |
|
| 3973 | 3973 | <div id="debug_section"> |
| 3974 | 3974 | <span id="debuginfo"></span> |
| 3975 | 3975 | </div>'; |
@@ -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 | |
@@ -107,11 +108,14 @@ discard block |
||
| 107 | 108 | ini_set('default_socket_timeout', 900); |
| 108 | 109 | } |
| 109 | 110 | // Clean the upgrade path if this is from the client. |
| 110 | -if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) |
|
| 111 | - for ($i = 1; $i < $_SERVER['argc']; $i++) |
|
| 111 | +if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { |
|
| 112 | + for ($i = 1; |
|
| 113 | +} |
|
| 114 | +$i < $_SERVER['argc']; $i++) |
|
| 112 | 115 | { |
| 113 | - if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) |
|
| 114 | - $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 116 | + if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) { |
|
| 117 | + $upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1]; |
|
| 118 | + } |
|
| 115 | 119 | } |
| 116 | 120 | |
| 117 | 121 | // Are we from the client? |
@@ -119,16 +123,17 @@ discard block |
||
| 119 | 123 | { |
| 120 | 124 | $command_line = true; |
| 121 | 125 | $disable_security = true; |
| 122 | -} |
|
| 123 | -else |
|
| 126 | +} else { |
|
| 124 | 127 | $command_line = false; |
| 128 | +} |
|
| 125 | 129 | |
| 126 | 130 | // Load this now just because we can. |
| 127 | 131 | require_once($upgrade_path . '/Settings.php'); |
| 128 | 132 | |
| 129 | 133 | // We don't use "-utf8" anymore... Tweak the entry that may have been loaded by Settings.php |
| 130 | -if (isset($language)) |
|
| 134 | +if (isset($language)) { |
|
| 131 | 135 | $language = str_ireplace('-utf8', '', $language); |
| 136 | +} |
|
| 132 | 137 | |
| 133 | 138 | // Are we logged in? |
| 134 | 139 | if (isset($upgradeData)) |
@@ -136,10 +141,12 @@ discard block |
||
| 136 | 141 | $upcontext['user'] = json_decode(base64_decode($upgradeData), true); |
| 137 | 142 | |
| 138 | 143 | // Check for sensible values. |
| 139 | - if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) |
|
| 140 | - $upcontext['user']['started'] = time(); |
|
| 141 | - if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) |
|
| 142 | - $upcontext['user']['updated'] = 0; |
|
| 144 | + if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) { |
|
| 145 | + $upcontext['user']['started'] = time(); |
|
| 146 | + } |
|
| 147 | + if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) { |
|
| 148 | + $upcontext['user']['updated'] = 0; |
|
| 149 | + } |
|
| 143 | 150 | |
| 144 | 151 | $upcontext['started'] = $upcontext['user']['started']; |
| 145 | 152 | $upcontext['updated'] = $upcontext['user']['updated']; |
@@ -204,8 +211,9 @@ discard block |
||
| 204 | 211 | 'db_error_skip' => true, |
| 205 | 212 | ) |
| 206 | 213 | ); |
| 207 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 208 | - $modSettings[$row['variable']] = $row['value']; |
|
| 214 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 215 | + $modSettings[$row['variable']] = $row['value']; |
|
| 216 | + } |
|
| 209 | 217 | $smcFunc['db_free_result']($request); |
| 210 | 218 | } |
| 211 | 219 | |
@@ -215,14 +223,17 @@ discard block |
||
| 215 | 223 | $modSettings['theme_url'] = 'Themes/default'; |
| 216 | 224 | $modSettings['images_url'] = 'Themes/default/images'; |
| 217 | 225 | } |
| 218 | -if (!isset($settings['default_theme_url'])) |
|
| 226 | +if (!isset($settings['default_theme_url'])) { |
|
| 219 | 227 | $settings['default_theme_url'] = $modSettings['theme_url']; |
| 220 | -if (!isset($settings['default_theme_dir'])) |
|
| 228 | +} |
|
| 229 | +if (!isset($settings['default_theme_dir'])) { |
|
| 221 | 230 | $settings['default_theme_dir'] = $modSettings['theme_dir']; |
| 231 | +} |
|
| 222 | 232 | |
| 223 | 233 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
| 224 | -if (httpsOn()) |
|
| 234 | +if (httpsOn()) { |
|
| 225 | 235 | $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
| 236 | +} |
|
| 226 | 237 | |
| 227 | 238 | $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000; |
| 228 | 239 | // Default title... |
@@ -240,13 +251,15 @@ discard block |
||
| 240 | 251 | $support_js = $upcontext['upgrade_status']['js']; |
| 241 | 252 | |
| 242 | 253 | // Only set this if the upgrader status says so. |
| 243 | - if (empty($is_debug)) |
|
| 244 | - $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 254 | + if (empty($is_debug)) { |
|
| 255 | + $is_debug = $upcontext['upgrade_status']['debug']; |
|
| 256 | + } |
|
| 245 | 257 | |
| 246 | 258 | // Load the language. |
| 247 | - if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 248 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 249 | -} |
|
| 259 | + if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 260 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 261 | + } |
|
| 262 | + } |
|
| 250 | 263 | // Set the defaults. |
| 251 | 264 | else |
| 252 | 265 | { |
@@ -264,15 +277,18 @@ discard block |
||
| 264 | 277 | } |
| 265 | 278 | |
| 266 | 279 | // If this isn't the first stage see whether they are logging in and resuming. |
| 267 | -if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) |
|
| 280 | +if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) { |
|
| 268 | 281 | checkLogin(); |
| 282 | +} |
|
| 269 | 283 | |
| 270 | -if ($command_line) |
|
| 284 | +if ($command_line) { |
|
| 271 | 285 | cmdStep0(); |
| 286 | +} |
|
| 272 | 287 | |
| 273 | 288 | // Don't error if we're using xml. |
| 274 | -if (isset($_GET['xml'])) |
|
| 289 | +if (isset($_GET['xml'])) { |
|
| 275 | 290 | $upcontext['return_error'] = true; |
| 291 | +} |
|
| 276 | 292 | |
| 277 | 293 | // Loop through all the steps doing each one as required. |
| 278 | 294 | $upcontext['overall_percent'] = 0; |
@@ -293,9 +309,9 @@ discard block |
||
| 293 | 309 | } |
| 294 | 310 | |
| 295 | 311 | // Call the step and if it returns false that means pause! |
| 296 | - if (function_exists($step[2]) && $step[2]() === false) |
|
| 297 | - break; |
|
| 298 | - elseif (function_exists($step[2])) { |
|
| 312 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
| 313 | + break; |
|
| 314 | + } elseif (function_exists($step[2])) { |
|
| 299 | 315 | //Start each new step with this unset, so the 'normal' template is called first |
| 300 | 316 | unset($_GET['xml']); |
| 301 | 317 | //Clear out warnings at the start of each step |
@@ -341,17 +357,18 @@ discard block |
||
| 341 | 357 | // This should not happen my dear... HELP ME DEVELOPERS!! |
| 342 | 358 | if (!empty($command_line)) |
| 343 | 359 | { |
| 344 | - if (function_exists('debug_print_backtrace')) |
|
| 345 | - debug_print_backtrace(); |
|
| 360 | + if (function_exists('debug_print_backtrace')) { |
|
| 361 | + debug_print_backtrace(); |
|
| 362 | + } |
|
| 346 | 363 | |
| 347 | 364 | 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.'; |
| 348 | 365 | flush(); |
| 349 | 366 | die(); |
| 350 | 367 | } |
| 351 | 368 | |
| 352 | - if (!isset($_GET['xml'])) |
|
| 353 | - template_upgrade_above(); |
|
| 354 | - else |
|
| 369 | + if (!isset($_GET['xml'])) { |
|
| 370 | + template_upgrade_above(); |
|
| 371 | + } else |
|
| 355 | 372 | { |
| 356 | 373 | header('content-type: text/xml; charset=UTF-8'); |
| 357 | 374 | // Sadly we need to retain the $_GET data thanks to the old upgrade scripts. |
@@ -373,25 +390,29 @@ discard block |
||
| 373 | 390 | $upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&substep=' . $_GET['substep'] . '&data=' . base64_encode(json_encode($upcontext['upgrade_status'])); |
| 374 | 391 | |
| 375 | 392 | // Custom stuff to pass back? |
| 376 | - if (!empty($upcontext['query_string'])) |
|
| 377 | - $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 393 | + if (!empty($upcontext['query_string'])) { |
|
| 394 | + $upcontext['form_url'] .= $upcontext['query_string']; |
|
| 395 | + } |
|
| 378 | 396 | |
| 379 | 397 | // Call the appropriate subtemplate |
| 380 | - if (is_callable('template_' . $upcontext['sub_template'])) |
|
| 381 | - call_user_func('template_' . $upcontext['sub_template']); |
|
| 382 | - else |
|
| 383 | - die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 398 | + if (is_callable('template_' . $upcontext['sub_template'])) { |
|
| 399 | + call_user_func('template_' . $upcontext['sub_template']); |
|
| 400 | + } else { |
|
| 401 | + die('Upgrade aborted! Invalid template: template_' . $upcontext['sub_template']); |
|
| 402 | + } |
|
| 384 | 403 | } |
| 385 | 404 | |
| 386 | 405 | // Was there an error? |
| 387 | - if (!empty($upcontext['forced_error_message'])) |
|
| 388 | - echo $upcontext['forced_error_message']; |
|
| 406 | + if (!empty($upcontext['forced_error_message'])) { |
|
| 407 | + echo $upcontext['forced_error_message']; |
|
| 408 | + } |
|
| 389 | 409 | |
| 390 | 410 | // Show the footer. |
| 391 | - if (!isset($_GET['xml'])) |
|
| 392 | - template_upgrade_below(); |
|
| 393 | - else |
|
| 394 | - template_xml_below(); |
|
| 411 | + if (!isset($_GET['xml'])) { |
|
| 412 | + template_upgrade_below(); |
|
| 413 | + } else { |
|
| 414 | + template_xml_below(); |
|
| 415 | + } |
|
| 395 | 416 | } |
| 396 | 417 | |
| 397 | 418 | // Show the upgrade time for CLI when we are completely done, if in debug mode. |
@@ -403,12 +424,13 @@ discard block |
||
| 403 | 424 | $seconds = intval($active % 60); |
| 404 | 425 | |
| 405 | 426 | $totalTime = ''; |
| 406 | - if ($hours > 0) |
|
| 407 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
| 408 | - elseif ($minutes > 0) |
|
| 409 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
| 410 | - elseif ($seconds > 0) |
|
| 411 | - echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
| 427 | + if ($hours > 0) { |
|
| 428 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n"; |
|
| 429 | + } elseif ($minutes > 0) { |
|
| 430 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n"; |
|
| 431 | + } elseif ($seconds > 0) { |
|
| 432 | + echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n"; |
|
| 433 | + } |
|
| 412 | 434 | } |
| 413 | 435 | |
| 414 | 436 | // Bang - gone! |
@@ -429,8 +451,9 @@ discard block |
||
| 429 | 451 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
| 430 | 452 | while ($entry = $dir->read()) |
| 431 | 453 | { |
| 432 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
| 433 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 454 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
| 455 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
| 456 | + } |
|
| 434 | 457 | } |
| 435 | 458 | $dir->close(); |
| 436 | 459 | } |
@@ -474,10 +497,11 @@ discard block |
||
| 474 | 497 | } |
| 475 | 498 | |
| 476 | 499 | // Override the language file? |
| 477 | - if (isset($_GET['lang_file'])) |
|
| 478 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 479 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
| 480 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 500 | + if (isset($_GET['lang_file'])) { |
|
| 501 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
| 502 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
| 503 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
| 504 | + } |
|
| 481 | 505 | |
| 482 | 506 | // Make sure it exists, if it doesn't reset it. |
| 483 | 507 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -486,12 +510,14 @@ discard block |
||
| 486 | 510 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
| 487 | 511 | |
| 488 | 512 | // If we have english and some other language, use the other language. We Americans hate english :P. |
| 489 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
| 490 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 513 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
| 514 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
| 515 | + } |
|
| 491 | 516 | |
| 492 | 517 | // For backup we load the english at first -> second language overwrite the english one |
| 493 | - if (count($incontext['detected_languages']) > 1) |
|
| 494 | - require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
| 518 | + if (count($incontext['detected_languages']) > 1) { |
|
| 519 | + require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php'); |
|
| 520 | + } |
|
| 495 | 521 | } |
| 496 | 522 | |
| 497 | 523 | // And now include the actual language file itself. |
@@ -499,11 +525,12 @@ discard block |
||
| 499 | 525 | |
| 500 | 526 | // Which language did we load? Assume that he likes his language. |
| 501 | 527 | preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches); |
| 502 | - if (empty($matches[1])) |
|
| 503 | - $matches = [ |
|
| 528 | + if (empty($matches[1])) { |
|
| 529 | + $matches = [ |
|
| 504 | 530 | 0 => 'nothing', |
| 505 | 531 | 1 => 'english', |
| 506 | 532 | ]; |
| 533 | + } |
|
| 507 | 534 | $user_info['language'] = $matches[1]; |
| 508 | 535 | } |
| 509 | 536 | |
@@ -513,8 +540,9 @@ discard block |
||
| 513 | 540 | global $upgradeurl, $upcontext, $command_line; |
| 514 | 541 | |
| 515 | 542 | // Command line users can't be redirected. |
| 516 | - if ($command_line) |
|
| 517 | - upgradeExit(true); |
|
| 543 | + if ($command_line) { |
|
| 544 | + upgradeExit(true); |
|
| 545 | + } |
|
| 518 | 546 | |
| 519 | 547 | // Are we providing the core info? |
| 520 | 548 | if ($addForm) |
@@ -540,12 +568,14 @@ discard block |
||
| 540 | 568 | define('SMF', 1); |
| 541 | 569 | |
| 542 | 570 | // Start the session. |
| 543 | - if (@ini_get('session.save_handler') == 'user') |
|
| 544 | - @ini_set('session.save_handler', 'files'); |
|
| 571 | + if (@ini_get('session.save_handler') == 'user') { |
|
| 572 | + @ini_set('session.save_handler', 'files'); |
|
| 573 | + } |
|
| 545 | 574 | @session_start(); |
| 546 | 575 | |
| 547 | - if (empty($smcFunc)) |
|
| 548 | - $smcFunc = array(); |
|
| 576 | + if (empty($smcFunc)) { |
|
| 577 | + $smcFunc = array(); |
|
| 578 | + } |
|
| 549 | 579 | |
| 550 | 580 | // We need this for authentication and some upgrade code |
| 551 | 581 | require_once($sourcedir . '/Subs-Auth.php'); |
@@ -576,30 +606,34 @@ discard block |
||
| 576 | 606 | { |
| 577 | 607 | $options = array('non_fatal' => true); |
| 578 | 608 | // Add in the port if needed |
| 579 | - if (!empty($db_port)) |
|
| 580 | - $options['port'] = $db_port; |
|
| 609 | + if (!empty($db_port)) { |
|
| 610 | + $options['port'] = $db_port; |
|
| 611 | + } |
|
| 581 | 612 | |
| 582 | - if (!empty($db_mb4)) |
|
| 583 | - $options['db_mb4'] = $db_mb4; |
|
| 613 | + if (!empty($db_mb4)) { |
|
| 614 | + $options['db_mb4'] = $db_mb4; |
|
| 615 | + } |
|
| 584 | 616 | |
| 585 | 617 | $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); |
| 586 | - } |
|
| 587 | - else |
|
| 588 | - // If we've returned here, ping/reconnect to be safe |
|
| 618 | + } else { |
|
| 619 | + // If we've returned here, ping/reconnect to be safe |
|
| 589 | 620 | $smcFunc['db_ping']($db_connection); |
| 621 | + } |
|
| 590 | 622 | |
| 591 | 623 | // Oh dear god!! |
| 592 | - if ($db_connection === null) |
|
| 593 | - die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 624 | + if ($db_connection === null) { |
|
| 625 | + die('Unable to connect to database - please check username and password are correct in Settings.php'); |
|
| 626 | + } |
|
| 594 | 627 | |
| 595 | - if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) |
|
| 596 | - $smcFunc['db_query']('', ' |
|
| 628 | + if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) { |
|
| 629 | + $smcFunc['db_query']('', ' |
|
| 597 | 630 | SET NAMES {string:db_character_set}', |
| 598 | 631 | array( |
| 599 | 632 | 'db_error_skip' => true, |
| 600 | 633 | 'db_character_set' => $db_character_set, |
| 601 | 634 | ) |
| 602 | 635 | ); |
| 636 | + } |
|
| 603 | 637 | |
| 604 | 638 | // Load the modSettings data... |
| 605 | 639 | $request = $smcFunc['db_query']('', ' |
@@ -610,11 +644,11 @@ discard block |
||
| 610 | 644 | ) |
| 611 | 645 | ); |
| 612 | 646 | $modSettings = array(); |
| 613 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 614 | - $modSettings[$row['variable']] = $row['value']; |
|
| 647 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 648 | + $modSettings[$row['variable']] = $row['value']; |
|
| 649 | + } |
|
| 615 | 650 | $smcFunc['db_free_result']($request); |
| 616 | - } |
|
| 617 | - else |
|
| 651 | + } else |
|
| 618 | 652 | { |
| 619 | 653 | 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.'); |
| 620 | 654 | } |
@@ -628,9 +662,10 @@ discard block |
||
| 628 | 662 | cleanRequest(); |
| 629 | 663 | } |
| 630 | 664 | |
| 631 | - if (!isset($_GET['substep'])) |
|
| 632 | - $_GET['substep'] = 0; |
|
| 633 | -} |
|
| 665 | + if (!isset($_GET['substep'])) { |
|
| 666 | + $_GET['substep'] = 0; |
|
| 667 | + } |
|
| 668 | + } |
|
| 634 | 669 | |
| 635 | 670 | function initialize_inputs() |
| 636 | 671 | { |
@@ -660,8 +695,9 @@ discard block |
||
| 660 | 695 | $dh = opendir(dirname(__FILE__)); |
| 661 | 696 | while ($file = readdir($dh)) |
| 662 | 697 | { |
| 663 | - if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) |
|
| 664 | - @unlink(dirname(__FILE__) . '/' . $file); |
|
| 698 | + if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) { |
|
| 699 | + @unlink(dirname(__FILE__) . '/' . $file); |
|
| 700 | + } |
|
| 665 | 701 | } |
| 666 | 702 | closedir($dh); |
| 667 | 703 | |
@@ -690,8 +726,9 @@ discard block |
||
| 690 | 726 | $temp = 'upgrade_php?step'; |
| 691 | 727 | while (strlen($temp) > 4) |
| 692 | 728 | { |
| 693 | - if (isset($_GET[$temp])) |
|
| 694 | - unset($_GET[$temp]); |
|
| 729 | + if (isset($_GET[$temp])) { |
|
| 730 | + unset($_GET[$temp]); |
|
| 731 | + } |
|
| 695 | 732 | $temp = substr($temp, 1); |
| 696 | 733 | } |
| 697 | 734 | |
@@ -718,32 +755,39 @@ discard block |
||
| 718 | 755 | && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql'); |
| 719 | 756 | |
| 720 | 757 | // Need legacy scripts? |
| 721 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) |
|
| 722 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 723 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) |
|
| 724 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 725 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) |
|
| 726 | - $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 758 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) { |
|
| 759 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql'); |
|
| 760 | + } |
|
| 761 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) { |
|
| 762 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); |
|
| 763 | + } |
|
| 764 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) { |
|
| 765 | + $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql'); |
|
| 766 | + } |
|
| 727 | 767 | |
| 728 | 768 | // We don't need "-utf8" files anymore... |
| 729 | 769 | $upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']); |
| 730 | 770 | |
| 731 | 771 | // This needs to exist! |
| 732 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 733 | - 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>]'); |
|
| 734 | - else |
|
| 735 | - require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 772 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 773 | + 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>]'); |
|
| 774 | + } else { |
|
| 775 | + require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
|
| 776 | + } |
|
| 736 | 777 | |
| 737 | - if (!$check) |
|
| 738 | - // 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. |
|
| 778 | + if (!$check) { |
|
| 779 | + // 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. |
|
| 739 | 780 | 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.'); |
| 781 | + } |
|
| 740 | 782 | |
| 741 | 783 | // Do they meet the install requirements? |
| 742 | - if (!php_version_check()) |
|
| 743 | - 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.'); |
|
| 784 | + if (!php_version_check()) { |
|
| 785 | + 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.'); |
|
| 786 | + } |
|
| 744 | 787 | |
| 745 | - if (!db_version_check()) |
|
| 746 | - 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.'); |
|
| 788 | + if (!db_version_check()) { |
|
| 789 | + 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.'); |
|
| 790 | + } |
|
| 747 | 791 | |
| 748 | 792 | // Do some checks to make sure they have proper privileges |
| 749 | 793 | db_extend('packages'); |
@@ -758,14 +802,16 @@ discard block |
||
| 758 | 802 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 759 | 803 | |
| 760 | 804 | // Sorry... we need CREATE, ALTER and DROP |
| 761 | - if (!$create || !$alter || !$drop) |
|
| 762 | - 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.'); |
|
| 805 | + if (!$create || !$alter || !$drop) { |
|
| 806 | + 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.'); |
|
| 807 | + } |
|
| 763 | 808 | |
| 764 | 809 | // Do a quick version spot check. |
| 765 | 810 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 766 | 811 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 767 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 768 | - 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.'); |
|
| 812 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 813 | + 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.'); |
|
| 814 | + } |
|
| 769 | 815 | |
| 770 | 816 | // What absolutely needs to be writable? |
| 771 | 817 | $writable_files = array( |
@@ -774,12 +820,13 @@ discard block |
||
| 774 | 820 | ); |
| 775 | 821 | |
| 776 | 822 | // Only check for minified writable files if we have it enabled or not set. |
| 777 | - if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) |
|
| 778 | - $writable_files += array( |
|
| 823 | + if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) { |
|
| 824 | + $writable_files += array( |
|
| 779 | 825 | $modSettings['theme_dir'] . '/css/minified.css', |
| 780 | 826 | $modSettings['theme_dir'] . '/scripts/minified.js', |
| 781 | 827 | $modSettings['theme_dir'] . '/scripts/minified_deferred.js', |
| 782 | 828 | ); |
| 829 | + } |
|
| 783 | 830 | |
| 784 | 831 | // Do we need to add this setting? |
| 785 | 832 | $need_settings_update = empty($modSettings['custom_avatar_dir']); |
@@ -791,12 +838,13 @@ discard block |
||
| 791 | 838 | quickFileWritable($custom_av_dir); |
| 792 | 839 | |
| 793 | 840 | // Are we good now? |
| 794 | - if (!is_writable($custom_av_dir)) |
|
| 795 | - 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)); |
|
| 796 | - elseif ($need_settings_update) |
|
| 841 | + if (!is_writable($custom_av_dir)) { |
|
| 842 | + 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)); |
|
| 843 | + } elseif ($need_settings_update) |
|
| 797 | 844 | { |
| 798 | - if (!function_exists('cache_put_data')) |
|
| 799 | - require_once($sourcedir . '/Load.php'); |
|
| 845 | + if (!function_exists('cache_put_data')) { |
|
| 846 | + require_once($sourcedir . '/Load.php'); |
|
| 847 | + } |
|
| 800 | 848 | |
| 801 | 849 | updateSettings(array('custom_avatar_dir' => $custom_av_dir)); |
| 802 | 850 | updateSettings(array('custom_avatar_url' => $custom_av_url)); |
@@ -806,29 +854,34 @@ discard block |
||
| 806 | 854 | |
| 807 | 855 | // Check the cache directory. |
| 808 | 856 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 809 | - if (!file_exists($cachedir_temp)) |
|
| 810 | - @mkdir($cachedir_temp); |
|
| 857 | + if (!file_exists($cachedir_temp)) { |
|
| 858 | + @mkdir($cachedir_temp); |
|
| 859 | + } |
|
| 811 | 860 | |
| 812 | - if (!file_exists($cachedir_temp)) |
|
| 813 | - 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.'); |
|
| 861 | + if (!file_exists($cachedir_temp)) { |
|
| 862 | + 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.'); |
|
| 863 | + } |
|
| 814 | 864 | |
| 815 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 816 | - 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>.'); |
|
| 817 | - elseif (!isset($_GET['skiplang'])) |
|
| 865 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 866 | + 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>.'); |
|
| 867 | + } elseif (!isset($_GET['skiplang'])) |
|
| 818 | 868 | { |
| 819 | 869 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 820 | 870 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 821 | 871 | |
| 822 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 823 | - 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>]'); |
|
| 872 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 873 | + 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>]'); |
|
| 874 | + } |
|
| 824 | 875 | } |
| 825 | 876 | |
| 826 | - if (!makeFilesWritable($writable_files)) |
|
| 827 | - return false; |
|
| 877 | + if (!makeFilesWritable($writable_files)) { |
|
| 878 | + return false; |
|
| 879 | + } |
|
| 828 | 880 | |
| 829 | 881 | // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) |
| 830 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 831 | - 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.'); |
|
| 882 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 883 | + 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.'); |
|
| 884 | + } |
|
| 832 | 885 | |
| 833 | 886 | // Upgrade the agreement. |
| 834 | 887 | elseif (isset($modSettings['agreement'])) |
@@ -839,8 +892,8 @@ discard block |
||
| 839 | 892 | } |
| 840 | 893 | |
| 841 | 894 | // We're going to check that their board dir setting is right in case they've been moving stuff around. |
| 842 | - if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) |
|
| 843 | - $upcontext['warning'] = ' |
|
| 895 | + if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) { |
|
| 896 | + $upcontext['warning'] = ' |
|
| 844 | 897 | '. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br> |
| 845 | 898 | <ul> |
| 846 | 899 | <li>'. $txt['upgrade_boarddir'] .' ' . $boarddir . '</li> |
@@ -848,19 +901,23 @@ discard block |
||
| 848 | 901 | <li>'. $txt['upgrade_cachedir'] .' ' . $cachedir_temp . '</li> |
| 849 | 902 | </ul> |
| 850 | 903 | '. $txt['upgrade_incorrect_settings'] .''; |
| 904 | + } |
|
| 851 | 905 | |
| 852 | 906 | // Confirm mbstring is loaded... |
| 853 | - if (!extension_loaded('mbstring')) |
|
| 854 | - return throw_error($txt['install_no_mbstring']); |
|
| 907 | + if (!extension_loaded('mbstring')) { |
|
| 908 | + return throw_error($txt['install_no_mbstring']); |
|
| 909 | + } |
|
| 855 | 910 | |
| 856 | 911 | // Check for https stream support. |
| 857 | 912 | $supported_streams = stream_get_wrappers(); |
| 858 | - if (!in_array('https', $supported_streams)) |
|
| 859 | - $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 913 | + if (!in_array('https', $supported_streams)) { |
|
| 914 | + $upcontext['custom_warning'] = $txt['install_no_https']; |
|
| 915 | + } |
|
| 860 | 916 | |
| 861 | 917 | // Either we're logged in or we're going to present the login. |
| 862 | - if (checkLogin()) |
|
| 863 | - return true; |
|
| 918 | + if (checkLogin()) { |
|
| 919 | + return true; |
|
| 920 | + } |
|
| 864 | 921 | |
| 865 | 922 | $upcontext += createToken('login'); |
| 866 | 923 | |
@@ -874,15 +931,17 @@ discard block |
||
| 874 | 931 | global $smcFunc, $db_type, $support_js; |
| 875 | 932 | |
| 876 | 933 | // Don't bother if the security is disabled. |
| 877 | - if ($disable_security) |
|
| 878 | - return true; |
|
| 934 | + if ($disable_security) { |
|
| 935 | + return true; |
|
| 936 | + } |
|
| 879 | 937 | |
| 880 | 938 | // Are we trying to login? |
| 881 | 939 | if (isset($_POST['contbutt']) && (!empty($_POST['user']))) |
| 882 | 940 | { |
| 883 | 941 | // If we've disabled security pick a suitable name! |
| 884 | - if (empty($_POST['user'])) |
|
| 885 | - $_POST['user'] = 'Administrator'; |
|
| 942 | + if (empty($_POST['user'])) { |
|
| 943 | + $_POST['user'] = 'Administrator'; |
|
| 944 | + } |
|
| 886 | 945 | |
| 887 | 946 | // Before 2.0 these column names were different! |
| 888 | 947 | $oldDB = false; |
@@ -897,16 +956,17 @@ discard block |
||
| 897 | 956 | 'db_error_skip' => true, |
| 898 | 957 | ) |
| 899 | 958 | ); |
| 900 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 901 | - $oldDB = true; |
|
| 959 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 960 | + $oldDB = true; |
|
| 961 | + } |
|
| 902 | 962 | $smcFunc['db_free_result']($request); |
| 903 | 963 | } |
| 904 | 964 | |
| 905 | 965 | // Get what we believe to be their details. |
| 906 | 966 | if (!$disable_security) |
| 907 | 967 | { |
| 908 | - if ($oldDB) |
|
| 909 | - $request = $smcFunc['db_query']('', ' |
|
| 968 | + if ($oldDB) { |
|
| 969 | + $request = $smcFunc['db_query']('', ' |
|
| 910 | 970 | SELECT id_member, memberName AS member_name, passwd, id_group, |
| 911 | 971 | additionalGroups AS additional_groups, lngfile |
| 912 | 972 | FROM {db_prefix}members |
@@ -916,8 +976,8 @@ discard block |
||
| 916 | 976 | 'db_error_skip' => true, |
| 917 | 977 | ) |
| 918 | 978 | ); |
| 919 | - else |
|
| 920 | - $request = $smcFunc['db_query']('', ' |
|
| 979 | + } else { |
|
| 980 | + $request = $smcFunc['db_query']('', ' |
|
| 921 | 981 | SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile |
| 922 | 982 | FROM {db_prefix}members |
| 923 | 983 | WHERE member_name = {string:member_name}', |
@@ -926,6 +986,7 @@ discard block |
||
| 926 | 986 | 'db_error_skip' => true, |
| 927 | 987 | ) |
| 928 | 988 | ); |
| 989 | + } |
|
| 929 | 990 | if ($smcFunc['db_num_rows']($request) != 0) |
| 930 | 991 | { |
| 931 | 992 | list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request); |
@@ -933,16 +994,17 @@ discard block |
||
| 933 | 994 | $groups = explode(',', $addGroups); |
| 934 | 995 | $groups[] = $id_group; |
| 935 | 996 | |
| 936 | - foreach ($groups as $k => $v) |
|
| 937 | - $groups[$k] = (int) $v; |
|
| 997 | + foreach ($groups as $k => $v) { |
|
| 998 | + $groups[$k] = (int) $v; |
|
| 999 | + } |
|
| 938 | 1000 | |
| 939 | 1001 | $sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd'])); |
| 940 | 1002 | |
| 941 | 1003 | // We don't use "-utf8" anymore... |
| 942 | 1004 | $user_language = str_ireplace('-utf8', '', $user_language); |
| 1005 | + } else { |
|
| 1006 | + $upcontext['username_incorrect'] = true; |
|
| 943 | 1007 | } |
| 944 | - else |
|
| 945 | - $upcontext['username_incorrect'] = true; |
|
| 946 | 1008 | |
| 947 | 1009 | $smcFunc['db_free_result']($request); |
| 948 | 1010 | } |
@@ -953,13 +1015,14 @@ discard block |
||
| 953 | 1015 | { |
| 954 | 1016 | $upcontext['upgrade_status']['js'] = 1; |
| 955 | 1017 | $support_js = 1; |
| 1018 | + } else { |
|
| 1019 | + $support_js = 0; |
|
| 956 | 1020 | } |
| 957 | - else |
|
| 958 | - $support_js = 0; |
|
| 959 | 1021 | |
| 960 | 1022 | // Note down the version we are coming from. |
| 961 | - if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) |
|
| 962 | - $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 1023 | + if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) { |
|
| 1024 | + $upcontext['user']['version'] = $modSettings['smfVersion']; |
|
| 1025 | + } |
|
| 963 | 1026 | |
| 964 | 1027 | // Didn't get anywhere? |
| 965 | 1028 | 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'])) |
@@ -993,15 +1056,15 @@ discard block |
||
| 993 | 1056 | 'db_error_skip' => true, |
| 994 | 1057 | ) |
| 995 | 1058 | ); |
| 996 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 997 | - return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 1059 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1060 | + return throw_error('You need to be an admin to perform an upgrade!'); |
|
| 1061 | + } |
|
| 998 | 1062 | $smcFunc['db_free_result']($request); |
| 999 | 1063 | } |
| 1000 | 1064 | |
| 1001 | 1065 | $upcontext['user']['id'] = $id_member; |
| 1002 | 1066 | $upcontext['user']['name'] = $name; |
| 1003 | - } |
|
| 1004 | - else |
|
| 1067 | + } else |
|
| 1005 | 1068 | { |
| 1006 | 1069 | $upcontext['user']['id'] = 1; |
| 1007 | 1070 | $upcontext['user']['name'] = 'Administrator'; |
@@ -1017,11 +1080,11 @@ discard block |
||
| 1017 | 1080 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096); |
| 1018 | 1081 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 1019 | 1082 | |
| 1020 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 1021 | - $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'] . '.'; |
|
| 1022 | - elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) |
|
| 1023 | - $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'] . '.'; |
|
| 1024 | - else |
|
| 1083 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 1084 | + $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'] . '.'; |
|
| 1085 | + } elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) { |
|
| 1086 | + $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'] . '.'; |
|
| 1087 | + } else |
|
| 1025 | 1088 | { |
| 1026 | 1089 | // Set this as the new language. |
| 1027 | 1090 | $upcontext['language'] = $user_language; |
@@ -1065,8 +1128,9 @@ discard block |
||
| 1065 | 1128 | unset($member_columns); |
| 1066 | 1129 | |
| 1067 | 1130 | // If we've not submitted then we're done. |
| 1068 | - if (empty($_POST['upcont'])) |
|
| 1069 | - return false; |
|
| 1131 | + if (empty($_POST['upcont'])) { |
|
| 1132 | + return false; |
|
| 1133 | + } |
|
| 1070 | 1134 | |
| 1071 | 1135 | // Firstly, if they're enabling SM stat collection just do it. |
| 1072 | 1136 | if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) |
@@ -1086,16 +1150,17 @@ discard block |
||
| 1086 | 1150 | fwrite($fp, $out); |
| 1087 | 1151 | |
| 1088 | 1152 | $return_data = ''; |
| 1089 | - while (!feof($fp)) |
|
| 1090 | - $return_data .= fgets($fp, 128); |
|
| 1153 | + while (!feof($fp)) { |
|
| 1154 | + $return_data .= fgets($fp, 128); |
|
| 1155 | + } |
|
| 1091 | 1156 | |
| 1092 | 1157 | fclose($fp); |
| 1093 | 1158 | |
| 1094 | 1159 | // Get the unique site ID. |
| 1095 | 1160 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
| 1096 | 1161 | |
| 1097 | - if (!empty($ID[1])) |
|
| 1098 | - $smcFunc['db_insert']('replace', |
|
| 1162 | + if (!empty($ID[1])) { |
|
| 1163 | + $smcFunc['db_insert']('replace', |
|
| 1099 | 1164 | $db_prefix . 'settings', |
| 1100 | 1165 | array('variable' => 'string', 'value' => 'string'), |
| 1101 | 1166 | array( |
@@ -1104,9 +1169,9 @@ discard block |
||
| 1104 | 1169 | ), |
| 1105 | 1170 | array('variable') |
| 1106 | 1171 | ); |
| 1172 | + } |
|
| 1107 | 1173 | } |
| 1108 | - } |
|
| 1109 | - else |
|
| 1174 | + } else |
|
| 1110 | 1175 | { |
| 1111 | 1176 | $smcFunc['db_insert']('replace', |
| 1112 | 1177 | $db_prefix . 'settings', |
@@ -1117,8 +1182,8 @@ discard block |
||
| 1117 | 1182 | } |
| 1118 | 1183 | } |
| 1119 | 1184 | // Don't remove stat collection unless we unchecked the box for real, not from the loop. |
| 1120 | - elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) |
|
| 1121 | - $smcFunc['db_query']('', ' |
|
| 1185 | + elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) { |
|
| 1186 | + $smcFunc['db_query']('', ' |
|
| 1122 | 1187 | DELETE FROM {db_prefix}settings |
| 1123 | 1188 | WHERE variable = {string:enable_sm_stats}', |
| 1124 | 1189 | array( |
@@ -1126,6 +1191,7 @@ discard block |
||
| 1126 | 1191 | 'db_error_skip' => true, |
| 1127 | 1192 | ) |
| 1128 | 1193 | ); |
| 1194 | + } |
|
| 1129 | 1195 | |
| 1130 | 1196 | // Deleting old karma stuff? |
| 1131 | 1197 | if (!empty($_POST['delete_karma'])) |
@@ -1140,20 +1206,22 @@ discard block |
||
| 1140 | 1206 | ); |
| 1141 | 1207 | |
| 1142 | 1208 | // Cleaning up old karma member settings. |
| 1143 | - if ($upcontext['karma_installed']['good']) |
|
| 1144 | - $smcFunc['db_query']('', ' |
|
| 1209 | + if ($upcontext['karma_installed']['good']) { |
|
| 1210 | + $smcFunc['db_query']('', ' |
|
| 1145 | 1211 | ALTER TABLE {db_prefix}members |
| 1146 | 1212 | DROP karma_good', |
| 1147 | 1213 | array() |
| 1148 | 1214 | ); |
| 1215 | + } |
|
| 1149 | 1216 | |
| 1150 | 1217 | // Does karma bad was enable? |
| 1151 | - if ($upcontext['karma_installed']['bad']) |
|
| 1152 | - $smcFunc['db_query']('', ' |
|
| 1218 | + if ($upcontext['karma_installed']['bad']) { |
|
| 1219 | + $smcFunc['db_query']('', ' |
|
| 1153 | 1220 | ALTER TABLE {db_prefix}members |
| 1154 | 1221 | DROP karma_bad', |
| 1155 | 1222 | array() |
| 1156 | 1223 | ); |
| 1224 | + } |
|
| 1157 | 1225 | |
| 1158 | 1226 | // Cleaning up old karma permissions. |
| 1159 | 1227 | $smcFunc['db_query']('', ' |
@@ -1171,32 +1239,37 @@ discard block |
||
| 1171 | 1239 | } |
| 1172 | 1240 | |
| 1173 | 1241 | // Emptying the error log? |
| 1174 | - if (!empty($_POST['empty_error'])) |
|
| 1175 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1242 | + if (!empty($_POST['empty_error'])) { |
|
| 1243 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1176 | 1244 | TRUNCATE {db_prefix}log_errors', |
| 1177 | 1245 | array( |
| 1178 | 1246 | ) |
| 1179 | 1247 | ); |
| 1248 | + } |
|
| 1180 | 1249 | |
| 1181 | 1250 | $changes = array(); |
| 1182 | 1251 | |
| 1183 | 1252 | // Add proxy settings. |
| 1184 | - if (!isset($GLOBALS['image_proxy_maxsize'])) |
|
| 1185 | - $changes += array( |
|
| 1253 | + if (!isset($GLOBALS['image_proxy_maxsize'])) { |
|
| 1254 | + $changes += array( |
|
| 1186 | 1255 | 'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'', |
| 1187 | 1256 | 'image_proxy_maxsize' => 5190, |
| 1188 | 1257 | 'image_proxy_enabled' => 0, |
| 1189 | 1258 | ); |
| 1259 | + } |
|
| 1190 | 1260 | |
| 1191 | 1261 | // If $boardurl reflects https, set force_ssl |
| 1192 | - if (!function_exists('cache_put_data')) |
|
| 1193 | - require_once($sourcedir . '/Load.php'); |
|
| 1194 | - if (stripos($boardurl, 'https://') !== false) |
|
| 1195 | - updateSettings(array('force_ssl' => '1')); |
|
| 1262 | + if (!function_exists('cache_put_data')) { |
|
| 1263 | + require_once($sourcedir . '/Load.php'); |
|
| 1264 | + } |
|
| 1265 | + if (stripos($boardurl, 'https://') !== false) { |
|
| 1266 | + updateSettings(array('force_ssl' => '1')); |
|
| 1267 | + } |
|
| 1196 | 1268 | |
| 1197 | 1269 | // If we're overriding the language follow it through. |
| 1198 | - if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) |
|
| 1199 | - $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1270 | + if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) { |
|
| 1271 | + $changes['language'] = '\'' . $_GET['lang'] . '\''; |
|
| 1272 | + } |
|
| 1200 | 1273 | |
| 1201 | 1274 | if (!empty($_POST['maint'])) |
| 1202 | 1275 | { |
@@ -1208,26 +1281,29 @@ discard block |
||
| 1208 | 1281 | { |
| 1209 | 1282 | $changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\''; |
| 1210 | 1283 | $changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\''; |
| 1211 | - } |
|
| 1212 | - else |
|
| 1284 | + } else |
|
| 1213 | 1285 | { |
| 1214 | 1286 | $changes['mtitle'] = '\'Upgrading the forum...\''; |
| 1215 | 1287 | $changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum. It will only be a minute ;).\''; |
| 1216 | 1288 | } |
| 1217 | 1289 | } |
| 1218 | 1290 | |
| 1219 | - if ($command_line) |
|
| 1220 | - echo ' * Updating Settings.php...'; |
|
| 1291 | + if ($command_line) { |
|
| 1292 | + echo ' * Updating Settings.php...'; |
|
| 1293 | + } |
|
| 1221 | 1294 | |
| 1222 | 1295 | // Fix some old paths. |
| 1223 | - if (substr($boarddir, 0, 1) == '.') |
|
| 1224 | - $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1296 | + if (substr($boarddir, 0, 1) == '.') { |
|
| 1297 | + $changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\''; |
|
| 1298 | + } |
|
| 1225 | 1299 | |
| 1226 | - if (substr($sourcedir, 0, 1) == '.') |
|
| 1227 | - $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1300 | + if (substr($sourcedir, 0, 1) == '.') { |
|
| 1301 | + $changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\''; |
|
| 1302 | + } |
|
| 1228 | 1303 | |
| 1229 | - if (empty($cachedir) || substr($cachedir, 0, 1) == '.') |
|
| 1230 | - $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1304 | + if (empty($cachedir) || substr($cachedir, 0, 1) == '.') { |
|
| 1305 | + $changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\''; |
|
| 1306 | + } |
|
| 1231 | 1307 | |
| 1232 | 1308 | // If they have a "host:port" setup for the host, split that into separate values |
| 1233 | 1309 | // You should never have a : in the hostname if you're not on MySQL, but better safe than sorry |
@@ -1238,32 +1314,36 @@ discard block |
||
| 1238 | 1314 | $changes['db_server'] = '\'' . $db_server . '\''; |
| 1239 | 1315 | |
| 1240 | 1316 | // Only set this if we're not using the default port |
| 1241 | - if ($db_port != ini_get('mysqli.default_port')) |
|
| 1242 | - $changes['db_port'] = (int) $db_port; |
|
| 1243 | - } |
|
| 1244 | - elseif (!empty($db_port)) |
|
| 1317 | + if ($db_port != ini_get('mysqli.default_port')) { |
|
| 1318 | + $changes['db_port'] = (int) $db_port; |
|
| 1319 | + } |
|
| 1320 | + } elseif (!empty($db_port)) |
|
| 1245 | 1321 | { |
| 1246 | 1322 | // If db_port is set and is the same as the default, set it to '' |
| 1247 | 1323 | if ($db_type == 'mysql') |
| 1248 | 1324 | { |
| 1249 | - if ($db_port == ini_get('mysqli.default_port')) |
|
| 1250 | - $changes['db_port'] = '\'\''; |
|
| 1251 | - elseif ($db_type == 'postgresql' && $db_port == 5432) |
|
| 1252 | - $changes['db_port'] = '\'\''; |
|
| 1325 | + if ($db_port == ini_get('mysqli.default_port')) { |
|
| 1326 | + $changes['db_port'] = '\'\''; |
|
| 1327 | + } elseif ($db_type == 'postgresql' && $db_port == 5432) { |
|
| 1328 | + $changes['db_port'] = '\'\''; |
|
| 1329 | + } |
|
| 1253 | 1330 | } |
| 1254 | 1331 | } |
| 1255 | 1332 | |
| 1256 | 1333 | // Maybe we haven't had this option yet? |
| 1257 | - if (empty($packagesdir)) |
|
| 1258 | - $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1334 | + if (empty($packagesdir)) { |
|
| 1335 | + $changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\''; |
|
| 1336 | + } |
|
| 1259 | 1337 | |
| 1260 | 1338 | // Add support for $tasksdir var. |
| 1261 | - if (empty($tasksdir)) |
|
| 1262 | - $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1339 | + if (empty($tasksdir)) { |
|
| 1340 | + $changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\''; |
|
| 1341 | + } |
|
| 1263 | 1342 | |
| 1264 | 1343 | // Make sure we fix the language as well. |
| 1265 | - if (stristr($language, '-utf8')) |
|
| 1266 | - $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1344 | + if (stristr($language, '-utf8')) { |
|
| 1345 | + $changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\''; |
|
| 1346 | + } |
|
| 1267 | 1347 | |
| 1268 | 1348 | // @todo Maybe change the cookie name if going to 1.1, too? |
| 1269 | 1349 | |
@@ -1274,8 +1354,9 @@ discard block |
||
| 1274 | 1354 | // Tell Settings.php to store db_last_error.php in the cache |
| 1275 | 1355 | move_db_last_error_to_cachedir(); |
| 1276 | 1356 | |
| 1277 | - if ($command_line) |
|
| 1278 | - echo ' Successful.' . "\n"; |
|
| 1357 | + if ($command_line) { |
|
| 1358 | + echo ' Successful.' . "\n"; |
|
| 1359 | + } |
|
| 1279 | 1360 | |
| 1280 | 1361 | // Are we doing debug? |
| 1281 | 1362 | if (isset($_POST['debug'])) |
@@ -1285,8 +1366,9 @@ discard block |
||
| 1285 | 1366 | } |
| 1286 | 1367 | |
| 1287 | 1368 | // If we're not backing up then jump one. |
| 1288 | - if (empty($_POST['backup'])) |
|
| 1289 | - $upcontext['current_step']++; |
|
| 1369 | + if (empty($_POST['backup'])) { |
|
| 1370 | + $upcontext['current_step']++; |
|
| 1371 | + } |
|
| 1290 | 1372 | |
| 1291 | 1373 | // If we've got here then let's proceed to the next step! |
| 1292 | 1374 | return true; |
@@ -1301,8 +1383,9 @@ discard block |
||
| 1301 | 1383 | $upcontext['page_title'] = $txt['backup_database']; |
| 1302 | 1384 | |
| 1303 | 1385 | // Done it already - js wise? |
| 1304 | - if (!empty($_POST['backup_done'])) |
|
| 1305 | - return true; |
|
| 1386 | + if (!empty($_POST['backup_done'])) { |
|
| 1387 | + return true; |
|
| 1388 | + } |
|
| 1306 | 1389 | |
| 1307 | 1390 | // Some useful stuff here. |
| 1308 | 1391 | db_extend(); |
@@ -1316,9 +1399,10 @@ discard block |
||
| 1316 | 1399 | $tables = $smcFunc['db_list_tables']($db, $filter); |
| 1317 | 1400 | |
| 1318 | 1401 | $table_names = array(); |
| 1319 | - foreach ($tables as $table) |
|
| 1320 | - if (substr($table, 0, 7) !== 'backup_') |
|
| 1402 | + foreach ($tables as $table) { |
|
| 1403 | + if (substr($table, 0, 7) !== 'backup_') |
|
| 1321 | 1404 | $table_names[] = $table; |
| 1405 | + } |
|
| 1322 | 1406 | |
| 1323 | 1407 | $upcontext['table_count'] = count($table_names); |
| 1324 | 1408 | $upcontext['cur_table_num'] = $_GET['substep']; |
@@ -1328,12 +1412,14 @@ discard block |
||
| 1328 | 1412 | $file_steps = $upcontext['table_count']; |
| 1329 | 1413 | |
| 1330 | 1414 | // What ones have we already done? |
| 1331 | - foreach ($table_names as $id => $table) |
|
| 1332 | - if ($id < $_GET['substep']) |
|
| 1415 | + foreach ($table_names as $id => $table) { |
|
| 1416 | + if ($id < $_GET['substep']) |
|
| 1333 | 1417 | $upcontext['previous_tables'][] = $table; |
| 1418 | + } |
|
| 1334 | 1419 | |
| 1335 | - if ($command_line) |
|
| 1336 | - echo 'Backing Up Tables.'; |
|
| 1420 | + if ($command_line) { |
|
| 1421 | + echo 'Backing Up Tables.'; |
|
| 1422 | + } |
|
| 1337 | 1423 | |
| 1338 | 1424 | // If we don't support javascript we backup here. |
| 1339 | 1425 | if (!$support_js || isset($_GET['xml'])) |
@@ -1352,8 +1438,9 @@ discard block |
||
| 1352 | 1438 | backupTable($table_names[$substep]); |
| 1353 | 1439 | |
| 1354 | 1440 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 1355 | - if (isset($_GET['xml'])) |
|
| 1356 | - return upgradeExit(); |
|
| 1441 | + if (isset($_GET['xml'])) { |
|
| 1442 | + return upgradeExit(); |
|
| 1443 | + } |
|
| 1357 | 1444 | } |
| 1358 | 1445 | |
| 1359 | 1446 | if ($command_line) |
@@ -1386,9 +1473,10 @@ discard block |
||
| 1386 | 1473 | |
| 1387 | 1474 | $smcFunc['db_backup_table']($table, 'backup_' . $table); |
| 1388 | 1475 | |
| 1389 | - if ($command_line) |
|
| 1390 | - echo ' done.'; |
|
| 1391 | -} |
|
| 1476 | + if ($command_line) { |
|
| 1477 | + echo ' done.'; |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1392 | 1480 | |
| 1393 | 1481 | // Step 2: Everything. |
| 1394 | 1482 | function DatabaseChanges() |
@@ -1397,8 +1485,9 @@ discard block |
||
| 1397 | 1485 | global $upcontext, $support_js, $db_type; |
| 1398 | 1486 | |
| 1399 | 1487 | // Have we just completed this? |
| 1400 | - if (!empty($_POST['database_done'])) |
|
| 1401 | - return true; |
|
| 1488 | + if (!empty($_POST['database_done'])) { |
|
| 1489 | + return true; |
|
| 1490 | + } |
|
| 1402 | 1491 | |
| 1403 | 1492 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes'; |
| 1404 | 1493 | $upcontext['page_title'] = $txt['database_changes']; |
@@ -1413,15 +1502,16 @@ discard block |
||
| 1413 | 1502 | ); |
| 1414 | 1503 | |
| 1415 | 1504 | // How many files are there in total? |
| 1416 | - if (isset($_GET['filecount'])) |
|
| 1417 | - $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1418 | - else |
|
| 1505 | + if (isset($_GET['filecount'])) { |
|
| 1506 | + $upcontext['file_count'] = (int) $_GET['filecount']; |
|
| 1507 | + } else |
|
| 1419 | 1508 | { |
| 1420 | 1509 | $upcontext['file_count'] = 0; |
| 1421 | 1510 | foreach ($files as $file) |
| 1422 | 1511 | { |
| 1423 | - if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) |
|
| 1424 | - $upcontext['file_count']++; |
|
| 1512 | + if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) { |
|
| 1513 | + $upcontext['file_count']++; |
|
| 1514 | + } |
|
| 1425 | 1515 | } |
| 1426 | 1516 | } |
| 1427 | 1517 | |
@@ -1431,9 +1521,9 @@ discard block |
||
| 1431 | 1521 | $upcontext['cur_file_num'] = 0; |
| 1432 | 1522 | foreach ($files as $file) |
| 1433 | 1523 | { |
| 1434 | - if ($did_not_do) |
|
| 1435 | - $did_not_do--; |
|
| 1436 | - else |
|
| 1524 | + if ($did_not_do) { |
|
| 1525 | + $did_not_do--; |
|
| 1526 | + } else |
|
| 1437 | 1527 | { |
| 1438 | 1528 | $upcontext['cur_file_num']++; |
| 1439 | 1529 | $upcontext['cur_file_name'] = $file[0]; |
@@ -1460,12 +1550,13 @@ discard block |
||
| 1460 | 1550 | // Flag to move on to the next. |
| 1461 | 1551 | $upcontext['completed_step'] = true; |
| 1462 | 1552 | // Did we complete the whole file? |
| 1463 | - if ($nextFile) |
|
| 1464 | - $upcontext['current_debug_item_num'] = -1; |
|
| 1553 | + if ($nextFile) { |
|
| 1554 | + $upcontext['current_debug_item_num'] = -1; |
|
| 1555 | + } |
|
| 1465 | 1556 | return upgradeExit(); |
| 1557 | + } elseif ($support_js) { |
|
| 1558 | + break; |
|
| 1466 | 1559 | } |
| 1467 | - elseif ($support_js) |
|
| 1468 | - break; |
|
| 1469 | 1560 | } |
| 1470 | 1561 | // Set the progress bar to be right as if we had - even if we hadn't... |
| 1471 | 1562 | $upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100; |
@@ -1491,8 +1582,9 @@ discard block |
||
| 1491 | 1582 | global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings; |
| 1492 | 1583 | |
| 1493 | 1584 | // Now it's nice to have some of the basic SMF source files. |
| 1494 | - if (!isset($_GET['ssi']) && !$command_line) |
|
| 1495 | - redirectLocation('&ssi=1'); |
|
| 1585 | + if (!isset($_GET['ssi']) && !$command_line) { |
|
| 1586 | + redirectLocation('&ssi=1'); |
|
| 1587 | + } |
|
| 1496 | 1588 | |
| 1497 | 1589 | $upcontext['sub_template'] = 'upgrade_complete'; |
| 1498 | 1590 | $upcontext['page_title'] = $txt['upgrade_complete']; |
@@ -1508,14 +1600,16 @@ discard block |
||
| 1508 | 1600 | // Are we in maintenance mode? |
| 1509 | 1601 | if (isset($upcontext['user']['main'])) |
| 1510 | 1602 | { |
| 1511 | - if ($command_line) |
|
| 1512 | - echo ' * '; |
|
| 1603 | + if ($command_line) { |
|
| 1604 | + echo ' * '; |
|
| 1605 | + } |
|
| 1513 | 1606 | $upcontext['removed_maintenance'] = true; |
| 1514 | 1607 | $changes['maintenance'] = $upcontext['user']['main']; |
| 1515 | 1608 | } |
| 1516 | 1609 | // Otherwise if somehow we are in 2 let's go to 1. |
| 1517 | - elseif (!empty($maintenance) && $maintenance == 2) |
|
| 1518 | - $changes['maintenance'] = 1; |
|
| 1610 | + elseif (!empty($maintenance) && $maintenance == 2) { |
|
| 1611 | + $changes['maintenance'] = 1; |
|
| 1612 | + } |
|
| 1519 | 1613 | |
| 1520 | 1614 | // Wipe this out... |
| 1521 | 1615 | $upcontext['user'] = array(); |
@@ -1530,21 +1624,23 @@ discard block |
||
| 1530 | 1624 | $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__); |
| 1531 | 1625 | |
| 1532 | 1626 | // Now is the perfect time to fetch the SM files. |
| 1533 | - if ($command_line) |
|
| 1534 | - cli_scheduled_fetchSMfiles(); |
|
| 1535 | - else |
|
| 1627 | + if ($command_line) { |
|
| 1628 | + cli_scheduled_fetchSMfiles(); |
|
| 1629 | + } else |
|
| 1536 | 1630 | { |
| 1537 | 1631 | require_once($sourcedir . '/ScheduledTasks.php'); |
| 1538 | 1632 | $forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us. |
| 1539 | 1633 | scheduled_fetchSMfiles(); // Now go get those files! |
| 1540 | 1634 | // This is needed in case someone invokes the upgrader using https when upgrading an http forum |
| 1541 | - if (httpsOn()) |
|
| 1542 | - $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
| 1635 | + if (httpsOn()) { |
|
| 1636 | + $settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://')); |
|
| 1637 | + } |
|
| 1543 | 1638 | } |
| 1544 | 1639 | |
| 1545 | 1640 | // Log what we've done. |
| 1546 | - if (empty($user_info['id'])) |
|
| 1547 | - $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1641 | + if (empty($user_info['id'])) { |
|
| 1642 | + $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0; |
|
| 1643 | + } |
|
| 1548 | 1644 | |
| 1549 | 1645 | // Log the action manually, so CLI still works. |
| 1550 | 1646 | $smcFunc['db_insert']('', |
@@ -1563,8 +1659,9 @@ discard block |
||
| 1563 | 1659 | |
| 1564 | 1660 | // Save the current database version. |
| 1565 | 1661 | $server_version = $smcFunc['db_server_info'](); |
| 1566 | - if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
| 1567 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1662 | + if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
| 1663 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
| 1664 | + } |
|
| 1568 | 1665 | |
| 1569 | 1666 | if ($command_line) |
| 1570 | 1667 | { |
@@ -1576,8 +1673,9 @@ discard block |
||
| 1576 | 1673 | |
| 1577 | 1674 | // Make sure it says we're done. |
| 1578 | 1675 | $upcontext['overall_percent'] = 100; |
| 1579 | - if (isset($upcontext['step_progress'])) |
|
| 1580 | - unset($upcontext['step_progress']); |
|
| 1676 | + if (isset($upcontext['step_progress'])) { |
|
| 1677 | + unset($upcontext['step_progress']); |
|
| 1678 | + } |
|
| 1581 | 1679 | |
| 1582 | 1680 | $_GET['substep'] = 0; |
| 1583 | 1681 | return false; |
@@ -1588,8 +1686,9 @@ discard block |
||
| 1588 | 1686 | { |
| 1589 | 1687 | global $sourcedir, $language, $forum_version, $modSettings, $smcFunc; |
| 1590 | 1688 | |
| 1591 | - if (empty($modSettings['time_format'])) |
|
| 1592 | - $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1689 | + if (empty($modSettings['time_format'])) { |
|
| 1690 | + $modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p'; |
|
| 1691 | + } |
|
| 1593 | 1692 | |
| 1594 | 1693 | // What files do we want to get |
| 1595 | 1694 | $request = $smcFunc['db_query']('', ' |
@@ -1623,8 +1722,9 @@ discard block |
||
| 1623 | 1722 | $file_data = fetch_web_data($url); |
| 1624 | 1723 | |
| 1625 | 1724 | // If we got an error - give up - the site might be down. |
| 1626 | - if ($file_data === false) |
|
| 1627 | - return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1725 | + if ($file_data === false) { |
|
| 1726 | + return throw_error(sprintf('Could not retrieve the file %1$s.', $url)); |
|
| 1727 | + } |
|
| 1628 | 1728 | |
| 1629 | 1729 | // Save the file to the database. |
| 1630 | 1730 | $smcFunc['db_query']('substring', ' |
@@ -1666,8 +1766,9 @@ discard block |
||
| 1666 | 1766 | $themeData = array(); |
| 1667 | 1767 | foreach ($values as $variable => $value) |
| 1668 | 1768 | { |
| 1669 | - if (!isset($value) || $value === null) |
|
| 1670 | - $value = 0; |
|
| 1769 | + if (!isset($value) || $value === null) { |
|
| 1770 | + $value = 0; |
|
| 1771 | + } |
|
| 1671 | 1772 | |
| 1672 | 1773 | $themeData[] = array(0, 1, $variable, $value); |
| 1673 | 1774 | } |
@@ -1696,8 +1797,9 @@ discard block |
||
| 1696 | 1797 | |
| 1697 | 1798 | foreach ($values as $variable => $value) |
| 1698 | 1799 | { |
| 1699 | - if (empty($modSettings[$value[0]])) |
|
| 1700 | - continue; |
|
| 1800 | + if (empty($modSettings[$value[0]])) { |
|
| 1801 | + continue; |
|
| 1802 | + } |
|
| 1701 | 1803 | |
| 1702 | 1804 | $smcFunc['db_query']('', ' |
| 1703 | 1805 | INSERT IGNORE INTO {db_prefix}themes |
@@ -1783,19 +1885,21 @@ discard block |
||
| 1783 | 1885 | set_error_handler( |
| 1784 | 1886 | function ($errno, $errstr, $errfile, $errline) use ($support_js) |
| 1785 | 1887 | { |
| 1786 | - if ($support_js) |
|
| 1787 | - return true; |
|
| 1788 | - else |
|
| 1789 | - echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1888 | + if ($support_js) { |
|
| 1889 | + return true; |
|
| 1890 | + } else { |
|
| 1891 | + echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline; |
|
| 1892 | + } |
|
| 1790 | 1893 | } |
| 1791 | 1894 | ); |
| 1792 | 1895 | |
| 1793 | 1896 | // If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8 |
| 1794 | 1897 | // Note it is expected to be in the format: ENGINE=MyISAM{$db_collation}; |
| 1795 | - if ($db_type == 'mysql') |
|
| 1796 | - $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1797 | - else |
|
| 1798 | - $db_collation = ''; |
|
| 1898 | + if ($db_type == 'mysql') { |
|
| 1899 | + $db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; |
|
| 1900 | + } else { |
|
| 1901 | + $db_collation = ''; |
|
| 1902 | + } |
|
| 1799 | 1903 | |
| 1800 | 1904 | $endl = $command_line ? "\n" : '<br>' . "\n"; |
| 1801 | 1905 | |
@@ -1807,8 +1911,9 @@ discard block |
||
| 1807 | 1911 | $last_step = ''; |
| 1808 | 1912 | |
| 1809 | 1913 | // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php |
| 1810 | - if (isset($db_character_set) && $db_character_set === 'utf8') |
|
| 1811 | - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1914 | + if (isset($db_character_set) && $db_character_set === 'utf8') { |
|
| 1915 | + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); |
|
| 1916 | + } |
|
| 1812 | 1917 | |
| 1813 | 1918 | // Count the total number of steps within this file - for progress. |
| 1814 | 1919 | $file_steps = substr_count(implode('', $lines), '---#'); |
@@ -1828,15 +1933,18 @@ discard block |
||
| 1828 | 1933 | $do_current = $substep >= $_GET['substep']; |
| 1829 | 1934 | |
| 1830 | 1935 | // Get rid of any comments in the beginning of the line... |
| 1831 | - if (substr(trim($line), 0, 2) === '/*') |
|
| 1832 | - $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1936 | + if (substr(trim($line), 0, 2) === '/*') { |
|
| 1937 | + $line = preg_replace('~/\*.+?\*/~', '', $line); |
|
| 1938 | + } |
|
| 1833 | 1939 | |
| 1834 | 1940 | // Always flush. Flush, flush, flush. Flush, flush, flush, flush! FLUSH! |
| 1835 | - if ($is_debug && !$support_js && $command_line) |
|
| 1836 | - flush(); |
|
| 1941 | + if ($is_debug && !$support_js && $command_line) { |
|
| 1942 | + flush(); |
|
| 1943 | + } |
|
| 1837 | 1944 | |
| 1838 | - if (trim($line) === '') |
|
| 1839 | - continue; |
|
| 1945 | + if (trim($line) === '') { |
|
| 1946 | + continue; |
|
| 1947 | + } |
|
| 1840 | 1948 | |
| 1841 | 1949 | if (trim(substr($line, 0, 3)) === '---') |
| 1842 | 1950 | { |
@@ -1846,8 +1954,9 @@ discard block |
||
| 1846 | 1954 | if (trim($current_data) != '' && $type !== '}') |
| 1847 | 1955 | { |
| 1848 | 1956 | $upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl; |
| 1849 | - if ($command_line) |
|
| 1850 | - echo $upcontext['error_message']; |
|
| 1957 | + if ($command_line) { |
|
| 1958 | + echo $upcontext['error_message']; |
|
| 1959 | + } |
|
| 1851 | 1960 | } |
| 1852 | 1961 | |
| 1853 | 1962 | if ($type == ' ') |
@@ -1865,17 +1974,18 @@ discard block |
||
| 1865 | 1974 | if ($do_current) |
| 1866 | 1975 | { |
| 1867 | 1976 | $upcontext['actioned_items'][] = $last_step; |
| 1868 | - if ($command_line) |
|
| 1869 | - echo ' * '; |
|
| 1977 | + if ($command_line) { |
|
| 1978 | + echo ' * '; |
|
| 1979 | + } |
|
| 1870 | 1980 | } |
| 1871 | - } |
|
| 1872 | - elseif ($type == '#') |
|
| 1981 | + } elseif ($type == '#') |
|
| 1873 | 1982 | { |
| 1874 | 1983 | $upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps; |
| 1875 | 1984 | |
| 1876 | 1985 | $upcontext['current_debug_item_num']++; |
| 1877 | - if (trim($line) != '---#') |
|
| 1878 | - $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1986 | + if (trim($line) != '---#') { |
|
| 1987 | + $upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 1988 | + } |
|
| 1879 | 1989 | |
| 1880 | 1990 | // Have we already done something? |
| 1881 | 1991 | if (isset($_GET['xml']) && $done_something) |
@@ -1886,34 +1996,36 @@ discard block |
||
| 1886 | 1996 | |
| 1887 | 1997 | if ($do_current) |
| 1888 | 1998 | { |
| 1889 | - if (trim($line) == '---#' && $command_line) |
|
| 1890 | - echo ' done.', $endl; |
|
| 1891 | - elseif ($command_line) |
|
| 1892 | - echo ' +++ ', rtrim(substr($line, 4)); |
|
| 1893 | - elseif (trim($line) != '---#') |
|
| 1999 | + if (trim($line) == '---#' && $command_line) { |
|
| 2000 | + echo ' done.', $endl; |
|
| 2001 | + } elseif ($command_line) { |
|
| 2002 | + echo ' +++ ', rtrim(substr($line, 4)); |
|
| 2003 | + } elseif (trim($line) != '---#') |
|
| 1894 | 2004 | { |
| 1895 | - if ($is_debug) |
|
| 1896 | - $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2005 | + if ($is_debug) { |
|
| 2006 | + $upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4))); |
|
| 2007 | + } |
|
| 1897 | 2008 | } |
| 1898 | 2009 | } |
| 1899 | 2010 | |
| 1900 | 2011 | if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep']) |
| 1901 | 2012 | { |
| 1902 | - if ($command_line) |
|
| 1903 | - echo ' * '; |
|
| 1904 | - else |
|
| 1905 | - $upcontext['actioned_items'][] = $last_step; |
|
| 2013 | + if ($command_line) { |
|
| 2014 | + echo ' * '; |
|
| 2015 | + } else { |
|
| 2016 | + $upcontext['actioned_items'][] = $last_step; |
|
| 2017 | + } |
|
| 1906 | 2018 | } |
| 1907 | 2019 | |
| 1908 | 2020 | // Small step - only if we're actually doing stuff. |
| 1909 | - if ($do_current) |
|
| 1910 | - nextSubstep(++$substep); |
|
| 1911 | - else |
|
| 1912 | - $substep++; |
|
| 1913 | - } |
|
| 1914 | - elseif ($type == '{') |
|
| 1915 | - $current_type = 'code'; |
|
| 1916 | - elseif ($type == '}') |
|
| 2021 | + if ($do_current) { |
|
| 2022 | + nextSubstep(++$substep); |
|
| 2023 | + } else { |
|
| 2024 | + $substep++; |
|
| 2025 | + } |
|
| 2026 | + } elseif ($type == '{') { |
|
| 2027 | + $current_type = 'code'; |
|
| 2028 | + } elseif ($type == '}') |
|
| 1917 | 2029 | { |
| 1918 | 2030 | $current_type = 'sql'; |
| 1919 | 2031 | |
@@ -1926,8 +2038,9 @@ discard block |
||
| 1926 | 2038 | if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false) |
| 1927 | 2039 | { |
| 1928 | 2040 | $upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl; |
| 1929 | - if ($command_line) |
|
| 1930 | - echo $upcontext['error_message']; |
|
| 2041 | + if ($command_line) { |
|
| 2042 | + echo $upcontext['error_message']; |
|
| 2043 | + } |
|
| 1931 | 2044 | } |
| 1932 | 2045 | |
| 1933 | 2046 | // Done with code! |
@@ -2015,8 +2128,9 @@ discard block |
||
| 2015 | 2128 | $db_unbuffered = false; |
| 2016 | 2129 | |
| 2017 | 2130 | // Failure?! |
| 2018 | - if ($result !== false) |
|
| 2019 | - return $result; |
|
| 2131 | + if ($result !== false) { |
|
| 2132 | + return $result; |
|
| 2133 | + } |
|
| 2020 | 2134 | |
| 2021 | 2135 | $db_error_message = $smcFunc['db_error']($db_connection); |
| 2022 | 2136 | // If MySQL we do something more clever. |
@@ -2044,54 +2158,61 @@ discard block |
||
| 2044 | 2158 | { |
| 2045 | 2159 | mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`'); |
| 2046 | 2160 | $result = mysqli_query($db_connection, $string); |
| 2047 | - if ($result !== false) |
|
| 2048 | - return $result; |
|
| 2161 | + if ($result !== false) { |
|
| 2162 | + return $result; |
|
| 2163 | + } |
|
| 2049 | 2164 | } |
| 2050 | - } |
|
| 2051 | - elseif ($mysqli_errno == 2013) |
|
| 2165 | + } elseif ($mysqli_errno == 2013) |
|
| 2052 | 2166 | { |
| 2053 | 2167 | $db_connection = mysqli_connect($db_server, $db_user, $db_passwd); |
| 2054 | 2168 | mysqli_select_db($db_connection, $db_name); |
| 2055 | 2169 | if ($db_connection) |
| 2056 | 2170 | { |
| 2057 | 2171 | $result = mysqli_query($db_connection, $string); |
| 2058 | - if ($result !== false) |
|
| 2059 | - return $result; |
|
| 2172 | + if ($result !== false) { |
|
| 2173 | + return $result; |
|
| 2174 | + } |
|
| 2060 | 2175 | } |
| 2061 | 2176 | } |
| 2062 | 2177 | // Duplicate column name... should be okay ;). |
| 2063 | - elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) |
|
| 2064 | - return false; |
|
| 2178 | + elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) { |
|
| 2179 | + return false; |
|
| 2180 | + } |
|
| 2065 | 2181 | // Duplicate insert... make sure it's the proper type of query ;). |
| 2066 | - elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) |
|
| 2067 | - return false; |
|
| 2182 | + elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) { |
|
| 2183 | + return false; |
|
| 2184 | + } |
|
| 2068 | 2185 | // Creating an index on a non-existent column. |
| 2069 | - elseif ($mysqli_errno == 1072) |
|
| 2070 | - return false; |
|
| 2071 | - elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') |
|
| 2072 | - return false; |
|
| 2186 | + elseif ($mysqli_errno == 1072) { |
|
| 2187 | + return false; |
|
| 2188 | + } elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') { |
|
| 2189 | + return false; |
|
| 2190 | + } |
|
| 2073 | 2191 | } |
| 2074 | 2192 | // If a table already exists don't go potty. |
| 2075 | 2193 | else |
| 2076 | 2194 | { |
| 2077 | 2195 | if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U'))) |
| 2078 | 2196 | { |
| 2079 | - if (strpos($db_error_message, 'exist') !== false) |
|
| 2080 | - return true; |
|
| 2081 | - } |
|
| 2082 | - elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2197 | + if (strpos($db_error_message, 'exist') !== false) { |
|
| 2198 | + return true; |
|
| 2199 | + } |
|
| 2200 | + } elseif (strpos(trim($string), 'INSERT ') !== false) |
|
| 2083 | 2201 | { |
| 2084 | - if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) |
|
| 2085 | - return true; |
|
| 2202 | + if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) { |
|
| 2203 | + return true; |
|
| 2204 | + } |
|
| 2086 | 2205 | } |
| 2087 | 2206 | } |
| 2088 | 2207 | |
| 2089 | 2208 | // Get the query string so we pass everything. |
| 2090 | 2209 | $query_string = ''; |
| 2091 | - foreach ($_GET as $k => $v) |
|
| 2092 | - $query_string .= ';' . $k . '=' . $v; |
|
| 2093 | - if (strlen($query_string) != 0) |
|
| 2094 | - $query_string = '?' . substr($query_string, 1); |
|
| 2210 | + foreach ($_GET as $k => $v) { |
|
| 2211 | + $query_string .= ';' . $k . '=' . $v; |
|
| 2212 | + } |
|
| 2213 | + if (strlen($query_string) != 0) { |
|
| 2214 | + $query_string = '?' . substr($query_string, 1); |
|
| 2215 | + } |
|
| 2095 | 2216 | |
| 2096 | 2217 | if ($command_line) |
| 2097 | 2218 | { |
@@ -2146,16 +2267,18 @@ discard block |
||
| 2146 | 2267 | { |
| 2147 | 2268 | $found |= 1; |
| 2148 | 2269 | // Do some checks on the data if we have it set. |
| 2149 | - if (isset($change['col_type'])) |
|
| 2150 | - $found &= $change['col_type'] === $column['type']; |
|
| 2151 | - if (isset($change['null_allowed'])) |
|
| 2152 | - $found &= $column['null'] == $change['null_allowed']; |
|
| 2153 | - if (isset($change['default'])) |
|
| 2154 | - $found &= $change['default'] === $column['default']; |
|
| 2270 | + if (isset($change['col_type'])) { |
|
| 2271 | + $found &= $change['col_type'] === $column['type']; |
|
| 2272 | + } |
|
| 2273 | + if (isset($change['null_allowed'])) { |
|
| 2274 | + $found &= $column['null'] == $change['null_allowed']; |
|
| 2275 | + } |
|
| 2276 | + if (isset($change['default'])) { |
|
| 2277 | + $found &= $change['default'] === $column['default']; |
|
| 2278 | + } |
|
| 2155 | 2279 | } |
| 2156 | 2280 | } |
| 2157 | - } |
|
| 2158 | - elseif ($change['type'] === 'index') |
|
| 2281 | + } elseif ($change['type'] === 'index') |
|
| 2159 | 2282 | { |
| 2160 | 2283 | $request = upgrade_query(' |
| 2161 | 2284 | SHOW INDEX |
@@ -2164,9 +2287,10 @@ discard block |
||
| 2164 | 2287 | { |
| 2165 | 2288 | $cur_index = array(); |
| 2166 | 2289 | |
| 2167 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2168 | - if ($row['Key_name'] === $change['name']) |
|
| 2290 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2291 | + if ($row['Key_name'] === $change['name']) |
|
| 2169 | 2292 | $cur_index[(int) $row['Seq_in_index']] = $row['Column_name']; |
| 2293 | + } |
|
| 2170 | 2294 | |
| 2171 | 2295 | ksort($cur_index, SORT_NUMERIC); |
| 2172 | 2296 | $found = array_values($cur_index) === $change['target_columns']; |
@@ -2176,14 +2300,17 @@ discard block |
||
| 2176 | 2300 | } |
| 2177 | 2301 | |
| 2178 | 2302 | // If we're trying to add and it's added, we're done. |
| 2179 | - if ($found && in_array($change['method'], array('add', 'change'))) |
|
| 2180 | - return true; |
|
| 2303 | + if ($found && in_array($change['method'], array('add', 'change'))) { |
|
| 2304 | + return true; |
|
| 2305 | + } |
|
| 2181 | 2306 | // Otherwise if we're removing and it wasn't found we're also done. |
| 2182 | - elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) |
|
| 2183 | - return true; |
|
| 2307 | + elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) { |
|
| 2308 | + return true; |
|
| 2309 | + } |
|
| 2184 | 2310 | // Otherwise is it just a test? |
| 2185 | - elseif ($is_test) |
|
| 2186 | - return false; |
|
| 2311 | + elseif ($is_test) { |
|
| 2312 | + return false; |
|
| 2313 | + } |
|
| 2187 | 2314 | |
| 2188 | 2315 | // Not found it yet? Bummer! How about we see if we're currently doing it? |
| 2189 | 2316 | $running = false; |
@@ -2194,8 +2321,9 @@ discard block |
||
| 2194 | 2321 | SHOW FULL PROCESSLIST'); |
| 2195 | 2322 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2196 | 2323 | { |
| 2197 | - if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) |
|
| 2198 | - $found = true; |
|
| 2324 | + if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) { |
|
| 2325 | + $found = true; |
|
| 2326 | + } |
|
| 2199 | 2327 | } |
| 2200 | 2328 | |
| 2201 | 2329 | // Can't find it? Then we need to run it fools! |
@@ -2207,8 +2335,9 @@ discard block |
||
| 2207 | 2335 | ALTER TABLE ' . $db_prefix . $change['table'] . ' |
| 2208 | 2336 | ' . $change['text'], true) !== false; |
| 2209 | 2337 | |
| 2210 | - if (!$success) |
|
| 2211 | - return false; |
|
| 2338 | + if (!$success) { |
|
| 2339 | + return false; |
|
| 2340 | + } |
|
| 2212 | 2341 | |
| 2213 | 2342 | // Return |
| 2214 | 2343 | $running = true; |
@@ -2250,8 +2379,9 @@ discard block |
||
| 2250 | 2379 | 'db_error_skip' => true, |
| 2251 | 2380 | ) |
| 2252 | 2381 | ); |
| 2253 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2254 | - die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2382 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2383 | + die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']); |
|
| 2384 | + } |
|
| 2255 | 2385 | $table_row = $smcFunc['db_fetch_assoc']($request); |
| 2256 | 2386 | $smcFunc['db_free_result']($request); |
| 2257 | 2387 | |
@@ -2273,18 +2403,19 @@ discard block |
||
| 2273 | 2403 | ) |
| 2274 | 2404 | ); |
| 2275 | 2405 | // No results? Just forget it all together. |
| 2276 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 2277 | - unset($table_row['Collation']); |
|
| 2278 | - else |
|
| 2279 | - $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2406 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 2407 | + unset($table_row['Collation']); |
|
| 2408 | + } else { |
|
| 2409 | + $collation_info = $smcFunc['db_fetch_assoc']($request); |
|
| 2410 | + } |
|
| 2280 | 2411 | $smcFunc['db_free_result']($request); |
| 2281 | 2412 | } |
| 2282 | 2413 | |
| 2283 | 2414 | if ($column_fix) |
| 2284 | 2415 | { |
| 2285 | 2416 | // Make sure there are no NULL's left. |
| 2286 | - if ($null_fix) |
|
| 2287 | - $smcFunc['db_query']('', ' |
|
| 2417 | + if ($null_fix) { |
|
| 2418 | + $smcFunc['db_query']('', ' |
|
| 2288 | 2419 | UPDATE {db_prefix}' . $change['table'] . ' |
| 2289 | 2420 | SET ' . $change['column'] . ' = {string:default} |
| 2290 | 2421 | WHERE ' . $change['column'] . ' IS NULL', |
@@ -2293,6 +2424,7 @@ discard block |
||
| 2293 | 2424 | 'db_error_skip' => true, |
| 2294 | 2425 | ) |
| 2295 | 2426 | ); |
| 2427 | + } |
|
| 2296 | 2428 | |
| 2297 | 2429 | // Do the actual alteration. |
| 2298 | 2430 | $smcFunc['db_query']('', ' |
@@ -2321,8 +2453,9 @@ discard block |
||
| 2321 | 2453 | } |
| 2322 | 2454 | |
| 2323 | 2455 | // Not a column we need to check on? |
| 2324 | - if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) |
|
| 2325 | - return; |
|
| 2456 | + if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) { |
|
| 2457 | + return; |
|
| 2458 | + } |
|
| 2326 | 2459 | |
| 2327 | 2460 | // Break it up you (six|seven). |
| 2328 | 2461 | $temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text'])); |
@@ -2341,13 +2474,13 @@ discard block |
||
| 2341 | 2474 | 'new_name' => $temp[2], |
| 2342 | 2475 | )); |
| 2343 | 2476 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2344 | - if ($smcFunc['db_num_rows'] != 1) |
|
| 2345 | - return; |
|
| 2477 | + if ($smcFunc['db_num_rows'] != 1) { |
|
| 2478 | + return; |
|
| 2479 | + } |
|
| 2346 | 2480 | |
| 2347 | 2481 | list (, $current_type) = $smcFunc['db_fetch_assoc']($request); |
| 2348 | 2482 | $smcFunc['db_free_result']($request); |
| 2349 | - } |
|
| 2350 | - else |
|
| 2483 | + } else |
|
| 2351 | 2484 | { |
| 2352 | 2485 | // Do this the old fashion, sure method way. |
| 2353 | 2486 | $request = $smcFunc['db_query']('', ' |
@@ -2358,21 +2491,24 @@ discard block |
||
| 2358 | 2491 | )); |
| 2359 | 2492 | // Mayday! |
| 2360 | 2493 | // !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet. |
| 2361 | - if ($smcFunc['db_num_rows'] == 0) |
|
| 2362 | - return; |
|
| 2494 | + if ($smcFunc['db_num_rows'] == 0) { |
|
| 2495 | + return; |
|
| 2496 | + } |
|
| 2363 | 2497 | |
| 2364 | 2498 | // Oh where, oh where has my little field gone. Oh where can it be... |
| 2365 | - while ($row = $smcFunc['db_query']($request)) |
|
| 2366 | - if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2499 | + while ($row = $smcFunc['db_query']($request)) { |
|
| 2500 | + if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2]) |
|
| 2367 | 2501 | { |
| 2368 | 2502 | $current_type = $row['Type']; |
| 2503 | + } |
|
| 2369 | 2504 | break; |
| 2370 | 2505 | } |
| 2371 | 2506 | } |
| 2372 | 2507 | |
| 2373 | 2508 | // If this doesn't match, the column may of been altered for a reason. |
| 2374 | - if (trim($current_type) != trim($temp[3])) |
|
| 2375 | - $temp[3] = $current_type; |
|
| 2509 | + if (trim($current_type) != trim($temp[3])) { |
|
| 2510 | + $temp[3] = $current_type; |
|
| 2511 | + } |
|
| 2376 | 2512 | |
| 2377 | 2513 | // Piece this back together. |
| 2378 | 2514 | $change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp)); |
@@ -2384,8 +2520,9 @@ discard block |
||
| 2384 | 2520 | global $start_time, $timeLimitThreshold, $command_line, $custom_warning; |
| 2385 | 2521 | global $step_progress, $is_debug, $upcontext; |
| 2386 | 2522 | |
| 2387 | - if ($_GET['substep'] < $substep) |
|
| 2388 | - $_GET['substep'] = $substep; |
|
| 2523 | + if ($_GET['substep'] < $substep) { |
|
| 2524 | + $_GET['substep'] = $substep; |
|
| 2525 | + } |
|
| 2389 | 2526 | |
| 2390 | 2527 | if ($command_line) |
| 2391 | 2528 | { |
@@ -2398,29 +2535,33 @@ discard block |
||
| 2398 | 2535 | } |
| 2399 | 2536 | |
| 2400 | 2537 | @set_time_limit(300); |
| 2401 | - if (function_exists('apache_reset_timeout')) |
|
| 2402 | - @apache_reset_timeout(); |
|
| 2538 | + if (function_exists('apache_reset_timeout')) { |
|
| 2539 | + @apache_reset_timeout(); |
|
| 2540 | + } |
|
| 2403 | 2541 | |
| 2404 | - if (time() - $start_time <= $timeLimitThreshold) |
|
| 2405 | - return; |
|
| 2542 | + if (time() - $start_time <= $timeLimitThreshold) { |
|
| 2543 | + return; |
|
| 2544 | + } |
|
| 2406 | 2545 | |
| 2407 | 2546 | // Do we have some custom step progress stuff? |
| 2408 | 2547 | if (!empty($step_progress)) |
| 2409 | 2548 | { |
| 2410 | 2549 | $upcontext['substep_progress'] = 0; |
| 2411 | 2550 | $upcontext['substep_progress_name'] = $step_progress['name']; |
| 2412 | - if ($step_progress['current'] > $step_progress['total']) |
|
| 2413 | - $upcontext['substep_progress'] = 99.9; |
|
| 2414 | - else |
|
| 2415 | - $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2551 | + if ($step_progress['current'] > $step_progress['total']) { |
|
| 2552 | + $upcontext['substep_progress'] = 99.9; |
|
| 2553 | + } else { |
|
| 2554 | + $upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100; |
|
| 2555 | + } |
|
| 2416 | 2556 | |
| 2417 | 2557 | // Make it nicely rounded. |
| 2418 | 2558 | $upcontext['substep_progress'] = round($upcontext['substep_progress'], 1); |
| 2419 | 2559 | } |
| 2420 | 2560 | |
| 2421 | 2561 | // If this is XML we just exit right away! |
| 2422 | - if (isset($_GET['xml'])) |
|
| 2423 | - return upgradeExit(); |
|
| 2562 | + if (isset($_GET['xml'])) { |
|
| 2563 | + return upgradeExit(); |
|
| 2564 | + } |
|
| 2424 | 2565 | |
| 2425 | 2566 | // We're going to pause after this! |
| 2426 | 2567 | $upcontext['pause'] = true; |
@@ -2428,13 +2569,15 @@ discard block |
||
| 2428 | 2569 | $upcontext['query_string'] = ''; |
| 2429 | 2570 | foreach ($_GET as $k => $v) |
| 2430 | 2571 | { |
| 2431 | - if ($k != 'data' && $k != 'substep' && $k != 'step') |
|
| 2432 | - $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2572 | + if ($k != 'data' && $k != 'substep' && $k != 'step') { |
|
| 2573 | + $upcontext['query_string'] .= ';' . $k . '=' . $v; |
|
| 2574 | + } |
|
| 2433 | 2575 | } |
| 2434 | 2576 | |
| 2435 | 2577 | // Custom warning? |
| 2436 | - if (!empty($custom_warning)) |
|
| 2437 | - $upcontext['custom_warning'] = $custom_warning; |
|
| 2578 | + if (!empty($custom_warning)) { |
|
| 2579 | + $upcontext['custom_warning'] = $custom_warning; |
|
| 2580 | + } |
|
| 2438 | 2581 | |
| 2439 | 2582 | upgradeExit(); |
| 2440 | 2583 | } |
@@ -2449,25 +2592,26 @@ discard block |
||
| 2449 | 2592 | ob_implicit_flush(true); |
| 2450 | 2593 | @set_time_limit(600); |
| 2451 | 2594 | |
| 2452 | - if (!isset($_SERVER['argv'])) |
|
| 2453 | - $_SERVER['argv'] = array(); |
|
| 2595 | + if (!isset($_SERVER['argv'])) { |
|
| 2596 | + $_SERVER['argv'] = array(); |
|
| 2597 | + } |
|
| 2454 | 2598 | $_GET['maint'] = 1; |
| 2455 | 2599 | |
| 2456 | 2600 | foreach ($_SERVER['argv'] as $i => $arg) |
| 2457 | 2601 | { |
| 2458 | - if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) |
|
| 2459 | - $_GET['lang'] = $match[1]; |
|
| 2460 | - elseif (preg_match('~^--path=(.+)$~', $arg) != 0) |
|
| 2461 | - continue; |
|
| 2462 | - elseif ($arg == '--no-maintenance') |
|
| 2463 | - $_GET['maint'] = 0; |
|
| 2464 | - elseif ($arg == '--debug') |
|
| 2465 | - $is_debug = true; |
|
| 2466 | - elseif ($arg == '--backup') |
|
| 2467 | - $_POST['backup'] = 1; |
|
| 2468 | - elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) |
|
| 2469 | - $_GET['conv'] = 1; |
|
| 2470 | - elseif ($i != 0) |
|
| 2602 | + if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) { |
|
| 2603 | + $_GET['lang'] = $match[1]; |
|
| 2604 | + } elseif (preg_match('~^--path=(.+)$~', $arg) != 0) { |
|
| 2605 | + continue; |
|
| 2606 | + } elseif ($arg == '--no-maintenance') { |
|
| 2607 | + $_GET['maint'] = 0; |
|
| 2608 | + } elseif ($arg == '--debug') { |
|
| 2609 | + $is_debug = true; |
|
| 2610 | + } elseif ($arg == '--backup') { |
|
| 2611 | + $_POST['backup'] = 1; |
|
| 2612 | + } elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) { |
|
| 2613 | + $_GET['conv'] = 1; |
|
| 2614 | + } elseif ($i != 0) |
|
| 2471 | 2615 | { |
| 2472 | 2616 | echo 'SMF Command-line Upgrader |
| 2473 | 2617 | Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]... |
@@ -2481,10 +2625,12 @@ discard block |
||
| 2481 | 2625 | } |
| 2482 | 2626 | } |
| 2483 | 2627 | |
| 2484 | - if (!php_version_check()) |
|
| 2485 | - print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2486 | - if (!db_version_check()) |
|
| 2487 | - print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2628 | + if (!php_version_check()) { |
|
| 2629 | + print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true); |
|
| 2630 | + } |
|
| 2631 | + if (!db_version_check()) { |
|
| 2632 | + print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true); |
|
| 2633 | + } |
|
| 2488 | 2634 | |
| 2489 | 2635 | // Do some checks to make sure they have proper privileges |
| 2490 | 2636 | db_extend('packages'); |
@@ -2499,34 +2645,39 @@ discard block |
||
| 2499 | 2645 | $drop = $smcFunc['db_drop_table']('{db_prefix}priv_check'); |
| 2500 | 2646 | |
| 2501 | 2647 | // Sorry... we need CREATE, ALTER and DROP |
| 2502 | - if (!$create || !$alter || !$drop) |
|
| 2503 | - 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); |
|
| 2648 | + if (!$create || !$alter || !$drop) { |
|
| 2649 | + 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); |
|
| 2650 | + } |
|
| 2504 | 2651 | |
| 2505 | 2652 | $check = @file_exists($modSettings['theme_dir'] . '/index.template.php') |
| 2506 | 2653 | && @file_exists($sourcedir . '/QueryString.php') |
| 2507 | 2654 | && @file_exists($sourcedir . '/ManageBoards.php'); |
| 2508 | - if (!$check && !isset($modSettings['smfVersion'])) |
|
| 2509 | - print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2655 | + if (!$check && !isset($modSettings['smfVersion'])) { |
|
| 2656 | + print_error('Error: Some files are missing or out-of-date.', true); |
|
| 2657 | + } |
|
| 2510 | 2658 | |
| 2511 | 2659 | // Do a quick version spot check. |
| 2512 | 2660 | $temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096); |
| 2513 | 2661 | preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match); |
| 2514 | - if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) |
|
| 2515 | - print_error('Error: Some files have not yet been updated properly.'); |
|
| 2662 | + if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) { |
|
| 2663 | + print_error('Error: Some files have not yet been updated properly.'); |
|
| 2664 | + } |
|
| 2516 | 2665 | |
| 2517 | 2666 | // Make sure Settings.php is writable. |
| 2518 | 2667 | quickFileWritable($boarddir . '/Settings.php'); |
| 2519 | - if (!is_writable($boarddir . '/Settings.php')) |
|
| 2520 | - print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2668 | + if (!is_writable($boarddir . '/Settings.php')) { |
|
| 2669 | + print_error('Error: Unable to obtain write access to "Settings.php".', true); |
|
| 2670 | + } |
|
| 2521 | 2671 | |
| 2522 | 2672 | // Make sure Settings_bak.php is writable. |
| 2523 | 2673 | quickFileWritable($boarddir . '/Settings_bak.php'); |
| 2524 | - if (!is_writable($boarddir . '/Settings_bak.php')) |
|
| 2525 | - print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2674 | + if (!is_writable($boarddir . '/Settings_bak.php')) { |
|
| 2675 | + print_error('Error: Unable to obtain write access to "Settings_bak.php".'); |
|
| 2676 | + } |
|
| 2526 | 2677 | |
| 2527 | - if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) |
|
| 2528 | - print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2529 | - elseif (isset($modSettings['agreement'])) |
|
| 2678 | + if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) { |
|
| 2679 | + print_error('Error: Unable to obtain write access to "agreement.txt".'); |
|
| 2680 | + } elseif (isset($modSettings['agreement'])) |
|
| 2530 | 2681 | { |
| 2531 | 2682 | $fp = fopen($boarddir . '/agreement.txt', 'w'); |
| 2532 | 2683 | fwrite($fp, $modSettings['agreement']); |
@@ -2536,36 +2687,42 @@ discard block |
||
| 2536 | 2687 | // Make sure Themes is writable. |
| 2537 | 2688 | quickFileWritable($modSettings['theme_dir']); |
| 2538 | 2689 | |
| 2539 | - if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) |
|
| 2540 | - print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2690 | + if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) { |
|
| 2691 | + print_error('Error: Unable to obtain write access to "Themes".'); |
|
| 2692 | + } |
|
| 2541 | 2693 | |
| 2542 | 2694 | // Make sure cache directory exists and is writable! |
| 2543 | 2695 | $cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir; |
| 2544 | - if (!file_exists($cachedir_temp)) |
|
| 2545 | - @mkdir($cachedir_temp); |
|
| 2696 | + if (!file_exists($cachedir_temp)) { |
|
| 2697 | + @mkdir($cachedir_temp); |
|
| 2698 | + } |
|
| 2546 | 2699 | |
| 2547 | 2700 | // Make sure the cache temp dir is writable. |
| 2548 | 2701 | quickFileWritable($cachedir_temp); |
| 2549 | 2702 | |
| 2550 | - if (!is_writable($cachedir_temp)) |
|
| 2551 | - print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2703 | + if (!is_writable($cachedir_temp)) { |
|
| 2704 | + print_error('Error: Unable to obtain write access to "cache".', true); |
|
| 2705 | + } |
|
| 2552 | 2706 | |
| 2553 | 2707 | // Make sure db_last_error.php is writable. |
| 2554 | 2708 | quickFileWritable($cachedir_temp . '/db_last_error.php'); |
| 2555 | - if (!is_writable($cachedir_temp . '/db_last_error.php')) |
|
| 2556 | - print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2709 | + if (!is_writable($cachedir_temp . '/db_last_error.php')) { |
|
| 2710 | + print_error('Error: Unable to obtain write access to "db_last_error.php".'); |
|
| 2711 | + } |
|
| 2557 | 2712 | |
| 2558 | - if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) |
|
| 2559 | - print_error('Error: Unable to find language files!', true); |
|
| 2560 | - else |
|
| 2713 | + if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) { |
|
| 2714 | + print_error('Error: Unable to find language files!', true); |
|
| 2715 | + } else |
|
| 2561 | 2716 | { |
| 2562 | 2717 | $temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096); |
| 2563 | 2718 | preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); |
| 2564 | 2719 | |
| 2565 | - if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) |
|
| 2566 | - print_error('Error: Language files out of date.', true); |
|
| 2567 | - if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) |
|
| 2568 | - print_error('Error: Install language is missing for selected language.', true); |
|
| 2720 | + if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { |
|
| 2721 | + print_error('Error: Language files out of date.', true); |
|
| 2722 | + } |
|
| 2723 | + if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) { |
|
| 2724 | + print_error('Error: Install language is missing for selected language.', true); |
|
| 2725 | + } |
|
| 2569 | 2726 | |
| 2570 | 2727 | // Otherwise include it! |
| 2571 | 2728 | require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'); |
@@ -2585,8 +2742,9 @@ discard block |
||
| 2585 | 2742 | global $db_prefix, $db_type, $command_line, $support_js, $txt; |
| 2586 | 2743 | |
| 2587 | 2744 | // Done it already? |
| 2588 | - if (!empty($_POST['utf8_done'])) |
|
| 2589 | - return true; |
|
| 2745 | + if (!empty($_POST['utf8_done'])) { |
|
| 2746 | + return true; |
|
| 2747 | + } |
|
| 2590 | 2748 | |
| 2591 | 2749 | // First make sure they aren't already on UTF-8 before we go anywhere... |
| 2592 | 2750 | if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8')) |
@@ -2599,8 +2757,7 @@ discard block |
||
| 2599 | 2757 | ); |
| 2600 | 2758 | |
| 2601 | 2759 | return true; |
| 2602 | - } |
|
| 2603 | - else |
|
| 2760 | + } else |
|
| 2604 | 2761 | { |
| 2605 | 2762 | $upcontext['page_title'] = $txt['converting_utf8']; |
| 2606 | 2763 | $upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8'; |
@@ -2644,8 +2801,9 @@ discard block |
||
| 2644 | 2801 | ) |
| 2645 | 2802 | ); |
| 2646 | 2803 | $db_charsets = array(); |
| 2647 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2648 | - $db_charsets[] = $row['Charset']; |
|
| 2804 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2805 | + $db_charsets[] = $row['Charset']; |
|
| 2806 | + } |
|
| 2649 | 2807 | |
| 2650 | 2808 | $smcFunc['db_free_result']($request); |
| 2651 | 2809 | |
@@ -2681,13 +2839,15 @@ discard block |
||
| 2681 | 2839 | // If there's a fulltext index, we need to drop it first... |
| 2682 | 2840 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
| 2683 | 2841 | { |
| 2684 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2685 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2842 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2843 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
| 2686 | 2844 | $upcontext['fulltext_index'][] = $row['Key_name']; |
| 2845 | + } |
|
| 2687 | 2846 | $smcFunc['db_free_result']($request); |
| 2688 | 2847 | |
| 2689 | - if (isset($upcontext['fulltext_index'])) |
|
| 2690 | - $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2848 | + if (isset($upcontext['fulltext_index'])) { |
|
| 2849 | + $upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']); |
|
| 2850 | + } |
|
| 2691 | 2851 | } |
| 2692 | 2852 | |
| 2693 | 2853 | // Drop it and make a note... |
@@ -2877,8 +3037,9 @@ discard block |
||
| 2877 | 3037 | $replace = '%field%'; |
| 2878 | 3038 | |
| 2879 | 3039 | // Build a huge REPLACE statement... |
| 2880 | - foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) |
|
| 2881 | - $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 3040 | + foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) { |
|
| 3041 | + $replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')'; |
|
| 3042 | + } |
|
| 2882 | 3043 | } |
| 2883 | 3044 | |
| 2884 | 3045 | // Get a list of table names ahead of time... This makes it easier to set our substep and such |
@@ -2888,9 +3049,10 @@ discard block |
||
| 2888 | 3049 | $upcontext['table_count'] = count($queryTables); |
| 2889 | 3050 | |
| 2890 | 3051 | // What ones have we already done? |
| 2891 | - foreach ($queryTables as $id => $table) |
|
| 2892 | - if ($id < $_GET['substep']) |
|
| 3052 | + foreach ($queryTables as $id => $table) { |
|
| 3053 | + if ($id < $_GET['substep']) |
|
| 2893 | 3054 | $upcontext['previous_tables'][] = $table; |
| 3055 | + } |
|
| 2894 | 3056 | |
| 2895 | 3057 | $upcontext['cur_table_num'] = $_GET['substep']; |
| 2896 | 3058 | $upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]); |
@@ -2927,8 +3089,9 @@ discard block |
||
| 2927 | 3089 | nextSubstep($substep); |
| 2928 | 3090 | |
| 2929 | 3091 | // Just to make sure it doesn't time out. |
| 2930 | - if (function_exists('apache_reset_timeout')) |
|
| 2931 | - @apache_reset_timeout(); |
|
| 3092 | + if (function_exists('apache_reset_timeout')) { |
|
| 3093 | + @apache_reset_timeout(); |
|
| 3094 | + } |
|
| 2932 | 3095 | |
| 2933 | 3096 | $table_charsets = array(); |
| 2934 | 3097 | |
@@ -2951,8 +3114,9 @@ discard block |
||
| 2951 | 3114 | |
| 2952 | 3115 | // Build structure of columns to operate on organized by charset; only operate on columns not yet utf8 |
| 2953 | 3116 | if ($charset != 'utf8') { |
| 2954 | - if (!isset($table_charsets[$charset])) |
|
| 2955 | - $table_charsets[$charset] = array(); |
|
| 3117 | + if (!isset($table_charsets[$charset])) { |
|
| 3118 | + $table_charsets[$charset] = array(); |
|
| 3119 | + } |
|
| 2956 | 3120 | |
| 2957 | 3121 | $table_charsets[$charset][] = $column_info; |
| 2958 | 3122 | } |
@@ -2993,10 +3157,11 @@ discard block |
||
| 2993 | 3157 | if (isset($translation_tables[$upcontext['charset_detected']])) |
| 2994 | 3158 | { |
| 2995 | 3159 | $update = ''; |
| 2996 | - foreach ($table_charsets as $charset => $columns) |
|
| 2997 | - foreach ($columns as $column) |
|
| 3160 | + foreach ($table_charsets as $charset => $columns) { |
|
| 3161 | + foreach ($columns as $column) |
|
| 2998 | 3162 | $update .= ' |
| 2999 | 3163 | ' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ','; |
| 3164 | + } |
|
| 3000 | 3165 | |
| 3001 | 3166 | $smcFunc['db_query']('', ' |
| 3002 | 3167 | UPDATE {raw:table_name} |
@@ -3021,8 +3186,9 @@ discard block |
||
| 3021 | 3186 | // Now do the actual conversion (if still needed). |
| 3022 | 3187 | if ($charsets[$upcontext['charset_detected']] !== 'utf8') |
| 3023 | 3188 | { |
| 3024 | - if ($command_line) |
|
| 3025 | - echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3189 | + if ($command_line) { |
|
| 3190 | + echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...'; |
|
| 3191 | + } |
|
| 3026 | 3192 | |
| 3027 | 3193 | $smcFunc['db_query']('', ' |
| 3028 | 3194 | ALTER TABLE {raw:table_name} |
@@ -3032,12 +3198,14 @@ discard block |
||
| 3032 | 3198 | ) |
| 3033 | 3199 | ); |
| 3034 | 3200 | |
| 3035 | - if ($command_line) |
|
| 3036 | - echo " done.\n"; |
|
| 3201 | + if ($command_line) { |
|
| 3202 | + echo " done.\n"; |
|
| 3203 | + } |
|
| 3037 | 3204 | } |
| 3038 | 3205 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3039 | - if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) |
|
| 3040 | - return upgradeExit(); |
|
| 3206 | + if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) { |
|
| 3207 | + return upgradeExit(); |
|
| 3208 | + } |
|
| 3041 | 3209 | } |
| 3042 | 3210 | |
| 3043 | 3211 | $prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']]; |
@@ -3066,8 +3234,8 @@ discard block |
||
| 3066 | 3234 | ); |
| 3067 | 3235 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3068 | 3236 | { |
| 3069 | - 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) |
|
| 3070 | - $smcFunc['db_query']('', ' |
|
| 3237 | + 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) { |
|
| 3238 | + $smcFunc['db_query']('', ' |
|
| 3071 | 3239 | UPDATE {db_prefix}log_actions |
| 3072 | 3240 | SET extra = {string:extra} |
| 3073 | 3241 | WHERE id_action = {int:current_action}', |
@@ -3076,6 +3244,7 @@ discard block |
||
| 3076 | 3244 | 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4], |
| 3077 | 3245 | ) |
| 3078 | 3246 | ); |
| 3247 | + } |
|
| 3079 | 3248 | } |
| 3080 | 3249 | $smcFunc['db_free_result']($request); |
| 3081 | 3250 | |
@@ -3097,15 +3266,17 @@ discard block |
||
| 3097 | 3266 | // First thing's first - did we already do this? |
| 3098 | 3267 | if (!empty($modSettings['json_done'])) |
| 3099 | 3268 | { |
| 3100 | - if ($command_line) |
|
| 3101 | - return DeleteUpgrade(); |
|
| 3102 | - else |
|
| 3103 | - return true; |
|
| 3269 | + if ($command_line) { |
|
| 3270 | + return DeleteUpgrade(); |
|
| 3271 | + } else { |
|
| 3272 | + return true; |
|
| 3273 | + } |
|
| 3104 | 3274 | } |
| 3105 | 3275 | |
| 3106 | 3276 | // Done it already - js wise? |
| 3107 | - if (!empty($_POST['json_done'])) |
|
| 3108 | - return true; |
|
| 3277 | + if (!empty($_POST['json_done'])) { |
|
| 3278 | + return true; |
|
| 3279 | + } |
|
| 3109 | 3280 | |
| 3110 | 3281 | // List of tables affected by this function |
| 3111 | 3282 | // name => array('key', col1[,col2|true[,col3]]) |
@@ -3137,12 +3308,14 @@ discard block |
||
| 3137 | 3308 | $upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0]; |
| 3138 | 3309 | $upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100); |
| 3139 | 3310 | |
| 3140 | - foreach ($keys as $id => $table) |
|
| 3141 | - if ($id < $_GET['substep']) |
|
| 3311 | + foreach ($keys as $id => $table) { |
|
| 3312 | + if ($id < $_GET['substep']) |
|
| 3142 | 3313 | $upcontext['previous_tables'][] = $table; |
| 3314 | + } |
|
| 3143 | 3315 | |
| 3144 | - if ($command_line) |
|
| 3145 | - echo 'Converting data from serialize() to json_encode().'; |
|
| 3316 | + if ($command_line) { |
|
| 3317 | + echo 'Converting data from serialize() to json_encode().'; |
|
| 3318 | + } |
|
| 3146 | 3319 | |
| 3147 | 3320 | if (!$support_js || isset($_GET['xml'])) |
| 3148 | 3321 | { |
@@ -3182,8 +3355,9 @@ discard block |
||
| 3182 | 3355 | |
| 3183 | 3356 | // Loop through and fix these... |
| 3184 | 3357 | $new_settings = array(); |
| 3185 | - if ($command_line) |
|
| 3186 | - echo "\n" . 'Fixing some settings...'; |
|
| 3358 | + if ($command_line) { |
|
| 3359 | + echo "\n" . 'Fixing some settings...'; |
|
| 3360 | + } |
|
| 3187 | 3361 | |
| 3188 | 3362 | foreach ($serialized_settings as $var) |
| 3189 | 3363 | { |
@@ -3191,22 +3365,24 @@ discard block |
||
| 3191 | 3365 | { |
| 3192 | 3366 | // Attempt to unserialize the setting |
| 3193 | 3367 | $temp = @safe_unserialize($modSettings[$var]); |
| 3194 | - if (!$temp && $command_line) |
|
| 3195 | - echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3196 | - elseif ($temp !== false) |
|
| 3197 | - $new_settings[$var] = json_encode($temp); |
|
| 3368 | + if (!$temp && $command_line) { |
|
| 3369 | + echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping."; |
|
| 3370 | + } elseif ($temp !== false) { |
|
| 3371 | + $new_settings[$var] = json_encode($temp); |
|
| 3372 | + } |
|
| 3198 | 3373 | } |
| 3199 | 3374 | } |
| 3200 | 3375 | |
| 3201 | 3376 | // Update everything at once |
| 3202 | - if (!function_exists('cache_put_data')) |
|
| 3203 | - require_once($sourcedir . '/Load.php'); |
|
| 3377 | + if (!function_exists('cache_put_data')) { |
|
| 3378 | + require_once($sourcedir . '/Load.php'); |
|
| 3379 | + } |
|
| 3204 | 3380 | updateSettings($new_settings, true); |
| 3205 | 3381 | |
| 3206 | - if ($command_line) |
|
| 3207 | - echo ' done.'; |
|
| 3208 | - } |
|
| 3209 | - elseif ($table == 'themes') |
|
| 3382 | + if ($command_line) { |
|
| 3383 | + echo ' done.'; |
|
| 3384 | + } |
|
| 3385 | + } elseif ($table == 'themes') |
|
| 3210 | 3386 | { |
| 3211 | 3387 | // Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point... |
| 3212 | 3388 | $query = $smcFunc['db_query']('', ' |
@@ -3225,10 +3401,11 @@ discard block |
||
| 3225 | 3401 | |
| 3226 | 3402 | if ($command_line) |
| 3227 | 3403 | { |
| 3228 | - if ($temp === false) |
|
| 3229 | - echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3230 | - else |
|
| 3231 | - echo "\n" . 'Fixing admin preferences...'; |
|
| 3404 | + if ($temp === false) { |
|
| 3405 | + echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.'; |
|
| 3406 | + } else { |
|
| 3407 | + echo "\n" . 'Fixing admin preferences...'; |
|
| 3408 | + } |
|
| 3232 | 3409 | } |
| 3233 | 3410 | |
| 3234 | 3411 | if ($temp !== false) |
@@ -3250,15 +3427,15 @@ discard block |
||
| 3250 | 3427 | ) |
| 3251 | 3428 | ); |
| 3252 | 3429 | |
| 3253 | - if ($command_line) |
|
| 3254 | - echo ' done.'; |
|
| 3430 | + if ($command_line) { |
|
| 3431 | + echo ' done.'; |
|
| 3432 | + } |
|
| 3255 | 3433 | } |
| 3256 | 3434 | } |
| 3257 | 3435 | |
| 3258 | 3436 | $smcFunc['db_free_result']($query); |
| 3259 | 3437 | } |
| 3260 | - } |
|
| 3261 | - else |
|
| 3438 | + } else |
|
| 3262 | 3439 | { |
| 3263 | 3440 | // First item is always the key... |
| 3264 | 3441 | $key = $info[0]; |
@@ -3269,8 +3446,7 @@ discard block |
||
| 3269 | 3446 | { |
| 3270 | 3447 | $col_select = $info[1]; |
| 3271 | 3448 | $where = ' WHERE ' . $info[1] . ' != {empty}'; |
| 3272 | - } |
|
| 3273 | - else |
|
| 3449 | + } else |
|
| 3274 | 3450 | { |
| 3275 | 3451 | $col_select = implode(', ', $info); |
| 3276 | 3452 | } |
@@ -3303,8 +3479,7 @@ discard block |
||
| 3303 | 3479 | if ($temp === false && $command_line) |
| 3304 | 3480 | { |
| 3305 | 3481 | echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n"; |
| 3306 | - } |
|
| 3307 | - else |
|
| 3482 | + } else |
|
| 3308 | 3483 | { |
| 3309 | 3484 | $row[$col] = json_encode($temp); |
| 3310 | 3485 | |
@@ -3329,16 +3504,18 @@ discard block |
||
| 3329 | 3504 | } |
| 3330 | 3505 | } |
| 3331 | 3506 | |
| 3332 | - if ($command_line) |
|
| 3333 | - echo ' done.'; |
|
| 3507 | + if ($command_line) { |
|
| 3508 | + echo ' done.'; |
|
| 3509 | + } |
|
| 3334 | 3510 | |
| 3335 | 3511 | // Free up some memory... |
| 3336 | 3512 | $smcFunc['db_free_result']($query); |
| 3337 | 3513 | } |
| 3338 | 3514 | } |
| 3339 | 3515 | // If this is XML to keep it nice for the user do one table at a time anyway! |
| 3340 | - if (isset($_GET['xml'])) |
|
| 3341 | - return upgradeExit(); |
|
| 3516 | + if (isset($_GET['xml'])) { |
|
| 3517 | + return upgradeExit(); |
|
| 3518 | + } |
|
| 3342 | 3519 | } |
| 3343 | 3520 | |
| 3344 | 3521 | if ($command_line) |
@@ -3353,8 +3530,9 @@ discard block |
||
| 3353 | 3530 | |
| 3354 | 3531 | $_GET['substep'] = 0; |
| 3355 | 3532 | // Make sure we move on! |
| 3356 | - if ($command_line) |
|
| 3357 | - return DeleteUpgrade(); |
|
| 3533 | + if ($command_line) { |
|
| 3534 | + return DeleteUpgrade(); |
|
| 3535 | + } |
|
| 3358 | 3536 | |
| 3359 | 3537 | return true; |
| 3360 | 3538 | } |
@@ -3411,14 +3589,16 @@ discard block |
||
| 3411 | 3589 | global $upcontext, $txt, $settings; |
| 3412 | 3590 | |
| 3413 | 3591 | // Don't call me twice! |
| 3414 | - if (!empty($upcontext['chmod_called'])) |
|
| 3415 | - return; |
|
| 3592 | + if (!empty($upcontext['chmod_called'])) { |
|
| 3593 | + return; |
|
| 3594 | + } |
|
| 3416 | 3595 | |
| 3417 | 3596 | $upcontext['chmod_called'] = true; |
| 3418 | 3597 | |
| 3419 | 3598 | // Nothing? |
| 3420 | - if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) |
|
| 3421 | - return; |
|
| 3599 | + if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) { |
|
| 3600 | + return; |
|
| 3601 | + } |
|
| 3422 | 3602 | |
| 3423 | 3603 | // Was it a problem with Windows? |
| 3424 | 3604 | if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess') |
@@ -3450,11 +3630,12 @@ discard block |
||
| 3450 | 3630 | content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\'); |
| 3451 | 3631 | content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');'; |
| 3452 | 3632 | |
| 3453 | - if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') |
|
| 3454 | - echo ' |
|
| 3633 | + if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') { |
|
| 3634 | + echo ' |
|
| 3455 | 3635 | content.write(\'<hr>\n\t\t\t\'); |
| 3456 | 3636 | content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\'); |
| 3457 | 3637 | content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');'; |
| 3638 | + } |
|
| 3458 | 3639 | |
| 3459 | 3640 | echo ' |
| 3460 | 3641 | content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\'); |
@@ -3462,16 +3643,18 @@ discard block |
||
| 3462 | 3643 | } |
| 3463 | 3644 | </script>'; |
| 3464 | 3645 | |
| 3465 | - if (!empty($upcontext['chmod']['ftp_error'])) |
|
| 3466 | - echo ' |
|
| 3646 | + if (!empty($upcontext['chmod']['ftp_error'])) { |
|
| 3647 | + echo ' |
|
| 3467 | 3648 | <div class="error_message red"> |
| 3468 | 3649 | <p>', $txt['upgrade_ftp_error'], '<p> |
| 3469 | 3650 | <code>', $upcontext['chmod']['ftp_error'], '</code> |
| 3470 | 3651 | </div>'; |
| 3652 | + } |
|
| 3471 | 3653 | |
| 3472 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3473 | - echo ' |
|
| 3654 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3655 | + echo ' |
|
| 3474 | 3656 | <form action="', $upcontext['form_url'], '" method="post">'; |
| 3657 | + } |
|
| 3475 | 3658 | |
| 3476 | 3659 | echo ' |
| 3477 | 3660 | <dl class="settings"> |
@@ -3513,9 +3696,10 @@ discard block |
||
| 3513 | 3696 | <input type="submit" value="', $txt['ftp_connect'], '" class="button"> |
| 3514 | 3697 | </div>'; |
| 3515 | 3698 | |
| 3516 | - if (empty($upcontext['chmod_in_form'])) |
|
| 3517 | - echo ' |
|
| 3699 | + if (empty($upcontext['chmod_in_form'])) { |
|
| 3700 | + echo ' |
|
| 3518 | 3701 | </form>'; |
| 3702 | + } |
|
| 3519 | 3703 | |
| 3520 | 3704 | echo ' |
| 3521 | 3705 | </div><!-- .panel -->'; |
@@ -3579,9 +3763,10 @@ discard block |
||
| 3579 | 3763 | <h2>', $txt['upgrade_progress'], '</h2> |
| 3580 | 3764 | <ul>'; |
| 3581 | 3765 | |
| 3582 | - foreach ($upcontext['steps'] as $num => $step) |
|
| 3583 | - echo ' |
|
| 3766 | + foreach ($upcontext['steps'] as $num => $step) { |
|
| 3767 | + echo ' |
|
| 3584 | 3768 | <li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
| 3769 | + } |
|
| 3585 | 3770 | |
| 3586 | 3771 | echo ' |
| 3587 | 3772 | </ul> |
@@ -3594,13 +3779,14 @@ discard block |
||
| 3594 | 3779 | <span id="overall_text">', $upcontext['overall_percent'], '%</span> |
| 3595 | 3780 | </div>'; |
| 3596 | 3781 | |
| 3597 | - if (isset($upcontext['step_progress'])) |
|
| 3598 | - echo ' |
|
| 3782 | + if (isset($upcontext['step_progress'])) { |
|
| 3783 | + echo ' |
|
| 3599 | 3784 | <div id="progress_bar_step" class="progress_bar progress_yellow"> |
| 3600 | 3785 | <h3>', $txt['upgrade_step_progress'], '</h3> |
| 3601 | 3786 | <div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div> |
| 3602 | 3787 | <span id="step_text">', $upcontext['step_progress'], '%</span> |
| 3603 | 3788 | </div>'; |
| 3789 | + } |
|
| 3604 | 3790 | |
| 3605 | 3791 | echo ' |
| 3606 | 3792 | <div id="substep_bar_div" class="progress_bar" style="display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';"> |
@@ -3631,31 +3817,35 @@ discard block |
||
| 3631 | 3817 | { |
| 3632 | 3818 | global $upcontext, $txt; |
| 3633 | 3819 | |
| 3634 | - if (!empty($upcontext['pause'])) |
|
| 3635 | - echo ' |
|
| 3820 | + if (!empty($upcontext['pause'])) { |
|
| 3821 | + echo ' |
|
| 3636 | 3822 | <em>', $txt['upgrade_incomplete'], '.</em><br> |
| 3637 | 3823 | |
| 3638 | 3824 | <h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2> |
| 3639 | 3825 | <h3> |
| 3640 | 3826 | ', $txt['upgrade_paused_overload'], ' |
| 3641 | 3827 | </h3>'; |
| 3828 | + } |
|
| 3642 | 3829 | |
| 3643 | - if (!empty($upcontext['custom_warning'])) |
|
| 3644 | - echo ' |
|
| 3830 | + if (!empty($upcontext['custom_warning'])) { |
|
| 3831 | + echo ' |
|
| 3645 | 3832 | <div class="errorbox"> |
| 3646 | 3833 | <h3>', $txt['upgrade_note'], '</h3> |
| 3647 | 3834 | ', $upcontext['custom_warning'], ' |
| 3648 | 3835 | </div>'; |
| 3836 | + } |
|
| 3649 | 3837 | |
| 3650 | 3838 | echo ' |
| 3651 | 3839 | <div class="righttext" style="margin: 1ex;">'; |
| 3652 | 3840 | |
| 3653 | - if (!empty($upcontext['continue'])) |
|
| 3654 | - echo ' |
|
| 3841 | + if (!empty($upcontext['continue'])) { |
|
| 3842 | + echo ' |
|
| 3655 | 3843 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">'; |
| 3656 | - if (!empty($upcontext['skip'])) |
|
| 3657 | - echo ' |
|
| 3844 | + } |
|
| 3845 | + if (!empty($upcontext['skip'])) { |
|
| 3846 | + echo ' |
|
| 3658 | 3847 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">'; |
| 3848 | + } |
|
| 3659 | 3849 | |
| 3660 | 3850 | echo ' |
| 3661 | 3851 | </div> |
@@ -3706,11 +3896,12 @@ discard block |
||
| 3706 | 3896 | echo '<', '?xml version="1.0" encoding="UTF-8"?', '> |
| 3707 | 3897 | <smf>'; |
| 3708 | 3898 | |
| 3709 | - if (!empty($upcontext['get_data'])) |
|
| 3710 | - foreach ($upcontext['get_data'] as $k => $v) |
|
| 3899 | + if (!empty($upcontext['get_data'])) { |
|
| 3900 | + foreach ($upcontext['get_data'] as $k => $v) |
|
| 3711 | 3901 | echo ' |
| 3712 | 3902 | <get key="', $k, '">', $v, '</get>'; |
| 3713 | -} |
|
| 3903 | + } |
|
| 3904 | + } |
|
| 3714 | 3905 | |
| 3715 | 3906 | function template_xml_below() |
| 3716 | 3907 | { |
@@ -3750,20 +3941,22 @@ discard block |
||
| 3750 | 3941 | template_chmod(); |
| 3751 | 3942 | |
| 3752 | 3943 | // For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade! |
| 3753 | - if ($upcontext['is_large_forum']) |
|
| 3754 | - echo ' |
|
| 3944 | + if ($upcontext['is_large_forum']) { |
|
| 3945 | + echo ' |
|
| 3755 | 3946 | <div class="errorbox"> |
| 3756 | 3947 | <h3>', $txt['upgrade_warning'], '</h3> |
| 3757 | 3948 | ', $txt['upgrade_warning_lots_data'], ' |
| 3758 | 3949 | </div>'; |
| 3950 | + } |
|
| 3759 | 3951 | |
| 3760 | 3952 | // A warning message? |
| 3761 | - if (!empty($upcontext['warning'])) |
|
| 3762 | - echo ' |
|
| 3953 | + if (!empty($upcontext['warning'])) { |
|
| 3954 | + echo ' |
|
| 3763 | 3955 | <div class="errorbox"> |
| 3764 | 3956 | <h3>', $txt['upgrade_warning'], '</h3> |
| 3765 | 3957 | ', $upcontext['warning'], ' |
| 3766 | 3958 | </div>'; |
| 3959 | + } |
|
| 3767 | 3960 | |
| 3768 | 3961 | // Paths are incorrect? |
| 3769 | 3962 | echo ' |
@@ -3794,16 +3987,18 @@ discard block |
||
| 3794 | 3987 | <p>', sprintf($txt[$agoTxt], $ago_seconds, $ago_minutes, $ago_hours), '</p> |
| 3795 | 3988 | <p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>'; |
| 3796 | 3989 | |
| 3797 | - if ($updated < 600) |
|
| 3798 | - echo ' |
|
| 3990 | + if ($updated < 600) { |
|
| 3991 | + echo ' |
|
| 3799 | 3992 | <p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>'; |
| 3993 | + } |
|
| 3800 | 3994 | |
| 3801 | - if ($updated > $upcontext['inactive_timeout']) |
|
| 3802 | - echo ' |
|
| 3995 | + if ($updated > $upcontext['inactive_timeout']) { |
|
| 3996 | + echo ' |
|
| 3803 | 3997 | <p>',$txt['upgrade_run'], '</p>'; |
| 3804 | - else |
|
| 3805 | - echo ' |
|
| 3998 | + } else { |
|
| 3999 | + echo ' |
|
| 3806 | 4000 | <p>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'), '</p>'; |
| 4001 | + } |
|
| 3807 | 4002 | |
| 3808 | 4003 | echo ' |
| 3809 | 4004 | </div>'; |
@@ -3819,9 +4014,10 @@ discard block |
||
| 3819 | 4014 | <dd> |
| 3820 | 4015 | <input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>'; |
| 3821 | 4016 | |
| 3822 | - if (!empty($upcontext['username_incorrect'])) |
|
| 3823 | - echo ' |
|
| 4017 | + if (!empty($upcontext['username_incorrect'])) { |
|
| 4018 | + echo ' |
|
| 3824 | 4019 | <div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>'; |
| 4020 | + } |
|
| 3825 | 4021 | |
| 3826 | 4022 | echo ' |
| 3827 | 4023 | </dd> |
@@ -3832,9 +4028,10 @@ discard block |
||
| 3832 | 4028 | <input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '> |
| 3833 | 4029 | <input type="hidden" name="hash_passwrd" value="">'; |
| 3834 | 4030 | |
| 3835 | - if (!empty($upcontext['password_failed'])) |
|
| 3836 | - echo ' |
|
| 4031 | + if (!empty($upcontext['password_failed'])) { |
|
| 4032 | + echo ' |
|
| 3837 | 4033 | <div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>'; |
| 4034 | + } |
|
| 3838 | 4035 | |
| 3839 | 4036 | echo ' |
| 3840 | 4037 | </dd>'; |
@@ -3902,12 +4099,13 @@ discard block |
||
| 3902 | 4099 | <form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">'; |
| 3903 | 4100 | |
| 3904 | 4101 | // Warning message? |
| 3905 | - if (!empty($upcontext['upgrade_options_warning'])) |
|
| 3906 | - echo ' |
|
| 4102 | + if (!empty($upcontext['upgrade_options_warning'])) { |
|
| 4103 | + echo ' |
|
| 3907 | 4104 | <div class="errorbox"> |
| 3908 | 4105 | <h3>', $txt['upgrade_warning'] ,'</h3> |
| 3909 | 4106 | ', $upcontext['upgrade_options_warning'], ' |
| 3910 | 4107 | </div>'; |
| 4108 | + } |
|
| 3911 | 4109 | |
| 3912 | 4110 | echo ' |
| 3913 | 4111 | <ul class="upgrade_settings"> |
@@ -3936,12 +4134,13 @@ discard block |
||
| 3936 | 4134 | <label for="empty_error">', $txt['upgrade_empty_errlog'], '</label> |
| 3937 | 4135 | </li>'; |
| 3938 | 4136 | |
| 3939 | - if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) |
|
| 3940 | - echo ' |
|
| 4137 | + if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) { |
|
| 4138 | + echo ' |
|
| 3941 | 4139 | <li> |
| 3942 | 4140 | <input type="checkbox" name="delete_karma" id="delete_karma" value="1"> |
| 3943 | 4141 | <label for="delete_karma">', $txt['upgrade_delete_karma'], '</label> |
| 3944 | 4142 | </li>'; |
| 4143 | + } |
|
| 3945 | 4144 | |
| 3946 | 4145 | echo ' |
| 3947 | 4146 | <li> |
@@ -3975,10 +4174,11 @@ discard block |
||
| 3975 | 4174 | </div>'; |
| 3976 | 4175 | |
| 3977 | 4176 | // Dont any tables so far? |
| 3978 | - if (!empty($upcontext['previous_tables'])) |
|
| 3979 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4177 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4178 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 3980 | 4179 | echo ' |
| 3981 | 4180 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4181 | + } |
|
| 3982 | 4182 | |
| 3983 | 4183 | echo ' |
| 3984 | 4184 | <h3 id="current_tab"> |
@@ -4017,12 +4217,13 @@ discard block |
||
| 4017 | 4217 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4018 | 4218 | |
| 4019 | 4219 | // If debug flood the screen. |
| 4020 | - if ($is_debug) |
|
| 4021 | - echo ' |
|
| 4220 | + if ($is_debug) { |
|
| 4221 | + echo ' |
|
| 4022 | 4222 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4023 | 4223 | |
| 4024 | 4224 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4025 | 4225 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4226 | + } |
|
| 4026 | 4227 | |
| 4027 | 4228 | echo ' |
| 4028 | 4229 | // Get the next update... |
@@ -4055,8 +4256,9 @@ discard block |
||
| 4055 | 4256 | { |
| 4056 | 4257 | global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt; |
| 4057 | 4258 | |
| 4058 | - if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) |
|
| 4059 | - $is_debug = true; |
|
| 4259 | + if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) { |
|
| 4260 | + $is_debug = true; |
|
| 4261 | + } |
|
| 4060 | 4262 | |
| 4061 | 4263 | echo ' |
| 4062 | 4264 | <h3>', $txt['upgrade_db_changes'], '</h3> |
@@ -4071,8 +4273,9 @@ discard block |
||
| 4071 | 4273 | { |
| 4072 | 4274 | foreach ($upcontext['actioned_items'] as $num => $item) |
| 4073 | 4275 | { |
| 4074 | - if ($num != 0) |
|
| 4075 | - echo ' Successful!'; |
|
| 4276 | + if ($num != 0) { |
|
| 4277 | + echo ' Successful!'; |
|
| 4278 | + } |
|
| 4076 | 4279 | echo '<br>' . $item; |
| 4077 | 4280 | } |
| 4078 | 4281 | |
@@ -4087,20 +4290,20 @@ discard block |
||
| 4087 | 4290 | $seconds = intval($active % 60); |
| 4088 | 4291 | |
| 4089 | 4292 | echo '', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '<br>'; |
| 4293 | + } else { |
|
| 4294 | + echo '', $txt['upgrade_success'], '<br>'; |
|
| 4090 | 4295 | } |
| 4091 | - else |
|
| 4092 | - echo '', $txt['upgrade_success'], '<br>'; |
|
| 4093 | 4296 | |
| 4094 | 4297 | echo ' |
| 4095 | 4298 | <p id="commess">', $txt['upgrade_db_complete'], '</p>'; |
| 4096 | 4299 | } |
| 4097 | - } |
|
| 4098 | - else |
|
| 4300 | + } else |
|
| 4099 | 4301 | { |
| 4100 | 4302 | // Tell them how many files we have in total. |
| 4101 | - if ($upcontext['file_count'] > 1) |
|
| 4102 | - echo ' |
|
| 4303 | + if ($upcontext['file_count'] > 1) { |
|
| 4304 | + echo ' |
|
| 4103 | 4305 | <strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>'; |
| 4306 | + } |
|
| 4104 | 4307 | |
| 4105 | 4308 | echo ' |
| 4106 | 4309 | <h3 id="info2"> |
@@ -4120,10 +4323,10 @@ discard block |
||
| 4120 | 4323 | |
| 4121 | 4324 | echo ' |
| 4122 | 4325 | <p id="upgradeCompleted">', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '</p>'; |
| 4123 | - } |
|
| 4124 | - else |
|
| 4125 | - echo ' |
|
| 4326 | + } else { |
|
| 4327 | + echo ' |
|
| 4126 | 4328 | <p id="upgradeCompleted"></p>'; |
| 4329 | + } |
|
| 4127 | 4330 | |
| 4128 | 4331 | echo ' |
| 4129 | 4332 | <div id="debug_section"> |
@@ -4159,9 +4362,10 @@ discard block |
||
| 4159 | 4362 | var getData = ""; |
| 4160 | 4363 | var debugItems = ', $upcontext['debug_items'], ';'; |
| 4161 | 4364 | |
| 4162 | - if ($is_debug) |
|
| 4163 | - echo ' |
|
| 4365 | + if ($is_debug) { |
|
| 4366 | + echo ' |
|
| 4164 | 4367 | var upgradeStartTime = ' . $upcontext['started'] . ';'; |
| 4368 | + } |
|
| 4165 | 4369 | |
| 4166 | 4370 | echo ' |
| 4167 | 4371 | function getNextItem() |
@@ -4201,9 +4405,10 @@ discard block |
||
| 4201 | 4405 | document.getElementById("error_block").style.display = ""; |
| 4202 | 4406 | setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));'; |
| 4203 | 4407 | |
| 4204 | - if ($is_debug) |
|
| 4205 | - echo ' |
|
| 4408 | + if ($is_debug) { |
|
| 4409 | + echo ' |
|
| 4206 | 4410 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4411 | + } |
|
| 4207 | 4412 | |
| 4208 | 4413 | echo ' |
| 4209 | 4414 | } |
@@ -4224,9 +4429,10 @@ discard block |
||
| 4224 | 4429 | document.getElementById("error_block").style.display = ""; |
| 4225 | 4430 | setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);'; |
| 4226 | 4431 | |
| 4227 | - if ($is_debug) |
|
| 4228 | - echo ' |
|
| 4432 | + if ($is_debug) { |
|
| 4433 | + echo ' |
|
| 4229 | 4434 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');'; |
| 4435 | + } |
|
| 4230 | 4436 | |
| 4231 | 4437 | echo ' |
| 4232 | 4438 | } |
@@ -4284,8 +4490,8 @@ discard block |
||
| 4284 | 4490 | {'; |
| 4285 | 4491 | |
| 4286 | 4492 | // Database Changes, tell us how much time we spen to do this. If this gets updated via JS. |
| 4287 | - if ($is_debug) |
|
| 4288 | - echo ' |
|
| 4493 | + if ($is_debug) { |
|
| 4494 | + echo ' |
|
| 4289 | 4495 | document.getElementById(\'debug_section\').style.display = "none"; |
| 4290 | 4496 | |
| 4291 | 4497 | var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue); |
@@ -4300,6 +4506,7 @@ discard block |
||
| 4300 | 4506 | completedTxt = completedTxt.replace("%1$d", diffSeconds).replace("%2$d", diffMinutes).replace("%3$d", diffHours); |
| 4301 | 4507 | console.log(completedTxt, upgradeFinishedTime, diffTime, diffHours, diffMinutes, diffSeconds); |
| 4302 | 4508 | setInnerHTML(document.getElementById("upgradeCompleted"), completedTxt);'; |
| 4509 | + } |
|
| 4303 | 4510 | |
| 4304 | 4511 | echo ' |
| 4305 | 4512 | |
@@ -4307,9 +4514,10 @@ discard block |
||
| 4307 | 4514 | document.getElementById(\'contbutt\').disabled = 0; |
| 4308 | 4515 | document.getElementById(\'database_done\').value = 1;'; |
| 4309 | 4516 | |
| 4310 | - if ($upcontext['file_count'] > 1) |
|
| 4311 | - echo ' |
|
| 4517 | + if ($upcontext['file_count'] > 1) { |
|
| 4518 | + echo ' |
|
| 4312 | 4519 | document.getElementById(\'info1\').style.display = "none";'; |
| 4520 | + } |
|
| 4313 | 4521 | |
| 4314 | 4522 | echo ' |
| 4315 | 4523 | document.getElementById(\'info2\').style.display = "none"; |
@@ -4322,9 +4530,10 @@ discard block |
||
| 4322 | 4530 | lastItem = 0; |
| 4323 | 4531 | prevFile = curFile;'; |
| 4324 | 4532 | |
| 4325 | - if ($is_debug) |
|
| 4326 | - echo ' |
|
| 4533 | + if ($is_debug) { |
|
| 4534 | + echo ' |
|
| 4327 | 4535 | setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');'; |
| 4536 | + } |
|
| 4328 | 4537 | |
| 4329 | 4538 | echo ' |
| 4330 | 4539 | getNextItem(); |
@@ -4332,8 +4541,8 @@ discard block |
||
| 4332 | 4541 | }'; |
| 4333 | 4542 | |
| 4334 | 4543 | // If debug scroll the screen. |
| 4335 | - if ($is_debug) |
|
| 4336 | - echo ' |
|
| 4544 | + if ($is_debug) { |
|
| 4545 | + echo ' |
|
| 4337 | 4546 | if (iLastSubStepProgress == -1) |
| 4338 | 4547 | { |
| 4339 | 4548 | // Give it consistent dots. |
@@ -4352,6 +4561,7 @@ discard block |
||
| 4352 | 4561 | |
| 4353 | 4562 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4354 | 4563 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4564 | + } |
|
| 4355 | 4565 | |
| 4356 | 4566 | echo ' |
| 4357 | 4567 | // Update the page. |
@@ -4412,9 +4622,10 @@ discard block |
||
| 4412 | 4622 | }'; |
| 4413 | 4623 | |
| 4414 | 4624 | // Start things off assuming we've not errored. |
| 4415 | - if (empty($upcontext['error_message'])) |
|
| 4416 | - echo ' |
|
| 4625 | + if (empty($upcontext['error_message'])) { |
|
| 4626 | + echo ' |
|
| 4417 | 4627 | getNextItem();'; |
| 4628 | + } |
|
| 4418 | 4629 | |
| 4419 | 4630 | echo ' |
| 4420 | 4631 | //# sourceURL=dynamicScript-dbch.js |
@@ -4432,18 +4643,21 @@ discard block |
||
| 4432 | 4643 | <item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item> |
| 4433 | 4644 | <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>'; |
| 4434 | 4645 | |
| 4435 | - if (!empty($upcontext['error_message'])) |
|
| 4436 | - echo ' |
|
| 4646 | + if (!empty($upcontext['error_message'])) { |
|
| 4647 | + echo ' |
|
| 4437 | 4648 | <error>', $upcontext['error_message'], '</error>'; |
| 4649 | + } |
|
| 4438 | 4650 | |
| 4439 | - if (!empty($upcontext['error_string'])) |
|
| 4440 | - echo ' |
|
| 4651 | + if (!empty($upcontext['error_string'])) { |
|
| 4652 | + echo ' |
|
| 4441 | 4653 | <sql>', $upcontext['error_string'], '</sql>'; |
| 4654 | + } |
|
| 4442 | 4655 | |
| 4443 | - if ($is_debug) |
|
| 4444 | - echo ' |
|
| 4656 | + if ($is_debug) { |
|
| 4657 | + echo ' |
|
| 4445 | 4658 | <curtime>', time(), '</curtime>'; |
| 4446 | -} |
|
| 4659 | + } |
|
| 4660 | + } |
|
| 4447 | 4661 | |
| 4448 | 4662 | // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications.... |
| 4449 | 4663 | function template_convert_utf8() |
@@ -4460,10 +4674,11 @@ discard block |
||
| 4460 | 4674 | </div>'; |
| 4461 | 4675 | |
| 4462 | 4676 | // Done any tables so far? |
| 4463 | - if (!empty($upcontext['previous_tables'])) |
|
| 4464 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4677 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4678 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4465 | 4679 | echo ' |
| 4466 | 4680 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4681 | + } |
|
| 4467 | 4682 | |
| 4468 | 4683 | echo ' |
| 4469 | 4684 | <h3 id="current_tab"> |
@@ -4471,9 +4686,10 @@ discard block |
||
| 4471 | 4686 | </h3>'; |
| 4472 | 4687 | |
| 4473 | 4688 | // If we dropped their index, let's let them know |
| 4474 | - if ($upcontext['dropping_index']) |
|
| 4475 | - echo ' |
|
| 4689 | + if ($upcontext['dropping_index']) { |
|
| 4690 | + echo ' |
|
| 4476 | 4691 | <p id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</p>'; |
| 4692 | + } |
|
| 4477 | 4693 | |
| 4478 | 4694 | // Completion notification |
| 4479 | 4695 | echo ' |
@@ -4510,12 +4726,13 @@ discard block |
||
| 4510 | 4726 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4511 | 4727 | |
| 4512 | 4728 | // If debug flood the screen. |
| 4513 | - if ($is_debug) |
|
| 4514 | - echo ' |
|
| 4729 | + if ($is_debug) { |
|
| 4730 | + echo ' |
|
| 4515 | 4731 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4516 | 4732 | |
| 4517 | 4733 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4518 | 4734 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4735 | + } |
|
| 4519 | 4736 | |
| 4520 | 4737 | echo ' |
| 4521 | 4738 | // Get the next update... |
@@ -4561,10 +4778,11 @@ discard block |
||
| 4561 | 4778 | </div>'; |
| 4562 | 4779 | |
| 4563 | 4780 | // Dont any tables so far? |
| 4564 | - if (!empty($upcontext['previous_tables'])) |
|
| 4565 | - foreach ($upcontext['previous_tables'] as $table) |
|
| 4781 | + if (!empty($upcontext['previous_tables'])) { |
|
| 4782 | + foreach ($upcontext['previous_tables'] as $table) |
|
| 4566 | 4783 | echo ' |
| 4567 | 4784 | <br>', $txt['upgrade_completed_table'], ' "', $table, '".'; |
| 4785 | + } |
|
| 4568 | 4786 | |
| 4569 | 4787 | echo ' |
| 4570 | 4788 | <h3 id="current_tab"> |
@@ -4573,9 +4791,10 @@ discard block |
||
| 4573 | 4791 | <p id="commess" style="display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</p>'; |
| 4574 | 4792 | |
| 4575 | 4793 | // Try to make sure substep was reset. |
| 4576 | - if ($upcontext['cur_table_num'] == $upcontext['table_count']) |
|
| 4577 | - echo ' |
|
| 4794 | + if ($upcontext['cur_table_num'] == $upcontext['table_count']) { |
|
| 4795 | + echo ' |
|
| 4578 | 4796 | <input type="hidden" name="substep" id="substep" value="0">'; |
| 4797 | + } |
|
| 4579 | 4798 | |
| 4580 | 4799 | // Continue please! |
| 4581 | 4800 | $upcontext['continue'] = $support_js ? 2 : 1; |
@@ -4608,12 +4827,13 @@ discard block |
||
| 4608 | 4827 | updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');'; |
| 4609 | 4828 | |
| 4610 | 4829 | // If debug flood the screen. |
| 4611 | - if ($is_debug) |
|
| 4612 | - echo ' |
|
| 4830 | + if ($is_debug) { |
|
| 4831 | + echo ' |
|
| 4613 | 4832 | setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' "\' + sCompletedTableName + \'".<span id="debuginfo"><\' + \'/span>\'); |
| 4614 | 4833 | |
| 4615 | 4834 | if (document.getElementById(\'debug_section\').scrollHeight) |
| 4616 | 4835 | document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight'; |
| 4836 | + } |
|
| 4617 | 4837 | |
| 4618 | 4838 | echo ' |
| 4619 | 4839 | // Get the next update... |
@@ -4649,8 +4869,8 @@ discard block |
||
| 4649 | 4869 | <h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>. ', $txt['upgrade_done3'], '</h3> |
| 4650 | 4870 | <form action="', $boardurl, '/index.php">'; |
| 4651 | 4871 | |
| 4652 | - if (!empty($upcontext['can_delete_script'])) |
|
| 4653 | - echo ' |
|
| 4872 | + if (!empty($upcontext['can_delete_script'])) { |
|
| 4873 | + echo ' |
|
| 4654 | 4874 | <label> |
| 4655 | 4875 | <input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], ' |
| 4656 | 4876 | </label> |
@@ -4664,6 +4884,7 @@ discard block |
||
| 4664 | 4884 | } |
| 4665 | 4885 | </script> |
| 4666 | 4886 | <img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>'; |
| 4887 | + } |
|
| 4667 | 4888 | |
| 4668 | 4889 | // Show Upgrade time in debug mode when we completed the upgrade process totatly |
| 4669 | 4890 | if ($is_debug) |
@@ -4673,12 +4894,13 @@ discard block |
||
| 4673 | 4894 | $minutes = intval(($active / 60) % 60); |
| 4674 | 4895 | $seconds = intval($active % 60); |
| 4675 | 4896 | |
| 4676 | - if ($hours > 0) |
|
| 4677 | - echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
| 4678 | - elseif ($minutes > 0) |
|
| 4679 | - echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
| 4680 | - elseif ($seconds > 0) |
|
| 4681 | - echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
| 4897 | + if ($hours > 0) { |
|
| 4898 | + echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), ''; |
|
| 4899 | + } elseif ($minutes > 0) { |
|
| 4900 | + echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), ''; |
|
| 4901 | + } elseif ($seconds > 0) { |
|
| 4902 | + echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), ''; |
|
| 4903 | + } |
|
| 4682 | 4904 | } |
| 4683 | 4905 | |
| 4684 | 4906 | echo ' |
@@ -4708,8 +4930,9 @@ discard block |
||
| 4708 | 4930 | |
| 4709 | 4931 | $current_substep = $_GET['substep']; |
| 4710 | 4932 | |
| 4711 | - if (empty($_GET['a'])) |
|
| 4712 | - $_GET['a'] = 0; |
|
| 4933 | + if (empty($_GET['a'])) { |
|
| 4934 | + $_GET['a'] = 0; |
|
| 4935 | + } |
|
| 4713 | 4936 | $step_progress['name'] = 'Converting ips'; |
| 4714 | 4937 | $step_progress['current'] = $_GET['a']; |
| 4715 | 4938 | |
@@ -4752,16 +4975,19 @@ discard block |
||
| 4752 | 4975 | 'empty' => '', |
| 4753 | 4976 | 'limit' => $limit, |
| 4754 | 4977 | )); |
| 4755 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4756 | - $arIp[] = $row[$oldCol]; |
|
| 4978 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4979 | + $arIp[] = $row[$oldCol]; |
|
| 4980 | + } |
|
| 4757 | 4981 | $smcFunc['db_free_result']($request); |
| 4758 | 4982 | |
| 4759 | 4983 | // Special case, null ip could keep us in a loop. |
| 4760 | - if (is_null($arIp[0])) |
|
| 4761 | - unset($arIp[0]); |
|
| 4984 | + if (is_null($arIp[0])) { |
|
| 4985 | + unset($arIp[0]); |
|
| 4986 | + } |
|
| 4762 | 4987 | |
| 4763 | - if (empty($arIp)) |
|
| 4764 | - $is_done = true; |
|
| 4988 | + if (empty($arIp)) { |
|
| 4989 | + $is_done = true; |
|
| 4990 | + } |
|
| 4765 | 4991 | |
| 4766 | 4992 | $updates = array(); |
| 4767 | 4993 | $cases = array(); |
@@ -4770,16 +4996,18 @@ discard block |
||
| 4770 | 4996 | { |
| 4771 | 4997 | $arIp[$i] = trim($arIp[$i]); |
| 4772 | 4998 | |
| 4773 | - if (empty($arIp[$i])) |
|
| 4774 | - continue; |
|
| 4999 | + if (empty($arIp[$i])) { |
|
| 5000 | + continue; |
|
| 5001 | + } |
|
| 4775 | 5002 | |
| 4776 | 5003 | $updates['ip' . $i] = $arIp[$i]; |
| 4777 | 5004 | $cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}'; |
| 4778 | 5005 | |
| 4779 | 5006 | if ($setSize > 0 && $i % $setSize === 0) |
| 4780 | 5007 | { |
| 4781 | - if (count($updates) == 1) |
|
| 4782 | - continue; |
|
| 5008 | + if (count($updates) == 1) { |
|
| 5009 | + continue; |
|
| 5010 | + } |
|
| 4783 | 5011 | |
| 4784 | 5012 | $updates['whereSet'] = array_values($updates); |
| 4785 | 5013 | $smcFunc['db_query']('', ' |
@@ -4813,8 +5041,7 @@ discard block |
||
| 4813 | 5041 | 'ip' => $ip |
| 4814 | 5042 | )); |
| 4815 | 5043 | } |
| 4816 | - } |
|
| 4817 | - else |
|
| 5044 | + } else |
|
| 4818 | 5045 | { |
| 4819 | 5046 | $updates['whereSet'] = array_values($updates); |
| 4820 | 5047 | $smcFunc['db_query']('', ' |
@@ -4828,9 +5055,9 @@ discard block |
||
| 4828 | 5055 | $updates |
| 4829 | 5056 | ); |
| 4830 | 5057 | } |
| 5058 | + } else { |
|
| 5059 | + $is_done = true; |
|
| 4831 | 5060 | } |
| 4832 | - else |
|
| 4833 | - $is_done = true; |
|
| 4834 | 5061 | |
| 4835 | 5062 | $_GET['a'] += $limit; |
| 4836 | 5063 | $step_progress['current'] = $_GET['a']; |
@@ -4856,10 +5083,11 @@ discard block |
||
| 4856 | 5083 | |
| 4857 | 5084 | $columns = $smcFunc['db_list_columns']($targetTable, true); |
| 4858 | 5085 | |
| 4859 | - if (isset($columns[$column])) |
|
| 4860 | - return $columns[$column]; |
|
| 4861 | - else |
|
| 4862 | - return null; |
|
| 4863 | -} |
|
| 5086 | + if (isset($columns[$column])) { |
|
| 5087 | + return $columns[$column]; |
|
| 5088 | + } else { |
|
| 5089 | + return null; |
|
| 5090 | + } |
|
| 5091 | + } |
|
| 4864 | 5092 | |
| 4865 | 5093 | ?> |
| 4866 | 5094 | \ 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); |
@@ -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 | /** |
@@ -294,9 +299,9 @@ discard block |
||
| 294 | 299 | $keys = array_merge(array_keys($this->default_options), array_keys($this->user_options)); |
| 295 | 300 | $vals = array_merge($this->default_options, $this->user_options); |
| 296 | 301 | $this->options = array_combine($keys, $vals); |
| 302 | + } else { |
|
| 303 | + $this->options = $this->default_options; |
|
| 297 | 304 | } |
| 298 | - else |
|
| 299 | - $this->options = $this->default_options; |
|
| 300 | 305 | |
| 301 | 306 | // POST data options, here we don't allow any overide |
| 302 | 307 | if (isset($this->post_data)) |
@@ -335,8 +340,9 @@ discard block |
||
| 335 | 340 | $temp = explode(': ', $_header, 2); |
| 336 | 341 | |
| 337 | 342 | // set proper headers only |
| 338 | - if (isset($temp[0]) && isset($temp[1])) |
|
| 339 | - $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 343 | + if (isset($temp[0]) && isset($temp[1])) { |
|
| 344 | + $this->headers[strtolower($temp[0])] = strtolower(trim($temp[1])); |
|
| 345 | + } |
|
| 340 | 346 | |
| 341 | 347 | // return the length of what was passed unless you want a Failed writing header error ;) |
| 342 | 348 | return strlen($header); |
@@ -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($smcFunc['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 | } |
@@ -559,8 +588,9 @@ discard block |
||
| 559 | 588 | 'gender', |
| 560 | 589 | 'blurb', |
| 561 | 590 | ); |
| 562 | - if ($xml_format != 'atom') |
|
| 563 | - $keysToCdata[] = 'category'; |
|
| 591 | + if ($xml_format != 'atom') { |
|
| 592 | + $keysToCdata[] = 'category'; |
|
| 593 | + } |
|
| 564 | 594 | |
| 565 | 595 | if (!empty($forceCdataKeys)) |
| 566 | 596 | { |
@@ -577,8 +607,9 @@ discard block |
||
| 577 | 607 | $attrs = isset($element['attributes']) ? $element['attributes'] : null; |
| 578 | 608 | |
| 579 | 609 | // Skip it, it's been set to null. |
| 580 | - if ($key === null || ($val === null && $attrs === null)) |
|
| 581 | - continue; |
|
| 610 | + if ($key === null || ($val === null && $attrs === null)) { |
|
| 611 | + continue; |
|
| 612 | + } |
|
| 582 | 613 | |
| 583 | 614 | $forceCdata = in_array($key, $forceCdataKeys); |
| 584 | 615 | $ns = !empty($nsKeys[$key]) ? $nsKeys[$key] : ''; |
@@ -591,16 +622,16 @@ discard block |
||
| 591 | 622 | |
| 592 | 623 | if (!empty($attrs)) |
| 593 | 624 | { |
| 594 | - foreach ($attrs as $attr_key => $attr_value) |
|
| 595 | - echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
| 625 | + foreach ($attrs as $attr_key => $attr_value) { |
|
| 626 | + echo ' ', $attr_key, '="', fix_possible_url($attr_value), '"'; |
|
| 627 | + } |
|
| 596 | 628 | } |
| 597 | 629 | |
| 598 | 630 | // If it's empty, simply output an empty element. |
| 599 | 631 | if (empty($val)) |
| 600 | 632 | { |
| 601 | 633 | echo ' />'; |
| 602 | - } |
|
| 603 | - else |
|
| 634 | + } else |
|
| 604 | 635 | { |
| 605 | 636 | echo '>'; |
| 606 | 637 | |
@@ -612,11 +643,13 @@ discard block |
||
| 612 | 643 | echo "\n", str_repeat("\t", $i); |
| 613 | 644 | } |
| 614 | 645 | // A string with returns in it.... show this as a multiline element. |
| 615 | - elseif (strpos($val, "\n") !== false) |
|
| 616 | - echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
| 646 | + elseif (strpos($val, "\n") !== false) { |
|
| 647 | + echo "\n", in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val), "\n", str_repeat("\t", $i); |
|
| 648 | + } |
|
| 617 | 649 | // A simple string. |
| 618 | - else |
|
| 619 | - echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
| 650 | + else { |
|
| 651 | + echo in_array($key, $keysToCdata) ? cdata_parse(fix_possible_url($val), $ns, $forceCdata) : fix_possible_url($val); |
|
| 652 | + } |
|
| 620 | 653 | |
| 621 | 654 | // Ending tag. |
| 622 | 655 | echo '</', $key, '>'; |
@@ -636,8 +669,9 @@ discard block |
||
| 636 | 669 | { |
| 637 | 670 | global $scripturl, $smcFunc; |
| 638 | 671 | |
| 639 | - if (!allowedTo('view_mlist')) |
|
| 640 | - return array(); |
|
| 672 | + if (!allowedTo('view_mlist')) { |
|
| 673 | + return array(); |
|
| 674 | + } |
|
| 641 | 675 | |
| 642 | 676 | // Find the most recent members. |
| 643 | 677 | $request = $smcFunc['db_query']('', ' |
@@ -656,8 +690,8 @@ discard block |
||
| 656 | 690 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['date_registered']) . ':member=' . $row['id_member']; |
| 657 | 691 | |
| 658 | 692 | // Make the data look rss-ish. |
| 659 | - if ($xml_format == 'rss' || $xml_format == 'rss2') |
|
| 660 | - $data[] = array( |
|
| 693 | + if ($xml_format == 'rss' || $xml_format == 'rss2') { |
|
| 694 | + $data[] = array( |
|
| 661 | 695 | 'tag' => 'item', |
| 662 | 696 | 'content' => array( |
| 663 | 697 | array( |
@@ -685,8 +719,8 @@ discard block |
||
| 685 | 719 | ), |
| 686 | 720 | ), |
| 687 | 721 | ); |
| 688 | - elseif ($xml_format == 'rdf') |
|
| 689 | - $data[] = array( |
|
| 722 | + } elseif ($xml_format == 'rdf') { |
|
| 723 | + $data[] = array( |
|
| 690 | 724 | 'tag' => 'item', |
| 691 | 725 | 'attributes' => array('rdf:about' => $scripturl . '?action=profile;u=' . $row['id_member']), |
| 692 | 726 | 'content' => array( |
@@ -704,8 +738,8 @@ discard block |
||
| 704 | 738 | ), |
| 705 | 739 | ), |
| 706 | 740 | ); |
| 707 | - elseif ($xml_format == 'atom') |
|
| 708 | - $data[] = array( |
|
| 741 | + } elseif ($xml_format == 'atom') { |
|
| 742 | + $data[] = array( |
|
| 709 | 743 | 'tag' => 'entry', |
| 710 | 744 | 'content' => array( |
| 711 | 745 | array( |
@@ -734,9 +768,10 @@ discard block |
||
| 734 | 768 | ), |
| 735 | 769 | ), |
| 736 | 770 | ); |
| 771 | + } |
|
| 737 | 772 | // More logical format for the data, but harder to apply. |
| 738 | - else |
|
| 739 | - $data[] = array( |
|
| 773 | + else { |
|
| 774 | + $data[] = array( |
|
| 740 | 775 | 'tag' => 'member', |
| 741 | 776 | 'content' => array( |
| 742 | 777 | array( |
@@ -757,6 +792,7 @@ discard block |
||
| 757 | 792 | ), |
| 758 | 793 | ), |
| 759 | 794 | ); |
| 795 | + } |
|
| 760 | 796 | } |
| 761 | 797 | $smcFunc['db_free_result']($request); |
| 762 | 798 | |
@@ -817,22 +853,24 @@ discard block |
||
| 817 | 853 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
| 818 | 854 | { |
| 819 | 855 | $smcFunc['db_free_result']($request); |
| 820 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
| 821 | - unset($context['optimize_msg']['lowest']); |
|
| 822 | - else |
|
| 823 | - $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
| 856 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
| 857 | + unset($context['optimize_msg']['lowest']); |
|
| 858 | + } else { |
|
| 859 | + $context['optimize_msg']['lowest'] = 'm.id_msg >= t.id_first_msg'; |
|
| 860 | + } |
|
| 824 | 861 | $context['optimize_msg']['highest'] = 'm.id_msg <= t.id_last_msg'; |
| 825 | 862 | $loops++; |
| 863 | + } else { |
|
| 864 | + $done = true; |
|
| 826 | 865 | } |
| 827 | - else |
|
| 828 | - $done = true; |
|
| 829 | 866 | } |
| 830 | 867 | $data = array(); |
| 831 | 868 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 832 | 869 | { |
| 833 | 870 | // Limit the length of the message, if the option is set. |
| 834 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
| 835 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 871 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
| 872 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 873 | + } |
|
| 836 | 874 | |
| 837 | 875 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 838 | 876 | |
@@ -859,8 +897,9 @@ discard block |
||
| 859 | 897 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
| 860 | 898 | { |
| 861 | 899 | // Include approved attachments only |
| 862 | - if ($attach['approved']) |
|
| 863 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 900 | + if ($attach['approved']) { |
|
| 901 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 902 | + } |
|
| 864 | 903 | } |
| 865 | 904 | $smcFunc['db_free_result']($attach_request); |
| 866 | 905 | |
@@ -868,16 +907,17 @@ discard block |
||
| 868 | 907 | if (!empty($loaded_attachments)) |
| 869 | 908 | { |
| 870 | 909 | uasort($loaded_attachments, function($a, $b) { |
| 871 | - if ($a['filesize'] == $b['filesize']) |
|
| 872 | - return 0; |
|
| 910 | + if ($a['filesize'] == $b['filesize']) { |
|
| 911 | + return 0; |
|
| 912 | + } |
|
| 873 | 913 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 874 | 914 | }); |
| 915 | + } else { |
|
| 916 | + $loaded_attachments = null; |
|
| 875 | 917 | } |
| 876 | - else |
|
| 877 | - $loaded_attachments = null; |
|
| 918 | + } else { |
|
| 919 | + $loaded_attachments = null; |
|
| 878 | 920 | } |
| 879 | - else |
|
| 880 | - $loaded_attachments = null; |
|
| 881 | 921 | |
| 882 | 922 | // Create a GUID for this topic using the tag URI scheme |
| 883 | 923 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':topic=' . $row['id_topic']; |
@@ -894,9 +934,9 @@ discard block |
||
| 894 | 934 | 'length' => $attachment['filesize'], |
| 895 | 935 | 'type' => $attachment['mime_type'], |
| 896 | 936 | ); |
| 937 | + } else { |
|
| 938 | + $enclosure = null; |
|
| 897 | 939 | } |
| 898 | - else |
|
| 899 | - $enclosure = null; |
|
| 900 | 940 | |
| 901 | 941 | $data[] = array( |
| 902 | 942 | 'tag' => 'item', |
@@ -942,8 +982,7 @@ discard block |
||
| 942 | 982 | ), |
| 943 | 983 | ), |
| 944 | 984 | ); |
| 945 | - } |
|
| 946 | - elseif ($xml_format == 'rdf') |
|
| 985 | + } elseif ($xml_format == 'rdf') |
|
| 947 | 986 | { |
| 948 | 987 | $data[] = array( |
| 949 | 988 | 'tag' => 'item', |
@@ -967,8 +1006,7 @@ discard block |
||
| 967 | 1006 | ), |
| 968 | 1007 | ), |
| 969 | 1008 | ); |
| 970 | - } |
|
| 971 | - elseif ($xml_format == 'atom') |
|
| 1009 | + } elseif ($xml_format == 'atom') |
|
| 972 | 1010 | { |
| 973 | 1011 | // Only one attachment allowed |
| 974 | 1012 | if (!empty($loaded_attachments)) |
@@ -980,9 +1018,9 @@ discard block |
||
| 980 | 1018 | 'length' => $attachment['filesize'], |
| 981 | 1019 | 'type' => $attachment['mime_type'], |
| 982 | 1020 | ); |
| 1021 | + } else { |
|
| 1022 | + $enclosure = null; |
|
| 983 | 1023 | } |
| 984 | - else |
|
| 985 | - $enclosure = null; |
|
| 986 | 1024 | |
| 987 | 1025 | $data[] = array( |
| 988 | 1026 | 'tag' => 'entry', |
@@ -1082,9 +1120,9 @@ discard block |
||
| 1082 | 1120 | ) |
| 1083 | 1121 | ); |
| 1084 | 1122 | } |
| 1123 | + } else { |
|
| 1124 | + $attachments = null; |
|
| 1085 | 1125 | } |
| 1086 | - else |
|
| 1087 | - $attachments = null; |
|
| 1088 | 1126 | |
| 1089 | 1127 | $data[] = array( |
| 1090 | 1128 | 'tag' => 'article', |
@@ -1202,22 +1240,25 @@ discard block |
||
| 1202 | 1240 | if ($loops < 2 && $smcFunc['db_num_rows']($request) < $_GET['limit']) |
| 1203 | 1241 | { |
| 1204 | 1242 | $smcFunc['db_free_result']($request); |
| 1205 | - if (empty($_REQUEST['boards']) && empty($board)) |
|
| 1206 | - unset($context['optimize_msg']['lowest']); |
|
| 1207 | - else |
|
| 1208 | - $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
| 1243 | + if (empty($_REQUEST['boards']) && empty($board)) { |
|
| 1244 | + unset($context['optimize_msg']['lowest']); |
|
| 1245 | + } else { |
|
| 1246 | + $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; |
|
| 1247 | + } |
|
| 1209 | 1248 | $loops++; |
| 1249 | + } else { |
|
| 1250 | + $done = true; |
|
| 1210 | 1251 | } |
| 1211 | - else |
|
| 1212 | - $done = true; |
|
| 1213 | 1252 | } |
| 1214 | 1253 | $messages = array(); |
| 1215 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1216 | - $messages[] = $row['id_msg']; |
|
| 1254 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1255 | + $messages[] = $row['id_msg']; |
|
| 1256 | + } |
|
| 1217 | 1257 | $smcFunc['db_free_result']($request); |
| 1218 | 1258 | |
| 1219 | - if (empty($messages)) |
|
| 1220 | - return array(); |
|
| 1259 | + if (empty($messages)) { |
|
| 1260 | + return array(); |
|
| 1261 | + } |
|
| 1221 | 1262 | |
| 1222 | 1263 | // Find the most recent posts this user can see. |
| 1223 | 1264 | $request = $smcFunc['db_query']('', ' |
@@ -1247,8 +1288,9 @@ discard block |
||
| 1247 | 1288 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1248 | 1289 | { |
| 1249 | 1290 | // Limit the length of the message, if the option is set. |
| 1250 | - if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) |
|
| 1251 | - $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 1291 | + if (!empty($modSettings['xmlnews_maxlen']) && $smcFunc['strlen'](str_replace('<br>', "\n", $row['body'])) > $modSettings['xmlnews_maxlen']) { |
|
| 1292 | + $row['body'] = strtr($smcFunc['substr'](str_replace('<br>', "\n", $row['body']), 0, $modSettings['xmlnews_maxlen'] - 3), array("\n" => '<br>')) . '...'; |
|
| 1293 | + } |
|
| 1252 | 1294 | |
| 1253 | 1295 | $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']); |
| 1254 | 1296 | |
@@ -1275,8 +1317,9 @@ discard block |
||
| 1275 | 1317 | while ($attach = $smcFunc['db_fetch_assoc']($attach_request)) |
| 1276 | 1318 | { |
| 1277 | 1319 | // Include approved attachments only |
| 1278 | - if ($attach['approved']) |
|
| 1279 | - $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 1320 | + if ($attach['approved']) { |
|
| 1321 | + $loaded_attachments['attachment_' . $attach['id_attach']] = $attach; |
|
| 1322 | + } |
|
| 1280 | 1323 | } |
| 1281 | 1324 | $smcFunc['db_free_result']($attach_request); |
| 1282 | 1325 | |
@@ -1284,16 +1327,17 @@ discard block |
||
| 1284 | 1327 | if (!empty($loaded_attachments)) |
| 1285 | 1328 | { |
| 1286 | 1329 | uasort($loaded_attachments, function($a, $b) { |
| 1287 | - if ($a['filesize'] == $b['filesize']) |
|
| 1288 | - return 0; |
|
| 1330 | + if ($a['filesize'] == $b['filesize']) { |
|
| 1331 | + return 0; |
|
| 1332 | + } |
|
| 1289 | 1333 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
| 1290 | 1334 | }); |
| 1335 | + } else { |
|
| 1336 | + $loaded_attachments = null; |
|
| 1291 | 1337 | } |
| 1292 | - else |
|
| 1293 | - $loaded_attachments = null; |
|
| 1338 | + } else { |
|
| 1339 | + $loaded_attachments = null; |
|
| 1294 | 1340 | } |
| 1295 | - else |
|
| 1296 | - $loaded_attachments = null; |
|
| 1297 | 1341 | |
| 1298 | 1342 | // Create a GUID for this post using the tag URI scheme |
| 1299 | 1343 | $guid = 'tag:' . parse_url($scripturl, PHP_URL_HOST) . ',' . gmdate('Y-m-d', $row['poster_time']) . ':msg=' . $row['id_msg']; |
@@ -1310,9 +1354,9 @@ discard block |
||
| 1310 | 1354 | 'length' => $attachment['filesize'], |
| 1311 | 1355 | 'type' => $attachment['mime_type'], |
| 1312 | 1356 | ); |
| 1357 | + } else { |
|
| 1358 | + $enclosure = null; |
|
| 1313 | 1359 | } |
| 1314 | - else |
|
| 1315 | - $enclosure = null; |
|
| 1316 | 1360 | |
| 1317 | 1361 | $data[] = array( |
| 1318 | 1362 | 'tag' => 'item', |
@@ -1358,8 +1402,7 @@ discard block |
||
| 1358 | 1402 | ), |
| 1359 | 1403 | ), |
| 1360 | 1404 | ); |
| 1361 | - } |
|
| 1362 | - elseif ($xml_format == 'rdf') |
|
| 1405 | + } elseif ($xml_format == 'rdf') |
|
| 1363 | 1406 | { |
| 1364 | 1407 | $data[] = array( |
| 1365 | 1408 | 'tag' => 'item', |
@@ -1383,8 +1426,7 @@ discard block |
||
| 1383 | 1426 | ), |
| 1384 | 1427 | ), |
| 1385 | 1428 | ); |
| 1386 | - } |
|
| 1387 | - elseif ($xml_format == 'atom') |
|
| 1429 | + } elseif ($xml_format == 'atom') |
|
| 1388 | 1430 | { |
| 1389 | 1431 | // Only one attachment allowed |
| 1390 | 1432 | if (!empty($loaded_attachments)) |
@@ -1396,9 +1438,9 @@ discard block |
||
| 1396 | 1438 | 'length' => $attachment['filesize'], |
| 1397 | 1439 | 'type' => $attachment['mime_type'], |
| 1398 | 1440 | ); |
| 1441 | + } else { |
|
| 1442 | + $enclosure = null; |
|
| 1399 | 1443 | } |
| 1400 | - else |
|
| 1401 | - $enclosure = null; |
|
| 1402 | 1444 | |
| 1403 | 1445 | $data[] = array( |
| 1404 | 1446 | 'tag' => 'entry', |
@@ -1498,9 +1540,9 @@ discard block |
||
| 1498 | 1540 | ) |
| 1499 | 1541 | ); |
| 1500 | 1542 | } |
| 1543 | + } else { |
|
| 1544 | + $attachments = null; |
|
| 1501 | 1545 | } |
| 1502 | - else |
|
| 1503 | - $attachments = null; |
|
| 1504 | 1546 | |
| 1505 | 1547 | $data[] = array( |
| 1506 | 1548 | 'tag' => 'recent-post', |
@@ -1619,14 +1661,16 @@ discard block |
||
| 1619 | 1661 | global $scripturl, $memberContext, $user_profile, $user_info; |
| 1620 | 1662 | |
| 1621 | 1663 | // You must input a valid user.... |
| 1622 | - if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) |
|
| 1623 | - return array(); |
|
| 1664 | + if (empty($_GET['u']) || !loadMemberData((int) $_GET['u'])) { |
|
| 1665 | + return array(); |
|
| 1666 | + } |
|
| 1624 | 1667 | |
| 1625 | 1668 | // Make sure the id is a number and not "I like trying to hack the database". |
| 1626 | 1669 | $_GET['u'] = (int) $_GET['u']; |
| 1627 | 1670 | // Load the member's contextual information! |
| 1628 | - if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) |
|
| 1629 | - return array(); |
|
| 1671 | + if (!loadMemberContext($_GET['u']) || !allowedTo('profile_view')) { |
|
| 1672 | + return array(); |
|
| 1673 | + } |
|
| 1630 | 1674 | |
| 1631 | 1675 | // Okay, I admit it, I'm lazy. Stupid $_GET['u'] is long and hard to type. |
| 1632 | 1676 | $profile = &$memberContext[$_GET['u']]; |
@@ -1668,8 +1712,7 @@ discard block |
||
| 1668 | 1712 | ), |
| 1669 | 1713 | ) |
| 1670 | 1714 | ); |
| 1671 | - } |
|
| 1672 | - elseif ($xml_format == 'rdf') |
|
| 1715 | + } elseif ($xml_format == 'rdf') |
|
| 1673 | 1716 | { |
| 1674 | 1717 | $data[] = array( |
| 1675 | 1718 | 'tag' => 'item', |
@@ -1693,8 +1736,7 @@ discard block |
||
| 1693 | 1736 | ), |
| 1694 | 1737 | ) |
| 1695 | 1738 | ); |
| 1696 | - } |
|
| 1697 | - elseif ($xml_format == 'atom') |
|
| 1739 | + } elseif ($xml_format == 'atom') |
|
| 1698 | 1740 | { |
| 1699 | 1741 | $data[] = array( |
| 1700 | 1742 | 'tag' => 'entry', |
@@ -1747,8 +1789,7 @@ discard block |
||
| 1747 | 1789 | ), |
| 1748 | 1790 | ) |
| 1749 | 1791 | ); |
| 1750 | - } |
|
| 1751 | - else |
|
| 1792 | + } else |
|
| 1752 | 1793 | { |
| 1753 | 1794 | $data = array( |
| 1754 | 1795 | array( |
@@ -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'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 216 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 212 | 220 | } |
| 213 | - else |
|
| 214 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 215 | 221 | |
| 216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
| 217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
| 219 | 225 | |
| 220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
| 221 | 227 | { |
| 222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
| 223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
| 229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 230 | + } |
|
| 224 | 231 | } |
| 225 | 232 | |
| 226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
| 336 | 343 | |
| 337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
| 338 | 345 | |
| 339 | - if ($return_config) |
|
| 340 | - return $config_vars; |
|
| 346 | + if ($return_config) { |
|
| 347 | + return $config_vars; |
|
| 348 | + } |
|
| 341 | 349 | |
| 342 | 350 | // We need this file for the settings template. |
| 343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
| 348 | 356 | checkSession(); |
| 349 | 357 | |
| 350 | 358 | // These settings cannot be left empty! |
| 351 | - if (empty($_POST['custom_avatar_dir'])) |
|
| 352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
| 360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 361 | + } |
|
| 353 | 362 | |
| 354 | - if (empty($_POST['custom_avatar_url'])) |
|
| 355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 363 | + if (empty($_POST['custom_avatar_url'])) { |
|
| 364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 365 | + } |
|
| 356 | 366 | |
| 357 | - if (empty($_POST['avatar_directory'])) |
|
| 358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 367 | + if (empty($_POST['avatar_directory'])) { |
|
| 368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 369 | + } |
|
| 359 | 370 | |
| 360 | - if (empty($_POST['avatar_url'])) |
|
| 361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 371 | + if (empty($_POST['avatar_url'])) { |
|
| 372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 373 | + } |
|
| 362 | 374 | |
| 363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
| 364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
| 406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
| 407 | 419 | foreach ($titles as $browse_type => $details) |
| 408 | 420 | { |
| 409 | - if ($browse_type != 'attachments') |
|
| 410 | - $list_title .= ' | '; |
|
| 421 | + if ($browse_type != 'attachments') { |
|
| 422 | + $list_title .= ' | '; |
|
| 423 | + } |
|
| 411 | 424 | |
| 412 | - if ($context['browse_type'] == $browse_type) |
|
| 413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 425 | + if ($context['browse_type'] == $browse_type) { |
|
| 426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 427 | + } |
|
| 414 | 428 | |
| 415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
| 416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
| 446 | 460 | $link = '<a href="'; |
| 447 | 461 | |
| 448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
| 449 | - if ($rowData['attachment_type'] == 1) |
|
| 450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 463 | + if ($rowData['attachment_type'] == 1) { |
|
| 464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 465 | + } |
|
| 451 | 466 | |
| 452 | 467 | // By default avatars are downloaded almost as attachments. |
| 453 | - elseif ($context['browse_type'] == 'avatars') |
|
| 454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 468 | + elseif ($context['browse_type'] == 'avatars') { |
|
| 469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 470 | + } |
|
| 455 | 471 | |
| 456 | 472 | // Normal attachments are always linked to a topic ID. |
| 457 | - else |
|
| 458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 473 | + else { |
|
| 474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 475 | + } |
|
| 459 | 476 | |
| 460 | 477 | $link .= '"'; |
| 461 | 478 | |
| 462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
| 463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 482 | + } |
|
| 465 | 483 | |
| 466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
| 467 | 485 | |
| 468 | 486 | // Show the dimensions. |
| 469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 489 | + } |
|
| 471 | 490 | |
| 472 | 491 | return $link; |
| 473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
| 500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
| 501 | 520 | { |
| 502 | 521 | // In case of an attachment, return the poster of the attachment. |
| 503 | - if (empty($rowData['id_member'])) |
|
| 504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 522 | + if (empty($rowData['id_member'])) { |
|
| 523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 524 | + } |
|
| 505 | 525 | |
| 506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
| 507 | - else |
|
| 508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 527 | + else { |
|
| 528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 529 | + } |
|
| 509 | 530 | }, |
| 510 | 531 | ), |
| 511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
| 524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
| 525 | 546 | |
| 526 | 547 | // Add a link to the topic in case of an attachment. |
| 527 | - if ($context['browse_type'] !== 'avatars') |
|
| 528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 548 | + if ($context['browse_type'] !== 'avatars') { |
|
| 549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 550 | + } |
|
| 529 | 551 | |
| 530 | 552 | return $date; |
| 531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
| 610 | 632 | global $smcFunc, $txt; |
| 611 | 633 | |
| 612 | 634 | // Choose a query depending on what we are viewing. |
| 613 | - if ($browse_type === 'avatars') |
|
| 614 | - $request = $smcFunc['db_query']('', ' |
|
| 635 | + if ($browse_type === 'avatars') { |
|
| 636 | + $request = $smcFunc['db_query']('', ' |
|
| 615 | 637 | SELECT |
| 616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
| 617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
| 630 | 652 | 'per_page' => $items_per_page, |
| 631 | 653 | ) |
| 632 | 654 | ); |
| 633 | - else |
|
| 634 | - $request = $smcFunc['db_query']('', ' |
|
| 655 | + } else { |
|
| 656 | + $request = $smcFunc['db_query']('', ' |
|
| 635 | 657 | SELECT |
| 636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
| 637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
| 650 | 672 | 'per_page' => $items_per_page, |
| 651 | 673 | ) |
| 652 | 674 | ); |
| 675 | + } |
|
| 653 | 676 | $files = array(); |
| 654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 655 | - $files[] = $row; |
|
| 677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 678 | + $files[] = $row; |
|
| 679 | + } |
|
| 656 | 680 | $smcFunc['db_free_result']($request); |
| 657 | 681 | |
| 658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
| 670 | 694 | global $smcFunc; |
| 671 | 695 | |
| 672 | 696 | // Depending on the type of file, different queries are used. |
| 673 | - if ($browse_type === 'avatars') |
|
| 674 | - $request = $smcFunc['db_query']('', ' |
|
| 697 | + if ($browse_type === 'avatars') { |
|
| 698 | + $request = $smcFunc['db_query']('', ' |
|
| 675 | 699 | SELECT COUNT(*) |
| 676 | 700 | FROM {db_prefix}attachments |
| 677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
| 679 | 703 | 'guest_id_member' => 0, |
| 680 | 704 | ) |
| 681 | 705 | ); |
| 682 | - else |
|
| 683 | - $request = $smcFunc['db_query']('', ' |
|
| 706 | + } else { |
|
| 707 | + $request = $smcFunc['db_query']('', ' |
|
| 684 | 708 | SELECT COUNT(*) AS num_attach |
| 685 | 709 | FROM {db_prefix}attachments AS a |
| 686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
| 693 | 717 | 'guest_id_member' => 0, |
| 694 | 718 | ) |
| 695 | 719 | ); |
| 720 | + } |
|
| 696 | 721 | |
| 697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
| 698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
| 775 | 800 | $current_dir_size /= 1024; |
| 776 | 801 | |
| 777 | 802 | // If they specified a limit only.... |
| 778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
| 779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
| 804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 805 | + } |
|
| 780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
| 781 | 807 | |
| 782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
| 783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
| 809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 810 | + } |
|
| 784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
| 785 | 812 | |
| 786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
| 817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
| 818 | 845 | |
| 819 | 846 | // Update the messages to reflect the change. |
| 820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 821 | - $smcFunc['db_query']('', ' |
|
| 847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 848 | + $smcFunc['db_query']('', ' |
|
| 822 | 849 | UPDATE {db_prefix}messages |
| 823 | 850 | SET body = CONCAT(body, {string:notice}) |
| 824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
| 827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
| 828 | 855 | ) |
| 829 | 856 | ); |
| 830 | - } |
|
| 831 | - else |
|
| 857 | + } |
|
| 858 | + } else |
|
| 832 | 859 | { |
| 833 | 860 | // Remove all the old avatars. |
| 834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
| 853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
| 854 | 881 | |
| 855 | 882 | // And make a note on the post. |
| 856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 857 | - $smcFunc['db_query']('', ' |
|
| 883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 884 | + $smcFunc['db_query']('', ' |
|
| 858 | 885 | UPDATE {db_prefix}messages |
| 859 | 886 | SET body = CONCAT(body, {string:notice}) |
| 860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
| 863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
| 864 | 891 | ) |
| 865 | 892 | ); |
| 893 | + } |
|
| 866 | 894 | |
| 867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | $attachments = array(); |
| 884 | 912 | // There must be a quicker way to pass this safety test?? |
| 885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
| 886 | - $attachments[] = (int) $removeID; |
|
| 913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
| 914 | + $attachments[] = (int) $removeID; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
| 889 | 918 | $filesRemoved = false; |
| 890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
| 891 | 920 | |
| 892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
| 893 | - removeAttachments(array('id_attach' => $attachments)); |
|
| 894 | - else if (!empty($attachments)) |
|
| 921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
| 922 | + removeAttachments(array('id_attach' => $attachments)); |
|
| 923 | + } else if (!empty($attachments)) |
|
| 895 | 924 | { |
| 896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
| 897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
| 930 | 959 | |
| 931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
| 932 | 961 | |
| 933 | - if (!isset($_POST['notice'])) |
|
| 934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 962 | + if (!isset($_POST['notice'])) { |
|
| 963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 964 | + } |
|
| 935 | 965 | |
| 936 | 966 | // Add the notice on the end of the changed messages. |
| 937 | - if (!empty($messages)) |
|
| 938 | - $smcFunc['db_query']('', ' |
|
| 967 | + if (!empty($messages)) { |
|
| 968 | + $smcFunc['db_query']('', ' |
|
| 939 | 969 | UPDATE {db_prefix}messages |
| 940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
| 941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
| 944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
| 945 | 975 | ) |
| 946 | 976 | ); |
| 977 | + } |
|
| 947 | 978 | |
| 948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
| 982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
| 983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
| 984 | 1015 | |
| 985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
| 986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 987 | - elseif ($type == 'attachment_type') |
|
| 988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 989 | - elseif ($type == 'poster_time') |
|
| 990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 991 | - elseif ($type == 'last_login') |
|
| 992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 993 | - elseif ($type == 'size') |
|
| 994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 995 | - elseif ($type == 'id_topic') |
|
| 996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
| 1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1018 | + } elseif ($type == 'attachment_type') { |
|
| 1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 1020 | + } elseif ($type == 'poster_time') { |
|
| 1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 1022 | + } elseif ($type == 'last_login') { |
|
| 1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 1024 | + } elseif ($type == 'size') { |
|
| 1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 1026 | + } elseif ($type == 'id_topic') { |
|
| 1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1028 | + } |
|
| 997 | 1029 | |
| 998 | 1030 | // Add the parameter! |
| 999 | 1031 | $query_parameter[$real_type] = $restriction; |
| 1000 | 1032 | |
| 1001 | - if ($type == 'do_logging') |
|
| 1002 | - $do_logging = $condition['id_attach']; |
|
| 1033 | + if ($type == 'do_logging') { |
|
| 1034 | + $do_logging = $condition['id_attach']; |
|
| 1035 | + } |
|
| 1003 | 1036 | } |
| 1004 | 1037 | $condition = implode(' AND ', $new_condition); |
| 1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
| 1031 | 1064 | // wasn't it obvious? :P |
| 1032 | 1065 | // @todo look again at this. |
| 1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
| 1034 | - } |
|
| 1035 | - else |
|
| 1067 | + } else |
|
| 1036 | 1068 | { |
| 1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
| 1038 | 1070 | @unlink($filename); |
| 1039 | 1071 | |
| 1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
| 1041 | - if (!empty($row['id_parent'])) |
|
| 1042 | - $parents[] = $row['id_parent']; |
|
| 1073 | + if (!empty($row['id_parent'])) { |
|
| 1074 | + $parents[] = $row['id_parent']; |
|
| 1075 | + } |
|
| 1043 | 1076 | |
| 1044 | 1077 | // If this attachments has a thumb, remove it as well. |
| 1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
| 1051 | 1084 | } |
| 1052 | 1085 | |
| 1053 | 1086 | // Make a list. |
| 1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
| 1055 | - $msgs[] = $row['id_msg']; |
|
| 1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
| 1088 | + $msgs[] = $row['id_msg']; |
|
| 1089 | + } |
|
| 1056 | 1090 | |
| 1057 | 1091 | $attach[] = $row['id_attach']; |
| 1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
| 1060 | 1094 | |
| 1061 | 1095 | // Removed attachments don't have to be updated anymore. |
| 1062 | 1096 | $parents = array_diff($parents, $attach); |
| 1063 | - if (!empty($parents)) |
|
| 1064 | - $smcFunc['db_query']('', ' |
|
| 1097 | + if (!empty($parents)) { |
|
| 1098 | + $smcFunc['db_query']('', ' |
|
| 1065 | 1099 | UPDATE {db_prefix}attachments |
| 1066 | 1100 | SET id_thumb = {int:no_thumb} |
| 1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
| 1070 | 1104 | 'no_thumb' => 0, |
| 1071 | 1105 | ) |
| 1072 | 1106 | ); |
| 1107 | + } |
|
| 1073 | 1108 | |
| 1074 | 1109 | if (!empty($do_logging)) |
| 1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
| 1086 | 1121 | ) |
| 1087 | 1122 | ); |
| 1088 | 1123 | |
| 1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1090 | - logAction( |
|
| 1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1125 | + logAction( |
|
| 1091 | 1126 | 'remove_attach', |
| 1092 | 1127 | array( |
| 1093 | 1128 | 'message' => $row['id_msg'], |
| 1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1095 | 1130 | ) |
| 1096 | 1131 | ); |
| 1132 | + } |
|
| 1097 | 1133 | $smcFunc['db_free_result']($request); |
| 1098 | 1134 | } |
| 1099 | 1135 | |
| 1100 | - if (!empty($attach)) |
|
| 1101 | - $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($attach)) { |
|
| 1137 | + $smcFunc['db_query']('', ' |
|
| 1102 | 1138 | DELETE FROM {db_prefix}attachments |
| 1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
| 1104 | 1140 | array( |
| 1105 | 1141 | 'attachment_list' => $attach, |
| 1106 | 1142 | ) |
| 1107 | 1143 | ); |
| 1144 | + } |
|
| 1108 | 1145 | |
| 1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
| 1110 | 1147 | |
| 1111 | - if ($return_affected_messages) |
|
| 1112 | - return array_unique($msgs); |
|
| 1113 | -} |
|
| 1148 | + if ($return_affected_messages) { |
|
| 1149 | + return array_unique($msgs); |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1114 | 1152 | |
| 1115 | 1153 | /** |
| 1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
| 1122 | 1160 | checkSession('get'); |
| 1123 | 1161 | |
| 1124 | 1162 | // If we choose cancel, redirect right back. |
| 1125 | - if (isset($_POST['cancel'])) |
|
| 1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1163 | + if (isset($_POST['cancel'])) { |
|
| 1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1165 | + } |
|
| 1127 | 1166 | |
| 1128 | 1167 | // Try give us a while to sort this out... |
| 1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
| 1140 | 1179 | if (isset($_GET['fixErrors'])) |
| 1141 | 1180 | { |
| 1142 | 1181 | // Nothing? |
| 1143 | - if (empty($_POST['to_fix'])) |
|
| 1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1182 | + if (empty($_POST['to_fix'])) { |
|
| 1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1184 | + } |
|
| 1145 | 1185 | |
| 1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
| 1147 | 1187 | // @todo No need to do this I think. |
| 1148 | - foreach ($_POST['to_fix'] as $value) |
|
| 1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
| 1188 | + foreach ($_POST['to_fix'] as $value) { |
|
| 1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
| 1190 | + } |
|
| 1150 | 1191 | } |
| 1151 | 1192 | } |
| 1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
| 1213 | 1254 | } |
| 1214 | 1255 | } |
| 1215 | 1256 | } |
| 1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1259 | + } |
|
| 1218 | 1260 | $smcFunc['db_free_result']($result); |
| 1219 | 1261 | |
| 1220 | 1262 | // Do we need to delete what we have? |
| 1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
| 1222 | - $smcFunc['db_query']('', ' |
|
| 1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
| 1264 | + $smcFunc['db_query']('', ' |
|
| 1223 | 1265 | DELETE FROM {db_prefix}attachments |
| 1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
| 1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
| 1228 | 1270 | 'attachment_type' => 3, |
| 1229 | 1271 | ) |
| 1230 | 1272 | ); |
| 1273 | + } |
|
| 1231 | 1274 | |
| 1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
| 1272 | 1315 | $to_update[] = $row['id_attach']; |
| 1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
| 1274 | 1317 | } |
| 1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1320 | + } |
|
| 1277 | 1321 | $smcFunc['db_free_result']($result); |
| 1278 | 1322 | |
| 1279 | 1323 | // Do we need to delete what we have? |
| 1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
| 1281 | - $smcFunc['db_query']('', ' |
|
| 1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
| 1325 | + $smcFunc['db_query']('', ' |
|
| 1282 | 1326 | UPDATE {db_prefix}attachments |
| 1283 | 1327 | SET id_thumb = {int:no_thumb} |
| 1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
| 1287 | 1331 | 'no_thumb' => 0, |
| 1288 | 1332 | ) |
| 1289 | 1333 | ); |
| 1334 | + } |
|
| 1290 | 1335 | |
| 1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
| 1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1325 | 1370 | { |
| 1326 | 1371 | // Get the filename. |
| 1327 | - if ($row['attachment_type'] == 1) |
|
| 1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1329 | - else |
|
| 1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1372 | + if ($row['attachment_type'] == 1) { |
|
| 1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1374 | + } else { |
|
| 1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1376 | + } |
|
| 1331 | 1377 | |
| 1332 | 1378 | // File doesn't exist? |
| 1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
| 1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
| 1340 | 1386 | |
| 1341 | 1387 | // Loop through the other folders. |
| 1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
| 1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
| 1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
| 1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
| 1344 | 1390 | { |
| 1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
| 1392 | + } |
|
| 1346 | 1393 | $errors_found[] = 'wrong_folder'; |
| 1347 | 1394 | |
| 1348 | 1395 | // Are we going to fix this now? |
| 1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
| 1350 | - $smcFunc['db_query']('', ' |
|
| 1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
| 1397 | + $smcFunc['db_query']('', ' |
|
| 1351 | 1398 | UPDATE {db_prefix}attachments |
| 1352 | 1399 | SET id_folder = {int:new_folder} |
| 1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
| 1356 | 1403 | 'id_attach' => $row['id_attach'], |
| 1357 | 1404 | ) |
| 1358 | 1405 | ); |
| 1406 | + } |
|
| 1359 | 1407 | |
| 1360 | 1408 | continue 2; |
| 1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
| 1364 | 1412 | $to_remove[] = $row['id_attach']; |
| 1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
| 1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
| 1367 | - } |
|
| 1368 | - elseif (filesize($filename) == 0) |
|
| 1415 | + } elseif (filesize($filename) == 0) |
|
| 1369 | 1416 | { |
| 1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
| 1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
| 1376 | 1423 | $to_remove[] = $row['id_attach']; |
| 1377 | 1424 | @unlink($filename); |
| 1378 | 1425 | } |
| 1379 | - } |
|
| 1380 | - elseif (filesize($filename) != $row['size']) |
|
| 1426 | + } elseif (filesize($filename) != $row['size']) |
|
| 1381 | 1427 | { |
| 1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
| 1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
| 1398 | 1444 | } |
| 1399 | 1445 | } |
| 1400 | 1446 | |
| 1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
| 1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
| 1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
| 1404 | - $to_fix[] = 'file_size_of_zero'; |
|
| 1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
| 1406 | - $to_fix[] = 'file_wrong_size'; |
|
| 1407 | - if (in_array('wrong_folder', $errors_found)) |
|
| 1408 | - $to_fix[] = 'wrong_folder'; |
|
| 1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
| 1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
| 1449 | + } |
|
| 1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
| 1451 | + $to_fix[] = 'file_size_of_zero'; |
|
| 1452 | + } |
|
| 1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
| 1454 | + $to_fix[] = 'file_wrong_size'; |
|
| 1455 | + } |
|
| 1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
| 1457 | + $to_fix[] = 'wrong_folder'; |
|
| 1458 | + } |
|
| 1409 | 1459 | $smcFunc['db_free_result']($result); |
| 1410 | 1460 | |
| 1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
| 1475 | 1525 | // If we are repairing remove the file from disk now. |
| 1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
| 1477 | 1527 | { |
| 1478 | - if ($row['attachment_type'] == 1) |
|
| 1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1480 | - else |
|
| 1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1528 | + if ($row['attachment_type'] == 1) { |
|
| 1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1530 | + } else { |
|
| 1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1532 | + } |
|
| 1482 | 1533 | @unlink($filename); |
| 1483 | 1534 | } |
| 1484 | 1535 | } |
| 1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1486 | - $to_fix[] = 'avatar_no_member'; |
|
| 1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1537 | + $to_fix[] = 'avatar_no_member'; |
|
| 1538 | + } |
|
| 1487 | 1539 | $smcFunc['db_free_result']($result); |
| 1488 | 1540 | |
| 1489 | 1541 | // Do we need to delete what we have? |
| 1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
| 1491 | - $smcFunc['db_query']('', ' |
|
| 1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
| 1543 | + $smcFunc['db_query']('', ' |
|
| 1492 | 1544 | DELETE FROM {db_prefix}attachments |
| 1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
| 1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
| 1499 | 1551 | 'no_msg' => 0, |
| 1500 | 1552 | ) |
| 1501 | 1553 | ); |
| 1554 | + } |
|
| 1502 | 1555 | |
| 1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1504 | 1557 | } |
@@ -1558,13 +1611,14 @@ discard block |
||
| 1558 | 1611 | @unlink($filename); |
| 1559 | 1612 | } |
| 1560 | 1613 | } |
| 1561 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1562 | - $to_fix[] = 'attachment_no_msg'; |
|
| 1614 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1615 | + $to_fix[] = 'attachment_no_msg'; |
|
| 1616 | + } |
|
| 1563 | 1617 | $smcFunc['db_free_result']($result); |
| 1564 | 1618 | |
| 1565 | 1619 | // Do we need to delete what we have? |
| 1566 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
| 1567 | - $smcFunc['db_query']('', ' |
|
| 1620 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
| 1621 | + $smcFunc['db_query']('', ' |
|
| 1568 | 1622 | DELETE FROM {db_prefix}attachments |
| 1569 | 1623 | WHERE id_attach IN ({array_int:to_remove}) |
| 1570 | 1624 | AND id_member = {int:no_member} |
@@ -1575,6 +1629,7 @@ discard block |
||
| 1575 | 1629 | 'attach_thumb' => array(0,3), |
| 1576 | 1630 | ) |
| 1577 | 1631 | ); |
| 1632 | + } |
|
| 1578 | 1633 | |
| 1579 | 1634 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1580 | 1635 | } |
@@ -1598,8 +1653,9 @@ discard block |
||
| 1598 | 1653 | { |
| 1599 | 1654 | while ($file = readdir($dir)) |
| 1600 | 1655 | { |
| 1601 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 1602 | - continue; |
|
| 1656 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 1657 | + continue; |
|
| 1658 | + } |
|
| 1603 | 1659 | |
| 1604 | 1660 | if ($files_checked <= $current_check) |
| 1605 | 1661 | { |
@@ -1607,8 +1663,9 @@ discard block |
||
| 1607 | 1663 | if (strpos($file, 'post_tmp_') !== false) |
| 1608 | 1664 | { |
| 1609 | 1665 | // Temp file is more than 5 hours old! |
| 1610 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1611 | - @unlink($attach_dir . '/' . $file); |
|
| 1666 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1667 | + @unlink($attach_dir . '/' . $file); |
|
| 1668 | + } |
|
| 1612 | 1669 | } |
| 1613 | 1670 | // That should be an attachment, let's check if we have it in the database |
| 1614 | 1671 | elseif (strpos($file, '_') !== false) |
@@ -1630,8 +1687,7 @@ discard block |
||
| 1630 | 1687 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1631 | 1688 | { |
| 1632 | 1689 | @unlink($attach_dir . '/' . $file); |
| 1633 | - } |
|
| 1634 | - else |
|
| 1690 | + } else |
|
| 1635 | 1691 | { |
| 1636 | 1692 | $context['repair_errors']['files_without_attachment']++; |
| 1637 | 1693 | $to_fix[] = 'files_without_attachment'; |
@@ -1639,14 +1695,12 @@ discard block |
||
| 1639 | 1695 | } |
| 1640 | 1696 | $smcFunc['db_free_result']($request); |
| 1641 | 1697 | } |
| 1642 | - } |
|
| 1643 | - else |
|
| 1698 | + } else |
|
| 1644 | 1699 | { |
| 1645 | 1700 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1646 | 1701 | { |
| 1647 | 1702 | @unlink($attach_dir . '/' . $file); |
| 1648 | - } |
|
| 1649 | - else |
|
| 1703 | + } else |
|
| 1650 | 1704 | { |
| 1651 | 1705 | $context['repair_errors']['files_without_attachment']++; |
| 1652 | 1706 | $to_fix[] = 'files_without_attachment'; |
@@ -1655,8 +1709,9 @@ discard block |
||
| 1655 | 1709 | } |
| 1656 | 1710 | $current_check++; |
| 1657 | 1711 | $_GET['substep'] = $current_check; |
| 1658 | - if ($current_check - $files_checked >= $max_checks) |
|
| 1659 | - pauseAttachmentMaintenance($to_fix); |
|
| 1712 | + if ($current_check - $files_checked >= $max_checks) { |
|
| 1713 | + pauseAttachmentMaintenance($to_fix); |
|
| 1714 | + } |
|
| 1660 | 1715 | } |
| 1661 | 1716 | closedir($dir); |
| 1662 | 1717 | } |
@@ -1692,12 +1747,14 @@ discard block |
||
| 1692 | 1747 | |
| 1693 | 1748 | // Try get more time... |
| 1694 | 1749 | @set_time_limit(600); |
| 1695 | - if (function_exists('apache_reset_timeout')) |
|
| 1696 | - @apache_reset_timeout(); |
|
| 1750 | + if (function_exists('apache_reset_timeout')) { |
|
| 1751 | + @apache_reset_timeout(); |
|
| 1752 | + } |
|
| 1697 | 1753 | |
| 1698 | 1754 | // Have we already used our maximum time? |
| 1699 | - if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
| 1700 | - return; |
|
| 1755 | + if ((time() - $time_start) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
| 1756 | + return; |
|
| 1757 | + } |
|
| 1701 | 1758 | |
| 1702 | 1759 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1703 | 1760 | $context['page_title'] = $txt['not_done_title']; |
@@ -1709,10 +1766,11 @@ discard block |
||
| 1709 | 1766 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
| 1710 | 1767 | |
| 1711 | 1768 | // Change these two if more steps are added! |
| 1712 | - if (empty($max_substep)) |
|
| 1713 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1714 | - else |
|
| 1715 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1769 | + if (empty($max_substep)) { |
|
| 1770 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1771 | + } else { |
|
| 1772 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1773 | + } |
|
| 1716 | 1774 | |
| 1717 | 1775 | // Never more than 100%! |
| 1718 | 1776 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1754,15 +1812,17 @@ discard block |
||
| 1754 | 1812 | 'attachment_type' => 0, |
| 1755 | 1813 | ) |
| 1756 | 1814 | ); |
| 1757 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1758 | - $attachments[] = $row['id_attach']; |
|
| 1815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1816 | + $attachments[] = $row['id_attach']; |
|
| 1817 | + } |
|
| 1759 | 1818 | $smcFunc['db_free_result']($request); |
| 1819 | + } elseif (!empty($_GET['aid'])) { |
|
| 1820 | + $attachments[] = (int) $_GET['aid']; |
|
| 1760 | 1821 | } |
| 1761 | - elseif (!empty($_GET['aid'])) |
|
| 1762 | - $attachments[] = (int) $_GET['aid']; |
|
| 1763 | 1822 | |
| 1764 | - if (empty($attachments)) |
|
| 1765 | - fatal_lang_error('no_access', false); |
|
| 1823 | + if (empty($attachments)) { |
|
| 1824 | + fatal_lang_error('no_access', false); |
|
| 1825 | + } |
|
| 1766 | 1826 | |
| 1767 | 1827 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
| 1768 | 1828 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1795,17 +1855,18 @@ discard block |
||
| 1795 | 1855 | } |
| 1796 | 1856 | $smcFunc['db_free_result']($request); |
| 1797 | 1857 | |
| 1798 | - if (empty($attachments)) |
|
| 1799 | - fatal_lang_error('no_access', false); |
|
| 1858 | + if (empty($attachments)) { |
|
| 1859 | + fatal_lang_error('no_access', false); |
|
| 1860 | + } |
|
| 1800 | 1861 | |
| 1801 | 1862 | // Finally, we are there. Follow through! |
| 1802 | 1863 | if ($is_approve) |
| 1803 | 1864 | { |
| 1804 | 1865 | // Checked and deemed worthy. |
| 1805 | 1866 | ApproveAttachments($attachments); |
| 1867 | + } else { |
|
| 1868 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1806 | 1869 | } |
| 1807 | - else |
|
| 1808 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1809 | 1870 | |
| 1810 | 1871 | // Return to the topic.... |
| 1811 | 1872 | redirectexit($redirect); |
@@ -1821,8 +1882,9 @@ discard block |
||
| 1821 | 1882 | { |
| 1822 | 1883 | global $smcFunc; |
| 1823 | 1884 | |
| 1824 | - if (empty($attachments)) |
|
| 1825 | - return 0; |
|
| 1885 | + if (empty($attachments)) { |
|
| 1886 | + return 0; |
|
| 1887 | + } |
|
| 1826 | 1888 | |
| 1827 | 1889 | // For safety, check for thumbnails... |
| 1828 | 1890 | $request = $smcFunc['db_query']('', ' |
@@ -1841,15 +1903,17 @@ discard block |
||
| 1841 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1842 | 1904 | { |
| 1843 | 1905 | // Update the thumbnail too... |
| 1844 | - if (!empty($row['id_thumb'])) |
|
| 1845 | - $attachments[] = $row['id_thumb']; |
|
| 1906 | + if (!empty($row['id_thumb'])) { |
|
| 1907 | + $attachments[] = $row['id_thumb']; |
|
| 1908 | + } |
|
| 1846 | 1909 | |
| 1847 | 1910 | $attachments[] = $row['id_attach']; |
| 1848 | 1911 | } |
| 1849 | 1912 | $smcFunc['db_free_result']($request); |
| 1850 | 1913 | |
| 1851 | - if (empty($attachments)) |
|
| 1852 | - return 0; |
|
| 1914 | + if (empty($attachments)) { |
|
| 1915 | + return 0; |
|
| 1916 | + } |
|
| 1853 | 1917 | |
| 1854 | 1918 | // Approving an attachment is not hard - it's easy. |
| 1855 | 1919 | $smcFunc['db_query']('', ' |
@@ -1875,14 +1939,15 @@ discard block |
||
| 1875 | 1939 | ) |
| 1876 | 1940 | ); |
| 1877 | 1941 | |
| 1878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1879 | - logAction( |
|
| 1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1943 | + logAction( |
|
| 1880 | 1944 | 'approve_attach', |
| 1881 | 1945 | array( |
| 1882 | 1946 | 'message' => $row['id_msg'], |
| 1883 | 1947 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1884 | 1948 | ) |
| 1885 | 1949 | ); |
| 1950 | + } |
|
| 1886 | 1951 | $smcFunc['db_free_result']($request); |
| 1887 | 1952 | |
| 1888 | 1953 | // Remove from the approval queue. |
@@ -1905,11 +1970,11 @@ discard block |
||
| 1905 | 1970 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
| 1906 | 1971 | |
| 1907 | 1972 | // Since this needs to be done eventually. |
| 1908 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
| 1909 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 1910 | - |
|
| 1911 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
| 1912 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 1973 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
| 1974 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 1975 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 1976 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 1977 | + } |
|
| 1913 | 1978 | |
| 1914 | 1979 | $errors = array(); |
| 1915 | 1980 | |
@@ -1924,8 +1989,9 @@ discard block |
||
| 1924 | 1989 | { |
| 1925 | 1990 | $error = ''; |
| 1926 | 1991 | $id = (int) $id; |
| 1927 | - if ($id < 1) |
|
| 1928 | - continue; |
|
| 1992 | + if ($id < 1) { |
|
| 1993 | + continue; |
|
| 1994 | + } |
|
| 1929 | 1995 | |
| 1930 | 1996 | // Sorry, these dirs are NOT valid |
| 1931 | 1997 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1944,8 +2010,7 @@ discard block |
||
| 1944 | 2010 | { |
| 1945 | 2011 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
| 1946 | 2012 | continue; |
| 1947 | - } |
|
| 1948 | - elseif (empty($path)) |
|
| 2013 | + } elseif (empty($path)) |
|
| 1949 | 2014 | { |
| 1950 | 2015 | // Ignore this and set $id to one less |
| 1951 | 2016 | continue; |
@@ -1953,10 +2018,11 @@ discard block |
||
| 1953 | 2018 | |
| 1954 | 2019 | // OK, so let's try to create it then. |
| 1955 | 2020 | require_once($sourcedir . '/Subs-Attachments.php'); |
| 1956 | - if (automanage_attachments_create_directory($path)) |
|
| 1957 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 1958 | - else |
|
| 1959 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2021 | + if (automanage_attachments_create_directory($path)) { |
|
| 2022 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2023 | + } else { |
|
| 2024 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2025 | + } |
|
| 1960 | 2026 | } |
| 1961 | 2027 | |
| 1962 | 2028 | // Changing a directory name? |
@@ -1969,8 +2035,7 @@ discard block |
||
| 1969 | 2035 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
| 1970 | 2036 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1971 | 2037 | } |
| 1972 | - } |
|
| 1973 | - else |
|
| 2038 | + } else |
|
| 1974 | 2039 | { |
| 1975 | 2040 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
| 1976 | 2041 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1995,12 +2060,13 @@ discard block |
||
| 1995 | 2060 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1996 | 2061 | |
| 1997 | 2062 | // It's not a good idea to delete the current directory. |
| 1998 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
| 1999 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2063 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
| 2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2065 | + } |
|
| 2000 | 2066 | // Or the current base directory |
| 2001 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
| 2002 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2003 | - else |
|
| 2067 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
| 2068 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2069 | + } else |
|
| 2004 | 2070 | { |
| 2005 | 2071 | // Let's not try to delete a path with files in it. |
| 2006 | 2072 | $request = $smcFunc['db_query']('', ' |
@@ -2019,17 +2085,18 @@ discard block |
||
| 2019 | 2085 | if (!empty($modSettings['attachment_basedirectories'])) |
| 2020 | 2086 | { |
| 2021 | 2087 | // Count any sub-folders. |
| 2022 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
| 2023 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2088 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
| 2089 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2024 | 2090 | $num_attach++; |
| 2091 | + } |
|
| 2025 | 2092 | } |
| 2026 | 2093 | |
| 2027 | 2094 | // It's safe to delete. So try to delete the folder also |
| 2028 | 2095 | if ($num_attach == 0) |
| 2029 | 2096 | { |
| 2030 | - if (is_dir($path)) |
|
| 2031 | - $doit = true; |
|
| 2032 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2097 | + if (is_dir($path)) { |
|
| 2098 | + $doit = true; |
|
| 2099 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2033 | 2100 | { |
| 2034 | 2101 | $doit = true; |
| 2035 | 2102 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2039,8 +2106,9 @@ discard block |
||
| 2039 | 2106 | { |
| 2040 | 2107 | unlink($path . '/.htaccess'); |
| 2041 | 2108 | unlink($path . '/index.php'); |
| 2042 | - if (!@rmdir($path)) |
|
| 2043 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2109 | + if (!@rmdir($path)) { |
|
| 2110 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2111 | + } |
|
| 2044 | 2112 | } |
| 2045 | 2113 | |
| 2046 | 2114 | // Remove it from the base directory list. |
@@ -2050,14 +2118,15 @@ discard block |
||
| 2050 | 2118 | updateSettings(array('attachment_basedirectories' => $smcFunc['json_encode']($modSettings['attachment_basedirectories']))); |
| 2051 | 2119 | $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
| 2052 | 2120 | } |
| 2121 | + } else { |
|
| 2122 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2053 | 2123 | } |
| 2054 | - else |
|
| 2055 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2056 | 2124 | |
| 2057 | - if (empty($error)) |
|
| 2058 | - continue; |
|
| 2059 | - else |
|
| 2060 | - $errors[] = $error; |
|
| 2125 | + if (empty($error)) { |
|
| 2126 | + continue; |
|
| 2127 | + } else { |
|
| 2128 | + $errors[] = $error; |
|
| 2129 | + } |
|
| 2061 | 2130 | } |
| 2062 | 2131 | } |
| 2063 | 2132 | |
@@ -2065,23 +2134,26 @@ discard block |
||
| 2065 | 2134 | } |
| 2066 | 2135 | |
| 2067 | 2136 | // We need to make sure the current directory is right. |
| 2068 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
| 2069 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2137 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 2138 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2139 | + } |
|
| 2070 | 2140 | |
| 2071 | 2141 | // Find the current directory if there's no value carried, |
| 2072 | 2142 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
| 2073 | 2143 | { |
| 2074 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
| 2075 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2076 | - else |
|
| 2077 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2144 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
| 2145 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2146 | + } else { |
|
| 2147 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2148 | + } |
|
| 2078 | 2149 | } |
| 2079 | 2150 | |
| 2080 | 2151 | // If the user wishes to go back, update the last_dir array |
| 2081 | 2152 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
| 2082 | 2153 | { |
| 2083 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 2084 | - $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
| 2154 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 2155 | + $modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true); |
|
| 2156 | + } |
|
| 2085 | 2157 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
| 2086 | 2158 | |
| 2087 | 2159 | if (is_numeric($num)) |
@@ -2089,16 +2161,18 @@ discard block |
||
| 2089 | 2161 | // Need to find the base folder. |
| 2090 | 2162 | $bid = -1; |
| 2091 | 2163 | $use_subdirectories_for_attachments = 0; |
| 2092 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2093 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2164 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2165 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2094 | 2166 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
| 2095 | 2167 | { |
| 2096 | 2168 | $use_subdirectories_for_attachments = 1; |
| 2169 | + } |
|
| 2097 | 2170 | break; |
| 2098 | 2171 | } |
| 2099 | 2172 | |
| 2100 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
| 2101 | - $bid = 0; |
|
| 2173 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
| 2174 | + $bid = 0; |
|
| 2175 | + } |
|
| 2102 | 2176 | |
| 2103 | 2177 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
| 2104 | 2178 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2117,8 +2191,8 @@ discard block |
||
| 2117 | 2191 | // We might need to reset the paths. This loop will just loop through once. |
| 2118 | 2192 | foreach ($new_dirs as $id => $dir) |
| 2119 | 2193 | { |
| 2120 | - if ($id != 1) |
|
| 2121 | - $smcFunc['db_query']('', ' |
|
| 2194 | + if ($id != 1) { |
|
| 2195 | + $smcFunc['db_query']('', ' |
|
| 2122 | 2196 | UPDATE {db_prefix}attachments |
| 2123 | 2197 | SET id_folder = {int:default_folder} |
| 2124 | 2198 | WHERE id_folder = {int:current_folder}', |
@@ -2127,14 +2201,14 @@ discard block |
||
| 2127 | 2201 | 'current_folder' => $id, |
| 2128 | 2202 | ) |
| 2129 | 2203 | ); |
| 2204 | + } |
|
| 2130 | 2205 | |
| 2131 | 2206 | $update = array( |
| 2132 | 2207 | 'currentAttachmentUploadDir' => 1, |
| 2133 | 2208 | 'attachmentUploadDir' => $smcFunc['json_encode'](array(1 => $dir)), |
| 2134 | 2209 | ); |
| 2135 | 2210 | } |
| 2136 | - } |
|
| 2137 | - else |
|
| 2211 | + } else |
|
| 2138 | 2212 | { |
| 2139 | 2213 | // Save it to the database. |
| 2140 | 2214 | $update = array( |
@@ -2143,11 +2217,13 @@ discard block |
||
| 2143 | 2217 | ); |
| 2144 | 2218 | } |
| 2145 | 2219 | |
| 2146 | - if (!empty($update)) |
|
| 2147 | - updateSettings($update); |
|
| 2220 | + if (!empty($update)) { |
|
| 2221 | + updateSettings($update); |
|
| 2222 | + } |
|
| 2148 | 2223 | |
| 2149 | - if (!empty($errors)) |
|
| 2150 | - $_SESSION['errors']['dir'] = $errors; |
|
| 2224 | + if (!empty($errors)) { |
|
| 2225 | + $_SESSION['errors']['dir'] = $errors; |
|
| 2226 | + } |
|
| 2151 | 2227 | |
| 2152 | 2228 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2153 | 2229 | } |
@@ -2161,10 +2237,11 @@ discard block |
||
| 2161 | 2237 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
| 2162 | 2238 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
| 2163 | 2239 | { |
| 2164 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
| 2165 | - $update = (array( |
|
| 2240 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
| 2241 | + $update = (array( |
|
| 2166 | 2242 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
| 2167 | 2243 | )); |
| 2244 | + } |
|
| 2168 | 2245 | } |
| 2169 | 2246 | |
| 2170 | 2247 | if (isset($_POST['base_dir'])) |
@@ -2212,13 +2289,15 @@ discard block |
||
| 2212 | 2289 | |
| 2213 | 2290 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
| 2214 | 2291 | { |
| 2215 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
| 2216 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2292 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
| 2293 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2294 | + } |
|
| 2217 | 2295 | } |
| 2218 | 2296 | |
| 2219 | 2297 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
| 2220 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
| 2221 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2298 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
| 2299 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2300 | + } |
|
| 2222 | 2301 | ksort($modSettings['attachment_basedirectories']); |
| 2223 | 2302 | |
| 2224 | 2303 | $update = (array( |
@@ -2228,11 +2307,13 @@ discard block |
||
| 2228 | 2307 | )); |
| 2229 | 2308 | } |
| 2230 | 2309 | |
| 2231 | - if (!empty($errors)) |
|
| 2232 | - $_SESSION['errors']['base'] = $errors; |
|
| 2310 | + if (!empty($errors)) { |
|
| 2311 | + $_SESSION['errors']['base'] = $errors; |
|
| 2312 | + } |
|
| 2233 | 2313 | |
| 2234 | - if (!empty($update)) |
|
| 2235 | - updateSettings($update); |
|
| 2314 | + if (!empty($update)) { |
|
| 2315 | + updateSettings($update); |
|
| 2316 | + } |
|
| 2236 | 2317 | |
| 2237 | 2318 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2238 | 2319 | } |
@@ -2242,13 +2323,15 @@ discard block |
||
| 2242 | 2323 | if (is_array($_SESSION['errors'])) |
| 2243 | 2324 | { |
| 2244 | 2325 | $errors = array(); |
| 2245 | - if (!empty($_SESSION['errors']['dir'])) |
|
| 2246 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2326 | + if (!empty($_SESSION['errors']['dir'])) { |
|
| 2327 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2247 | 2328 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2329 | + } |
|
| 2248 | 2330 | |
| 2249 | - if (!empty($_SESSION['errors']['base'])) |
|
| 2250 | - foreach ($_SESSION['errors']['base'] as $error) |
|
| 2331 | + if (!empty($_SESSION['errors']['base'])) { |
|
| 2332 | + foreach ($_SESSION['errors']['base'] as $error) |
|
| 2251 | 2333 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2334 | + } |
|
| 2252 | 2335 | } |
| 2253 | 2336 | unset($_SESSION['errors']); |
| 2254 | 2337 | } |
@@ -2458,8 +2541,9 @@ discard block |
||
| 2458 | 2541 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
| 2459 | 2542 | { |
| 2460 | 2543 | // If there aren't any attachments in this directory this won't exist. |
| 2461 | - if (!isset($expected_files[$id])) |
|
| 2462 | - $expected_files[$id] = 0; |
|
| 2544 | + if (!isset($expected_files[$id])) { |
|
| 2545 | + $expected_files[$id] = 0; |
|
| 2546 | + } |
|
| 2463 | 2547 | |
| 2464 | 2548 | // Check if the directory is doing okay. |
| 2465 | 2549 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2472,10 +2556,11 @@ discard block |
||
| 2472 | 2556 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
| 2473 | 2557 | |
| 2474 | 2558 | // Count any sub-folders. |
| 2475 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2476 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2559 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2560 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2477 | 2561 | { |
| 2478 | 2562 | $expected_files[$id]++; |
| 2563 | + } |
|
| 2479 | 2564 | $sub_dirs++; |
| 2480 | 2565 | } |
| 2481 | 2566 | } |
@@ -2493,8 +2578,8 @@ discard block |
||
| 2493 | 2578 | } |
| 2494 | 2579 | |
| 2495 | 2580 | // Just stick a new directory on at the bottom. |
| 2496 | - if (isset($_REQUEST['new_path'])) |
|
| 2497 | - $attachdirs[] = array( |
|
| 2581 | + if (isset($_REQUEST['new_path'])) { |
|
| 2582 | + $attachdirs[] = array( |
|
| 2498 | 2583 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
| 2499 | 2584 | 'current' => false, |
| 2500 | 2585 | 'path' => '', |
@@ -2502,6 +2587,7 @@ discard block |
||
| 2502 | 2587 | 'num_files' => '', |
| 2503 | 2588 | 'status' => '', |
| 2504 | 2589 | ); |
| 2590 | + } |
|
| 2505 | 2591 | |
| 2506 | 2592 | return $attachdirs; |
| 2507 | 2593 | } |
@@ -2514,8 +2600,9 @@ discard block |
||
| 2514 | 2600 | { |
| 2515 | 2601 | global $modSettings, $txt; |
| 2516 | 2602 | |
| 2517 | - if (empty($modSettings['attachment_basedirectories'])) |
|
| 2518 | - return; |
|
| 2603 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
| 2604 | + return; |
|
| 2605 | + } |
|
| 2519 | 2606 | |
| 2520 | 2607 | $basedirs = array(); |
| 2521 | 2608 | // Get a list of the base directories. |
@@ -2523,16 +2610,18 @@ discard block |
||
| 2523 | 2610 | { |
| 2524 | 2611 | // Loop through the attach directory array to count any sub-directories |
| 2525 | 2612 | $expected_dirs = 0; |
| 2526 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2527 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2613 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2614 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2528 | 2615 | $expected_dirs++; |
| 2616 | + } |
|
| 2529 | 2617 | |
| 2530 | - if (!is_dir($dir)) |
|
| 2531 | - $status = 'does_not_exist'; |
|
| 2532 | - elseif (!is_writeable($dir)) |
|
| 2533 | - $status = 'not_writable'; |
|
| 2534 | - else |
|
| 2535 | - $status = 'ok'; |
|
| 2618 | + if (!is_dir($dir)) { |
|
| 2619 | + $status = 'does_not_exist'; |
|
| 2620 | + } elseif (!is_writeable($dir)) { |
|
| 2621 | + $status = 'not_writable'; |
|
| 2622 | + } else { |
|
| 2623 | + $status = 'ok'; |
|
| 2624 | + } |
|
| 2536 | 2625 | |
| 2537 | 2626 | $basedirs[] = array( |
| 2538 | 2627 | 'id' => $id, |
@@ -2543,14 +2632,15 @@ discard block |
||
| 2543 | 2632 | ); |
| 2544 | 2633 | } |
| 2545 | 2634 | |
| 2546 | - if (isset($_REQUEST['new_base_path'])) |
|
| 2547 | - $basedirs[] = array( |
|
| 2635 | + if (isset($_REQUEST['new_base_path'])) { |
|
| 2636 | + $basedirs[] = array( |
|
| 2548 | 2637 | 'id' => '', |
| 2549 | 2638 | 'current' => false, |
| 2550 | 2639 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
| 2551 | 2640 | 'num_dirs' => '', |
| 2552 | 2641 | 'status' => '', |
| 2553 | 2642 | ); |
| 2643 | + } |
|
| 2554 | 2644 | |
| 2555 | 2645 | return $basedirs; |
| 2556 | 2646 | } |
@@ -2566,10 +2656,11 @@ discard block |
||
| 2566 | 2656 | */ |
| 2567 | 2657 | function attachDirStatus($dir, $expected_files) |
| 2568 | 2658 | { |
| 2569 | - if (!is_dir($dir)) |
|
| 2570 | - return array('does_not_exist', true, ''); |
|
| 2571 | - elseif (!is_writable($dir)) |
|
| 2572 | - return array('not_writable', true, ''); |
|
| 2659 | + if (!is_dir($dir)) { |
|
| 2660 | + return array('does_not_exist', true, ''); |
|
| 2661 | + } elseif (!is_writable($dir)) { |
|
| 2662 | + return array('not_writable', true, ''); |
|
| 2663 | + } |
|
| 2573 | 2664 | |
| 2574 | 2665 | // Everything is okay so far, start to scan through the directory. |
| 2575 | 2666 | $num_files = 0; |
@@ -2577,22 +2668,26 @@ discard block |
||
| 2577 | 2668 | while ($file = $dir_handle->read()) |
| 2578 | 2669 | { |
| 2579 | 2670 | // Now do we have a real file here? |
| 2580 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 2581 | - continue; |
|
| 2671 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 2672 | + continue; |
|
| 2673 | + } |
|
| 2582 | 2674 | |
| 2583 | 2675 | $num_files++; |
| 2584 | 2676 | } |
| 2585 | 2677 | $dir_handle->close(); |
| 2586 | 2678 | |
| 2587 | - if ($num_files < $expected_files) |
|
| 2588 | - return array('files_missing', true, $num_files); |
|
| 2679 | + if ($num_files < $expected_files) { |
|
| 2680 | + return array('files_missing', true, $num_files); |
|
| 2681 | + } |
|
| 2589 | 2682 | // Empty? |
| 2590 | - elseif ($expected_files == 0) |
|
| 2591 | - return array('unused', false, $num_files); |
|
| 2683 | + elseif ($expected_files == 0) { |
|
| 2684 | + return array('unused', false, $num_files); |
|
| 2685 | + } |
|
| 2592 | 2686 | // All good! |
| 2593 | - else |
|
| 2594 | - return array('ok', false, $num_files); |
|
| 2595 | -} |
|
| 2687 | + else { |
|
| 2688 | + return array('ok', false, $num_files); |
|
| 2689 | + } |
|
| 2690 | + } |
|
| 2596 | 2691 | |
| 2597 | 2692 | /** |
| 2598 | 2693 | * Maintance function to move attachments from one directory to another |
@@ -2604,10 +2699,11 @@ discard block |
||
| 2604 | 2699 | checkSession(); |
| 2605 | 2700 | |
| 2606 | 2701 | $modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true); |
| 2607 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2608 | - $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 2609 | - else |
|
| 2610 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2702 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2703 | + $modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true); |
|
| 2704 | + } else { |
|
| 2705 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2706 | + } |
|
| 2611 | 2707 | |
| 2612 | 2708 | $_POST['from'] = (int) $_POST['from']; |
| 2613 | 2709 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2621,11 +2717,13 @@ discard block |
||
| 2621 | 2717 | $total_moved = 0; |
| 2622 | 2718 | $total_not_moved = 0; |
| 2623 | 2719 | |
| 2624 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
| 2625 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2720 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
| 2721 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2722 | + } |
|
| 2626 | 2723 | |
| 2627 | - if ($_POST['from'] == $_POST['to']) |
|
| 2628 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2724 | + if ($_POST['from'] == $_POST['to']) { |
|
| 2725 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2726 | + } |
|
| 2629 | 2727 | |
| 2630 | 2728 | if (empty($results)) |
| 2631 | 2729 | { |
@@ -2644,8 +2742,9 @@ discard block |
||
| 2644 | 2742 | $smcFunc['db_free_result']($request); |
| 2645 | 2743 | $total_progress -= $start; |
| 2646 | 2744 | |
| 2647 | - if ($total_progress < 1) |
|
| 2648 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2745 | + if ($total_progress < 1) { |
|
| 2746 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2747 | + } |
|
| 2649 | 2748 | } |
| 2650 | 2749 | |
| 2651 | 2750 | if (empty($results)) |
@@ -2661,9 +2760,9 @@ discard block |
||
| 2661 | 2760 | |
| 2662 | 2761 | automanage_attachments_check_directory(); |
| 2663 | 2762 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
| 2763 | + } else { |
|
| 2764 | + $new_dir = $_POST['to']; |
|
| 2664 | 2765 | } |
| 2665 | - else |
|
| 2666 | - $new_dir = $_POST['to']; |
|
| 2667 | 2766 | |
| 2668 | 2767 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
| 2669 | 2768 | |
@@ -2671,8 +2770,9 @@ discard block |
||
| 2671 | 2770 | while ($break == false) |
| 2672 | 2771 | { |
| 2673 | 2772 | @set_time_limit(300); |
| 2674 | - if (function_exists('apache_reset_timeout')) |
|
| 2675 | - @apache_reset_timeout(); |
|
| 2773 | + if (function_exists('apache_reset_timeout')) { |
|
| 2774 | + @apache_reset_timeout(); |
|
| 2775 | + } |
|
| 2676 | 2776 | |
| 2677 | 2777 | // If limits are set, get the file count and size for the destination folder |
| 2678 | 2778 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2708,13 +2808,15 @@ discard block |
||
| 2708 | 2808 | |
| 2709 | 2809 | if ($smcFunc['db_num_rows']($request) === 0) |
| 2710 | 2810 | { |
| 2711 | - if (empty($current_progress)) |
|
| 2712 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2811 | + if (empty($current_progress)) { |
|
| 2812 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2813 | + } |
|
| 2713 | 2814 | break; |
| 2714 | 2815 | } |
| 2715 | 2816 | |
| 2716 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
| 2717 | - $break = true; |
|
| 2817 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
| 2818 | + $break = true; |
|
| 2819 | + } |
|
| 2718 | 2820 | |
| 2719 | 2821 | // Move them |
| 2720 | 2822 | $moved = array(); |
@@ -2738,8 +2840,9 @@ discard block |
||
| 2738 | 2840 | automanage_attachments_by_space(); |
| 2739 | 2841 | |
| 2740 | 2842 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2741 | - if (!empty($total_not_moved)) |
|
| 2742 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2843 | + if (!empty($total_not_moved)) { |
|
| 2844 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2845 | + } |
|
| 2743 | 2846 | |
| 2744 | 2847 | $dir_files = 0; |
| 2745 | 2848 | $total_moved = 0; |
@@ -2747,8 +2850,7 @@ discard block |
||
| 2747 | 2850 | |
| 2748 | 2851 | $break = false; |
| 2749 | 2852 | break; |
| 2750 | - } |
|
| 2751 | - else |
|
| 2853 | + } else |
|
| 2752 | 2854 | { |
| 2753 | 2855 | // Hmm, not in auto. Time to bail out then... |
| 2754 | 2856 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2763,9 +2865,9 @@ discard block |
||
| 2763 | 2865 | $total_moved++; |
| 2764 | 2866 | $current_progress++; |
| 2765 | 2867 | $moved[] = $row['id_attach']; |
| 2868 | + } else { |
|
| 2869 | + $total_not_moved++; |
|
| 2766 | 2870 | } |
| 2767 | - else |
|
| 2768 | - $total_not_moved++; |
|
| 2769 | 2871 | } |
| 2770 | 2872 | $smcFunc['db_free_result']($request); |
| 2771 | 2873 | |
@@ -2803,13 +2905,15 @@ discard block |
||
| 2803 | 2905 | } |
| 2804 | 2906 | |
| 2805 | 2907 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2806 | - if (!empty($total_not_moved)) |
|
| 2807 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2908 | + if (!empty($total_not_moved)) { |
|
| 2909 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2910 | + } |
|
| 2808 | 2911 | } |
| 2809 | 2912 | |
| 2810 | 2913 | $_SESSION['results'] = $results; |
| 2811 | - if (file_exists($boarddir . '/progress.php')) |
|
| 2812 | - unlink($boarddir . '/progress.php'); |
|
| 2914 | + if (file_exists($boarddir . '/progress.php')) { |
|
| 2915 | + unlink($boarddir . '/progress.php'); |
|
| 2916 | + } |
|
| 2813 | 2917 | |
| 2814 | 2918 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
| 2815 | 2919 | } |
@@ -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 | { |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function cleanCache($type = '') |
| 110 | 110 | { |
| 111 | - if($type == 'expired') |
|
| 112 | - $query = 'DELETE FROM cache WHERE ttl >= ' . time().';'; |
|
| 111 | + if ($type == 'expired') |
|
| 112 | + $query = 'DELETE FROM cache WHERE ttl >= ' . time() . ';'; |
|
| 113 | 113 | else |
| 114 | 114 | $query = 'DELETE FROM cache;'; |
| 115 | 115 | |
| 116 | 116 | $result = $this->cacheDB->exec($query); |
| 117 | 117 | |
| 118 | - $query = 'VACUUM;'; |
|
| 118 | + $query = 'VACUUM;'; |
|
| 119 | 119 | $this->cacheDB->exec($query); |
| 120 | 120 | |
| 121 | 121 | return $result; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | // If its invalid, use SMF's. |
| 158 | 158 | if (is_null($dir) || !is_writable($dir)) |
| 159 | - if(is_null($cachedir_sqlite) || !is_writable($cachedir_sqlite)) |
|
| 159 | + if (is_null($cachedir_sqlite) || !is_writable($cachedir_sqlite)) |
|
| 160 | 160 | $this->cachedir = $cachedir; |
| 161 | 161 | else |
| 162 | 162 | $this->cachedir = $cachedir_sqlite; |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * SQLite Cache API class |
@@ -68,8 +69,9 @@ discard block |
||
| 68 | 69 | { |
| 69 | 70 | $supported = class_exists("SQLite3") && is_writable($this->cachedir); |
| 70 | 71 | |
| 71 | - if ($test) |
|
| 72 | - return $supported; |
|
| 72 | + if ($test) { |
|
| 73 | + return $supported; |
|
| 74 | + } |
|
| 73 | 75 | |
| 74 | 76 | return parent::isSupported() && $supported; |
| 75 | 77 | } |
@@ -84,8 +86,9 @@ discard block |
||
| 84 | 86 | $result = $this->cacheDB->query($query); |
| 85 | 87 | |
| 86 | 88 | $value = null; |
| 87 | - while ($res = $result->fetchArray(SQLITE3_ASSOC)) |
|
| 88 | - $value = $res['value']; |
|
| 89 | + while ($res = $result->fetchArray(SQLITE3_ASSOC)) { |
|
| 90 | + $value = $res['value']; |
|
| 91 | + } |
|
| 89 | 92 | |
| 90 | 93 | return !empty($value) ? $value : null; |
| 91 | 94 | } |
@@ -108,10 +111,11 @@ discard block |
||
| 108 | 111 | */ |
| 109 | 112 | public function cleanCache($type = '') |
| 110 | 113 | { |
| 111 | - if($type == 'expired') |
|
| 112 | - $query = 'DELETE FROM cache WHERE ttl >= ' . time().';'; |
|
| 113 | - else |
|
| 114 | - $query = 'DELETE FROM cache;'; |
|
| 114 | + if($type == 'expired') { |
|
| 115 | + $query = 'DELETE FROM cache WHERE ttl >= ' . time().';'; |
|
| 116 | + } else { |
|
| 117 | + $query = 'DELETE FROM cache;'; |
|
| 118 | + } |
|
| 115 | 119 | |
| 116 | 120 | $result = $this->cacheDB->exec($query); |
| 117 | 121 | |
@@ -131,8 +135,9 @@ discard block |
||
| 131 | 135 | $config_vars[] = $txt['cache_sqlite_settings']; |
| 132 | 136 | $config_vars[] = array('cachedir_sqlite', $txt['cachedir_sqlite'], 'file', 'text', 36, 'cache_sqlite_cachedir'); |
| 133 | 137 | |
| 134 | - if (!isset($context['settings_post_javascript'])) |
|
| 135 | - $context['settings_post_javascript'] = ''; |
|
| 138 | + if (!isset($context['settings_post_javascript'])) { |
|
| 139 | + $context['settings_post_javascript'] = ''; |
|
| 140 | + } |
|
| 136 | 141 | |
| 137 | 142 | $context['settings_post_javascript'] .= ' |
| 138 | 143 | $("#cache_accelerator").change(function (e) { |
@@ -155,13 +160,15 @@ discard block |
||
| 155 | 160 | global $cachedir, $cachedir_sqlite; |
| 156 | 161 | |
| 157 | 162 | // If its invalid, use SMF's. |
| 158 | - if (is_null($dir) || !is_writable($dir)) |
|
| 159 | - if(is_null($cachedir_sqlite) || !is_writable($cachedir_sqlite)) |
|
| 163 | + if (is_null($dir) || !is_writable($dir)) { |
|
| 164 | + if(is_null($cachedir_sqlite) || !is_writable($cachedir_sqlite)) |
|
| 160 | 165 | $this->cachedir = $cachedir; |
| 161 | - else |
|
| 162 | - $this->cachedir = $cachedir_sqlite; |
|
| 163 | - else |
|
| 164 | - $this->cachedir = $dir; |
|
| 166 | + } else { |
|
| 167 | + $this->cachedir = $cachedir_sqlite; |
|
| 168 | + } |
|
| 169 | + else { |
|
| 170 | + $this->cachedir = $dir; |
|
| 171 | + } |
|
| 165 | 172 | } |
| 166 | 173 | |
| 167 | 174 | /** |
@@ -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 | { |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | $smcFunc['db_drop_table']($table_name); |
| 123 | 123 | else if ($if_exists == 'update') |
| 124 | 124 | { |
| 125 | - $smcFunc['db_drop_table']($table_name.'_old'); |
|
| 125 | + $smcFunc['db_drop_table']($table_name . '_old'); |
|
| 126 | 126 | $smcFunc['db_transaction']('begin'); |
| 127 | 127 | $db_trans = true; |
| 128 | - $smcFunc['db_query']('',' |
|
| 129 | - ALTER TABLE '. $table_name .' RENAME TO ' . $table_name . '_old', |
|
| 128 | + $smcFunc['db_query']('', ' |
|
| 129 | + ALTER TABLE '. $table_name . ' RENAME TO ' . $table_name . '_old', |
|
| 130 | 130 | array( |
| 131 | 131 | 'security_override' => true, |
| 132 | 132 | ) |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | $same_col = array(); |
| 215 | 215 | |
| 216 | - $request = $smcFunc['db_query']('',' |
|
| 216 | + $request = $smcFunc['db_query']('', ' |
|
| 217 | 217 | SELECT count(*), column_name |
| 218 | 218 | FROM information_schema.columns |
| 219 | 219 | WHERE table_name in ({string:table1},{string:table2}) AND table_schema = {string:schema} |
| 220 | 220 | GROUP BY column_name |
| 221 | 221 | HAVING count(*) > 1', |
| 222 | - array ( |
|
| 222 | + array( |
|
| 223 | 223 | 'table1' => $table_name, |
| 224 | - 'table2' => $table_name.'_old', |
|
| 224 | + 'table2' => $table_name . '_old', |
|
| 225 | 225 | 'schema' => 'public', |
| 226 | 226 | ) |
| 227 | 227 | ); |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | $same_col[] = $row['column_name']; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $smcFunc['db_query']('',' |
|
| 235 | - INSERT INTO ' . $table_name .'(' |
|
| 234 | + $smcFunc['db_query']('', ' |
|
| 235 | + INSERT INTO ' . $table_name . '(' |
|
| 236 | 236 | . implode($same_col, ',') . |
| 237 | 237 | ') |
| 238 | 238 | SELECT '. implode($same_col, ',') . ' |
@@ -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. |
@@ -53,8 +54,9 @@ discard block |
||
| 53 | 54 | 'messages', 'moderator_groups', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', |
| 54 | 55 | 'pm_labeled_messages', 'pm_labels', 'pm_recipients', 'pm_rules', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys', |
| 55 | 56 | 'spiders', 'subscriptions', 'themes', 'topics', 'user_alerts', 'user_alerts_prefs', 'user_drafts', 'user_likes'); |
| 56 | - foreach ($reservedTables as $k => $table_name) |
|
| 57 | - $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 57 | + foreach ($reservedTables as $k => $table_name) { |
|
| 58 | + $reservedTables[$k] = strtolower($db_prefix . $table_name); |
|
| 59 | + } |
|
| 58 | 60 | |
| 59 | 61 | // We in turn may need the extra stuff. |
| 60 | 62 | db_extend('extra'); |
@@ -107,8 +109,9 @@ discard block |
||
| 107 | 109 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 108 | 110 | |
| 109 | 111 | // First - no way do we touch SMF tables. |
| 110 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 111 | - return false; |
|
| 112 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 112 | 115 | |
| 113 | 116 | // Log that we'll want to remove this on uninstall. |
| 114 | 117 | $db_package_log[] = array('remove_table', $table_name); |
@@ -118,9 +121,9 @@ discard block |
||
| 118 | 121 | if (in_array($full_table_name, $tables)) |
| 119 | 122 | { |
| 120 | 123 | // This is a sad day... drop the table? If not, return false (error) by default. |
| 121 | - if ($if_exists == 'overwrite') |
|
| 122 | - $smcFunc['db_drop_table']($table_name); |
|
| 123 | - else if ($if_exists == 'update') |
|
| 124 | + if ($if_exists == 'overwrite') { |
|
| 125 | + $smcFunc['db_drop_table']($table_name); |
|
| 126 | + } else if ($if_exists == 'update') |
|
| 124 | 127 | { |
| 125 | 128 | $smcFunc['db_drop_table']($table_name.'_old'); |
| 126 | 129 | $smcFunc['db_transaction']('begin'); |
@@ -132,47 +135,51 @@ discard block |
||
| 132 | 135 | ) |
| 133 | 136 | ); |
| 134 | 137 | $old_table_exists = true; |
| 138 | + } else { |
|
| 139 | + return $if_exists == 'ignore'; |
|
| 135 | 140 | } |
| 136 | - else |
|
| 137 | - return $if_exists == 'ignore'; |
|
| 138 | 141 | } |
| 139 | 142 | |
| 140 | 143 | // If we've got this far - good news - no table exists. We can build our own! |
| 141 | - if (!$db_trans) |
|
| 142 | - $smcFunc['db_transaction']('begin'); |
|
| 144 | + if (!$db_trans) { |
|
| 145 | + $smcFunc['db_transaction']('begin'); |
|
| 146 | + } |
|
| 143 | 147 | $table_query = 'CREATE TABLE ' . $table_name . "\n" . '('; |
| 144 | 148 | foreach ($columns as $column) |
| 145 | 149 | { |
| 146 | 150 | // If we have an auto increment do it! |
| 147 | 151 | if (!empty($column['auto'])) |
| 148 | 152 | { |
| 149 | - if (!$old_table_exists) |
|
| 150 | - $smcFunc['db_query']('', ' |
|
| 153 | + if (!$old_table_exists) { |
|
| 154 | + $smcFunc['db_query']('', ' |
|
| 151 | 155 | DROP SEQUENCE IF EXISTS ' . $table_name . '_seq', |
| 152 | 156 | array( |
| 153 | 157 | 'security_override' => true, |
| 154 | 158 | ) |
| 155 | 159 | ); |
| 160 | + } |
|
| 156 | 161 | |
| 157 | - if (!$old_table_exists) |
|
| 158 | - $smcFunc['db_query']('', ' |
|
| 162 | + if (!$old_table_exists) { |
|
| 163 | + $smcFunc['db_query']('', ' |
|
| 159 | 164 | CREATE SEQUENCE ' . $table_name . '_seq', |
| 160 | 165 | array( |
| 161 | 166 | 'security_override' => true, |
| 162 | 167 | ) |
| 163 | 168 | ); |
| 169 | + } |
|
| 164 | 170 | $default = 'default nextval(\'' . $table_name . '_seq\')'; |
| 171 | + } elseif (isset($column['default']) && $column['default'] !== null) { |
|
| 172 | + $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 173 | + } else { |
|
| 174 | + $default = ''; |
|
| 165 | 175 | } |
| 166 | - elseif (isset($column['default']) && $column['default'] !== null) |
|
| 167 | - $default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\''; |
|
| 168 | - else |
|
| 169 | - $default = ''; |
|
| 170 | 176 | |
| 171 | 177 | // Sort out the size... |
| 172 | 178 | $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; |
| 173 | 179 | list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']); |
| 174 | - if ($size !== null) |
|
| 175 | - $type = $type . '(' . $size . ')'; |
|
| 180 | + if ($size !== null) { |
|
| 181 | + $type = $type . '(' . $size . ')'; |
|
| 182 | + } |
|
| 176 | 183 | |
| 177 | 184 | // Now just put it together! |
| 178 | 185 | $table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ','; |
@@ -185,19 +192,21 @@ discard block |
||
| 185 | 192 | $columns = implode(',', $index['columns']); |
| 186 | 193 | |
| 187 | 194 | // Primary goes in the table... |
| 188 | - if (isset($index['type']) && $index['type'] == 'primary') |
|
| 189 | - $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 190 | - else |
|
| 195 | + if (isset($index['type']) && $index['type'] == 'primary') { |
|
| 196 | + $table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),'; |
|
| 197 | + } else |
|
| 191 | 198 | { |
| 192 | - if (empty($index['name'])) |
|
| 193 | - $index['name'] = implode('_', $index['columns']); |
|
| 199 | + if (empty($index['name'])) { |
|
| 200 | + $index['name'] = implode('_', $index['columns']); |
|
| 201 | + } |
|
| 194 | 202 | $index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')'; |
| 195 | 203 | } |
| 196 | 204 | } |
| 197 | 205 | |
| 198 | 206 | // No trailing commas! |
| 199 | - if (substr($table_query, -1) == ',') |
|
| 200 | - $table_query = substr($table_query, 0, -1); |
|
| 207 | + if (substr($table_query, -1) == ',') { |
|
| 208 | + $table_query = substr($table_query, 0, -1); |
|
| 209 | + } |
|
| 201 | 210 | |
| 202 | 211 | $table_query .= ')'; |
| 203 | 212 | |
@@ -242,18 +251,20 @@ discard block |
||
| 242 | 251 | } |
| 243 | 252 | |
| 244 | 253 | // And the indexes... |
| 245 | - foreach ($index_queries as $query) |
|
| 246 | - $smcFunc['db_query']('', $query, |
|
| 254 | + foreach ($index_queries as $query) { |
|
| 255 | + $smcFunc['db_query']('', $query, |
|
| 247 | 256 | array( |
| 248 | 257 | 'security_override' => true, |
| 249 | 258 | ) |
| 250 | 259 | ); |
| 260 | + } |
|
| 251 | 261 | |
| 252 | 262 | // Go, go power rangers! |
| 253 | 263 | $smcFunc['db_transaction']('commit'); |
| 254 | 264 | |
| 255 | - if ($old_table_exists) |
|
| 256 | - $smcFunc['db_drop_table']($table_name . '_old'); |
|
| 265 | + if ($old_table_exists) { |
|
| 266 | + $smcFunc['db_drop_table']($table_name . '_old'); |
|
| 267 | + } |
|
| 257 | 268 | |
| 258 | 269 | return true; |
| 259 | 270 | } |
@@ -278,8 +289,9 @@ discard block |
||
| 278 | 289 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 279 | 290 | |
| 280 | 291 | // God no - dropping one of these = bad. |
| 281 | - if (in_array(strtolower($table_name), $reservedTables)) |
|
| 282 | - return false; |
|
| 292 | + if (in_array(strtolower($table_name), $reservedTables)) { |
|
| 293 | + return false; |
|
| 294 | + } |
|
| 283 | 295 | |
| 284 | 296 | // Does it exist? |
| 285 | 297 | if (in_array($full_table_name, $smcFunc['db_list_tables']())) |
@@ -337,21 +349,24 @@ discard block |
||
| 337 | 349 | |
| 338 | 350 | // Does it exist - if so don't add it again! |
| 339 | 351 | $columns = $smcFunc['db_list_columns']($table_name, false); |
| 340 | - foreach ($columns as $column) |
|
| 341 | - if ($column == $column_info['name']) |
|
| 352 | + foreach ($columns as $column) { |
|
| 353 | + if ($column == $column_info['name']) |
|
| 342 | 354 | { |
| 343 | 355 | // If we're going to overwrite then use change column. |
| 344 | 356 | if ($if_exists == 'update') |
| 345 | 357 | return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
| 346 | - else |
|
| 347 | - return false; |
|
| 358 | + } |
|
| 359 | + else { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 348 | 362 | } |
| 349 | 363 | |
| 350 | 364 | // Get the specifics... |
| 351 | 365 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 352 | 366 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 353 | - if ($size !== null) |
|
| 354 | - $type = $type . '(' . $size . ')'; |
|
| 367 | + if ($size !== null) { |
|
| 368 | + $type = $type . '(' . $size . ')'; |
|
| 369 | + } |
|
| 355 | 370 | |
| 356 | 371 | // Now add the thing! |
| 357 | 372 | $query = ' |
@@ -366,11 +381,12 @@ discard block |
||
| 366 | 381 | // If there's more attributes they need to be done via a change on PostgreSQL. |
| 367 | 382 | unset($column_info['type'], $column_info['size']); |
| 368 | 383 | |
| 369 | - if (count($column_info) != 1) |
|
| 370 | - return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 371 | - else |
|
| 372 | - return true; |
|
| 373 | -} |
|
| 384 | + if (count($column_info) != 1) { |
|
| 385 | + return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info); |
|
| 386 | + } else { |
|
| 387 | + return true; |
|
| 388 | + } |
|
| 389 | + } |
|
| 374 | 390 | |
| 375 | 391 | /** |
| 376 | 392 | * Removes a column. |
@@ -389,8 +405,8 @@ discard block |
||
| 389 | 405 | |
| 390 | 406 | // Does it exist? |
| 391 | 407 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 392 | - foreach ($columns as $column) |
|
| 393 | - if ($column['name'] == $column_name) |
|
| 408 | + foreach ($columns as $column) { |
|
| 409 | + if ($column['name'] == $column_name) |
|
| 394 | 410 | { |
| 395 | 411 | // If there is an auto we need remove it! |
| 396 | 412 | if ($column['auto']) |
@@ -400,6 +416,7 @@ discard block |
||
| 400 | 416 | 'security_override' => true, |
| 401 | 417 | ) |
| 402 | 418 | ); |
| 419 | + } |
|
| 403 | 420 | |
| 404 | 421 | $smcFunc['db_query']('', ' |
| 405 | 422 | ALTER TABLE ' . $table_name . ' |
@@ -433,13 +450,15 @@ discard block |
||
| 433 | 450 | // Check it does exist! |
| 434 | 451 | $columns = $smcFunc['db_list_columns']($table_name, true); |
| 435 | 452 | $old_info = null; |
| 436 | - foreach ($columns as $column) |
|
| 437 | - if ($column['name'] == $old_column) |
|
| 453 | + foreach ($columns as $column) { |
|
| 454 | + if ($column['name'] == $old_column) |
|
| 438 | 455 | $old_info = $column; |
| 456 | + } |
|
| 439 | 457 | |
| 440 | 458 | // Nothing? |
| 441 | - if ($old_info == null) |
|
| 442 | - return false; |
|
| 459 | + if ($old_info == null) { |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 443 | 462 | |
| 444 | 463 | // Now we check each bit individually and ALTER as required. |
| 445 | 464 | if (isset($column_info['name']) && $column_info['name'] != $old_column) |
@@ -496,8 +515,9 @@ discard block |
||
| 496 | 515 | { |
| 497 | 516 | $column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null; |
| 498 | 517 | list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']); |
| 499 | - if ($size !== null) |
|
| 500 | - $type = $type . '(' . $size . ')'; |
|
| 518 | + if ($size !== null) { |
|
| 519 | + $type = $type . '(' . $size . ')'; |
|
| 520 | + } |
|
| 501 | 521 | |
| 502 | 522 | // The alter is a pain. |
| 503 | 523 | $smcFunc['db_transaction']('begin'); |
@@ -598,21 +618,23 @@ discard block |
||
| 598 | 618 | $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); |
| 599 | 619 | |
| 600 | 620 | // No columns = no index. |
| 601 | - if (empty($index_info['columns'])) |
|
| 602 | - return false; |
|
| 621 | + if (empty($index_info['columns'])) { |
|
| 622 | + return false; |
|
| 623 | + } |
|
| 603 | 624 | $columns = implode(',', $index_info['columns']); |
| 604 | 625 | |
| 605 | 626 | // No name - make it up! |
| 606 | 627 | if (empty($index_info['name'])) |
| 607 | 628 | { |
| 608 | 629 | // No need for primary. |
| 609 | - if (isset($index_info['type']) && $index_info['type'] == 'primary') |
|
| 610 | - $index_info['name'] = ''; |
|
| 611 | - else |
|
| 612 | - $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 630 | + if (isset($index_info['type']) && $index_info['type'] == 'primary') { |
|
| 631 | + $index_info['name'] = ''; |
|
| 632 | + } else { |
|
| 633 | + $index_info['name'] = $table_name . implode('_', $index_info['columns']); |
|
| 634 | + } |
|
| 635 | + } else { |
|
| 636 | + $index_info['name'] = $table_name . $index_info['name']; |
|
| 613 | 637 | } |
| 614 | - else |
|
| 615 | - $index_info['name'] = $table_name . $index_info['name']; |
|
| 616 | 638 | |
| 617 | 639 | // Log that we are going to want to remove this! |
| 618 | 640 | $db_package_log[] = array('remove_index', $table_name, $index_info['name']); |
@@ -625,10 +647,11 @@ discard block |
||
| 625 | 647 | if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary')) |
| 626 | 648 | { |
| 627 | 649 | // If we want to overwrite simply remove the current one then continue. |
| 628 | - if ($if_exists != 'update' || $index['type'] == 'primary') |
|
| 629 | - return false; |
|
| 630 | - else |
|
| 631 | - $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 650 | + if ($if_exists != 'update' || $index['type'] == 'primary') { |
|
| 651 | + return false; |
|
| 652 | + } else { |
|
| 653 | + $smcFunc['db_remove_index']($table_name, $index_info['name']); |
|
| 654 | + } |
|
| 632 | 655 | } |
| 633 | 656 | } |
| 634 | 657 | |
@@ -642,8 +665,7 @@ discard block |
||
| 642 | 665 | 'security_override' => true, |
| 643 | 666 | ) |
| 644 | 667 | ); |
| 645 | - } |
|
| 646 | - else |
|
| 668 | + } else |
|
| 647 | 669 | { |
| 648 | 670 | $smcFunc['db_query']('', ' |
| 649 | 671 | CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')', |
@@ -671,8 +693,9 @@ discard block |
||
| 671 | 693 | |
| 672 | 694 | // Better exist! |
| 673 | 695 | $indexes = $smcFunc['db_list_indexes']($table_name, true); |
| 674 | - if ($index_name != 'primary') |
|
| 675 | - $index_name = $table_name . '_' . $index_name; |
|
| 696 | + if ($index_name != 'primary') { |
|
| 697 | + $index_name = $table_name . '_' . $index_name; |
|
| 698 | + } |
|
| 676 | 699 | |
| 677 | 700 | foreach ($indexes as $index) |
| 678 | 701 | { |
@@ -736,8 +759,7 @@ discard block |
||
| 736 | 759 | 'datetime' => 'timestamp without time zone', |
| 737 | 760 | 'timestamp' => 'timestamp without time zone', |
| 738 | 761 | ); |
| 739 | - } |
|
| 740 | - else |
|
| 762 | + } else |
|
| 741 | 763 | { |
| 742 | 764 | $types = array( |
| 743 | 765 | 'character varying' => 'varchar', |
@@ -753,14 +775,16 @@ discard block |
||
| 753 | 775 | // Got it? Change it! |
| 754 | 776 | if (isset($types[$type_name])) |
| 755 | 777 | { |
| 756 | - if ($type_name == 'tinytext') |
|
| 757 | - $type_size = 255; |
|
| 778 | + if ($type_name == 'tinytext') { |
|
| 779 | + $type_size = 255; |
|
| 780 | + } |
|
| 758 | 781 | $type_name = $types[$type_name]; |
| 759 | 782 | } |
| 760 | 783 | |
| 761 | 784 | // Only char fields got size |
| 762 | - if (strpos($type_name, 'char') === false) |
|
| 763 | - $type_size = null; |
|
| 785 | + if (strpos($type_name, 'char') === false) { |
|
| 786 | + $type_size = null; |
|
| 787 | + } |
|
| 764 | 788 | |
| 765 | 789 | |
| 766 | 790 | return array($type_name, $type_size); |
@@ -816,8 +840,7 @@ discard block |
||
| 816 | 840 | if (!$detail) |
| 817 | 841 | { |
| 818 | 842 | $columns[] = $row['column_name']; |
| 819 | - } |
|
| 820 | - else |
|
| 843 | + } else |
|
| 821 | 844 | { |
| 822 | 845 | $auto = false; |
| 823 | 846 | // What is the default? |
@@ -825,11 +848,11 @@ discard block |
||
| 825 | 848 | { |
| 826 | 849 | $default = null; |
| 827 | 850 | $auto = true; |
| 851 | + } elseif (trim($row['column_default']) != '') { |
|
| 852 | + $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 853 | + } else { |
|
| 854 | + $default = null; |
|
| 828 | 855 | } |
| 829 | - elseif (trim($row['column_default']) != '') |
|
| 830 | - $default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::')); |
|
| 831 | - else |
|
| 832 | - $default = null; |
|
| 833 | 856 | |
| 834 | 857 | // Make the type generic. |
| 835 | 858 | list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true); |
@@ -880,26 +903,30 @@ discard block |
||
| 880 | 903 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 881 | 904 | { |
| 882 | 905 | // Try get the columns that make it up. |
| 883 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
| 884 | - continue; |
|
| 906 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
| 907 | + continue; |
|
| 908 | + } |
|
| 885 | 909 | |
| 886 | 910 | $columns = explode(',', $matches[1]); |
| 887 | 911 | |
| 888 | - if (empty($columns)) |
|
| 889 | - continue; |
|
| 912 | + if (empty($columns)) { |
|
| 913 | + continue; |
|
| 914 | + } |
|
| 890 | 915 | |
| 891 | - foreach ($columns as $k => $v) |
|
| 892 | - $columns[$k] = trim($v); |
|
| 916 | + foreach ($columns as $k => $v) { |
|
| 917 | + $columns[$k] = trim($v); |
|
| 918 | + } |
|
| 893 | 919 | |
| 894 | 920 | // Fix up the name to be consistent cross databases |
| 895 | - if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) |
|
| 896 | - $row['name'] = 'PRIMARY'; |
|
| 897 | - else |
|
| 898 | - $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 921 | + if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { |
|
| 922 | + $row['name'] = 'PRIMARY'; |
|
| 923 | + } else { |
|
| 924 | + $row['name'] = str_replace($table_name . '_', '', $row['name']); |
|
| 925 | + } |
|
| 899 | 926 | |
| 900 | - if (!$detail) |
|
| 901 | - $indexes[] = $row['name']; |
|
| 902 | - else |
|
| 927 | + if (!$detail) { |
|
| 928 | + $indexes[] = $row['name']; |
|
| 929 | + } else |
|
| 903 | 930 | { |
| 904 | 931 | $indexes[$row['name']] = array( |
| 905 | 932 | 'name' => $row['name'], |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
| 4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
| 4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
| 5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
| 6 | -else |
|
| 6 | +} else { |
|
| 7 | 7 | exit; |
| 8 | +} |
|
| 8 | 9 | |
| 9 | 10 | ?> |
| 10 | 11 | \ No newline at end of file |