@@ -37,9 +37,10 @@ discard block |
||
37 | 37 | echo ' |
38 | 38 | <optgroup label="', $category['name'], '">'; |
39 | 39 | |
40 | - foreach ($category['boards'] as $board) |
|
41 | - echo ' |
|
40 | + foreach ($category['boards'] as $board) { |
|
41 | + echo ' |
|
42 | 42 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', $board['id'] == $context['current_board'] ? ' disabled' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level']-1) . '=> ' : '', $board['name'], '</option>'; |
43 | + } |
|
43 | 44 | echo ' |
44 | 45 | </optgroup>'; |
45 | 46 | } |
@@ -70,9 +71,10 @@ discard block |
||
70 | 71 | </div><!-- .move_topic --> |
71 | 72 | </div><!-- .windowbg -->'; |
72 | 73 | |
73 | - if ($context['back_to_topic']) |
|
74 | - echo ' |
|
74 | + if ($context['back_to_topic']) { |
|
75 | + echo ' |
|
75 | 76 | <input type="hidden" name="goback" value="1">'; |
77 | + } |
|
76 | 78 | |
77 | 79 | echo ' |
78 | 80 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -125,10 +127,10 @@ discard block |
||
125 | 127 | <option value="86400">', $txt['two_months'], '</option> |
126 | 128 | </select> |
127 | 129 | </dd>'; |
128 | - } |
|
129 | - else |
|
130 | - echo ' |
|
130 | + } else { |
|
131 | + echo ' |
|
131 | 132 | <input type="hidden" name="redirect_expires" value="0">'; |
133 | + } |
|
132 | 134 | |
133 | 135 | echo ' |
134 | 136 | </dl> |
@@ -207,9 +209,10 @@ discard block |
||
207 | 209 | echo ' |
208 | 210 | <optgroup label="', $cat['name'], '">'; |
209 | 211 | |
210 | - foreach ($cat['boards'] as $board) |
|
211 | - echo ' |
|
212 | + foreach ($cat['boards'] as $board) { |
|
213 | + echo ' |
|
212 | 214 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], '</option>'; |
215 | + } |
|
213 | 216 | |
214 | 217 | echo ' |
215 | 218 | </optgroup>'; |
@@ -219,9 +222,9 @@ discard block |
||
219 | 222 | <input type="hidden" name="from" value="' . $context['origin_topic'] . '"> |
220 | 223 | <input type="submit" value="', $txt['go'], '" class="button"> |
221 | 224 | </form>'; |
225 | + } else { |
|
226 | + echo $txt['target_below']; |
|
222 | 227 | } |
223 | - else |
|
224 | - echo $txt['target_below']; |
|
225 | 228 | |
226 | 229 | echo ' </h4> |
227 | 230 | </div><!-- .title_bar --> |
@@ -239,12 +242,13 @@ discard block |
||
239 | 242 | |
240 | 243 | $merge_button = create_button('merge', 'merge', ''); |
241 | 244 | |
242 | - foreach ($context['topics'] as $topic) |
|
243 | - echo ' |
|
245 | + foreach ($context['topics'] as $topic) { |
|
246 | + echo ' |
|
244 | 247 | <li> |
245 | 248 | <a href="', $scripturl, '?action=mergetopics;sa=options;board=', $context['current_board'], '.0;from=', $context['origin_topic'], ';to=', $topic['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $merge_button, '</a> |
246 | 249 | <a href="', $scripturl, '?topic=', $topic['id'], '.0" target="_blank" rel="noopener">', $topic['subject'], '</a> ', $txt['started_by'], ' ', $topic['poster']['link'], ' |
247 | 250 | </li>'; |
251 | + } |
|
248 | 252 | |
249 | 253 | echo ' |
250 | 254 | </ul> |
@@ -255,9 +259,10 @@ discard block |
||
255 | 259 | </div>'; |
256 | 260 | } |
257 | 261 | // Just a nice "There aren't any topics" message |
258 | - else |
|
259 | - echo ' |
|
262 | + else { |
|
263 | + echo ' |
|
260 | 264 | <div class="windowbg">', $txt['topic_alert_none'], '</div>'; |
265 | + } |
|
261 | 266 | |
262 | 267 | echo ' |
263 | 268 | <br> |
@@ -307,8 +312,8 @@ discard block |
||
307 | 312 | </thead> |
308 | 313 | <tbody>'; |
309 | 314 | |
310 | - foreach ($context['topics'] as $topic) |
|
311 | - echo ' |
|
315 | + foreach ($context['topics'] as $topic) { |
|
316 | + echo ' |
|
312 | 317 | <tr class="windowbg"> |
313 | 318 | <td> |
314 | 319 | <input type="checkbox" name="topics[]" value="' . $topic['id'] . '" checked> |
@@ -328,6 +333,7 @@ discard block |
||
328 | 333 | <input type="checkbox" name="notifications[]" value="' . $topic['id'] . '" checked> |
329 | 334 | </td> |
330 | 335 | </tr>'; |
336 | + } |
|
331 | 337 | echo ' |
332 | 338 | </tbody> |
333 | 339 | </table> |
@@ -337,9 +343,10 @@ discard block |
||
337 | 343 | <legend>', $txt['merge_select_subject'], '</legend> |
338 | 344 | <select name="subject" onchange="this.form.custom_subject.style.display = (this.options[this.selectedIndex].value != 0) ? \'none\': \'\' ;">'; |
339 | 345 | |
340 | - foreach ($context['topics'] as $topic) |
|
341 | - echo ' |
|
346 | + foreach ($context['topics'] as $topic) { |
|
347 | + echo ' |
|
342 | 348 | <option value="', $topic['id'], '"' . ($topic['selected'] ? ' selected' : '') . '>', $topic['subject'], '</option>'; |
349 | + } |
|
343 | 350 | echo ' |
344 | 351 | <option value="0">', $txt['merge_custom_subject'], ':</option> |
345 | 352 | </select> |
@@ -358,11 +365,12 @@ discard block |
||
358 | 365 | <legend>', $txt['merge_select_target_board'], '</legend> |
359 | 366 | <ul>'; |
360 | 367 | |
361 | - foreach ($context['boards'] as $board) |
|
362 | - echo ' |
|
368 | + foreach ($context['boards'] as $board) { |
|
369 | + echo ' |
|
363 | 370 | <li> |
364 | 371 | <input type="radio" name="board" value="' . $board['id'] . '"' . ($board['selected'] ? ' checked' : '') . '> ' . $board['name'] . ' |
365 | 372 | </li>'; |
373 | + } |
|
366 | 374 | echo ' |
367 | 375 | </ul> |
368 | 376 | </fieldset>'; |
@@ -374,11 +382,12 @@ discard block |
||
374 | 382 | <legend>' . $txt['merge_select_poll'] . '</legend> |
375 | 383 | <ul>'; |
376 | 384 | |
377 | - foreach ($context['polls'] as $poll) |
|
378 | - echo ' |
|
385 | + foreach ($context['polls'] as $poll) { |
|
386 | + echo ' |
|
379 | 387 | <li> |
380 | 388 | <input type="radio" name="poll" value="' . $poll['id'] . '"' . ($poll['selected'] ? ' checked' : '') . '> ' . $poll['question'] . ' (' . $txt['topic'] . ': <a href="' . $scripturl . '?topic=' . $poll['topic']['id'] . '.0" target="_blank" rel="noopener">' . $poll['topic']['subject'] . '</a>) |
381 | 389 | </li>'; |
390 | + } |
|
382 | 391 | echo ' |
383 | 392 | <li> |
384 | 393 | <input type="radio" name="poll" value="-1"> (' . $txt['merge_no_poll'] . ') |
@@ -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> |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false, 'minimize' => true), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -170,16 +181,19 @@ discard block |
||
170 | 181 | if (in_array('website', $reg_fields)) |
171 | 182 | { |
172 | 183 | unset($reg_fields['website']); |
173 | - if (isset($_POST['website_title'])) |
|
174 | - $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
175 | - if (isset($_POST['website_url'])) |
|
176 | - $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
184 | + if (isset($_POST['website_title'])) { |
|
185 | + $cur_profile['website_title'] = $smcFunc['htmlspecialchars']($_POST['website_title']); |
|
186 | + } |
|
187 | + if (isset($_POST['website_url'])) { |
|
188 | + $cur_profile['website_url'] = $smcFunc['htmlspecialchars']($_POST['website_url']); |
|
189 | + } |
|
177 | 190 | } |
178 | 191 | |
179 | 192 | // We might have had some submissions on this front - go check. |
180 | - foreach ($reg_fields as $field) |
|
181 | - if (isset($_POST[$field])) |
|
193 | + foreach ($reg_fields as $field) { |
|
194 | + if (isset($_POST[$field])) |
|
182 | 195 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
196 | + } |
|
183 | 197 | |
184 | 198 | // Load all the fields in question. |
185 | 199 | setupProfileContext($reg_fields); |
@@ -196,8 +210,9 @@ discard block |
||
196 | 210 | $context['visual_verification_id'] = $verificationOptions['id']; |
197 | 211 | } |
198 | 212 | // Otherwise we have nothing to show. |
199 | - else |
|
200 | - $context['visual_verification'] = false; |
|
213 | + else { |
|
214 | + $context['visual_verification'] = false; |
|
215 | + } |
|
201 | 216 | |
202 | 217 | |
203 | 218 | $context += array( |
@@ -208,8 +223,9 @@ discard block |
||
208 | 223 | |
209 | 224 | // Were there any errors? |
210 | 225 | $context['registration_errors'] = array(); |
211 | - if (!empty($reg_errors)) |
|
212 | - $context['registration_errors'] = $reg_errors; |
|
226 | + if (!empty($reg_errors)) { |
|
227 | + $context['registration_errors'] = $reg_errors; |
|
228 | + } |
|
213 | 229 | |
214 | 230 | createToken('register'); |
215 | 231 | } |
@@ -226,27 +242,32 @@ discard block |
||
226 | 242 | validateToken('register'); |
227 | 243 | |
228 | 244 | // Check to ensure we're forcing SSL for authentication |
229 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) |
|
230 | - fatal_lang_error('register_ssl_required'); |
|
245 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) { |
|
246 | + fatal_lang_error('register_ssl_required'); |
|
247 | + } |
|
231 | 248 | |
232 | 249 | // Start collecting together any errors. |
233 | 250 | $reg_errors = array(); |
234 | 251 | |
235 | 252 | // You can't register if it's disabled. |
236 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
237 | - fatal_lang_error('registration_disabled', false); |
|
253 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
254 | + fatal_lang_error('registration_disabled', false); |
|
255 | + } |
|
238 | 256 | |
239 | 257 | // Well, if you don't agree, you can't register. |
240 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
241 | - redirectexit(); |
|
258 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
259 | + redirectexit(); |
|
260 | + } |
|
242 | 261 | |
243 | 262 | // Make sure they came from *somewhere*, have a session. |
244 | - if (!isset($_SESSION['old_url'])) |
|
245 | - redirectexit('action=signup'); |
|
263 | + if (!isset($_SESSION['old_url'])) { |
|
264 | + redirectexit('action=signup'); |
|
265 | + } |
|
246 | 266 | |
247 | 267 | // If we don't require an agreement, we need a extra check for coppa. |
248 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
249 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
268 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
269 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
270 | + } |
|
250 | 271 | // Are they under age, and under age users are banned? |
251 | 272 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
252 | 273 | { |
@@ -255,8 +276,9 @@ discard block |
||
255 | 276 | } |
256 | 277 | |
257 | 278 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
258 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
259 | - redirectexit('action=signup'); |
|
279 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
280 | + redirectexit('action=signup'); |
|
281 | + } |
|
260 | 282 | // Failing that, check the time on it. |
261 | 283 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
262 | 284 | { |
@@ -276,8 +298,9 @@ discard block |
||
276 | 298 | if (is_array($context['visual_verification'])) |
277 | 299 | { |
278 | 300 | loadLanguage('Errors'); |
279 | - foreach ($context['visual_verification'] as $error) |
|
280 | - $reg_errors[] = $txt['error_' . $error]; |
|
301 | + foreach ($context['visual_verification'] as $error) { |
|
302 | + $reg_errors[] = $txt['error_' . $error]; |
|
303 | + } |
|
281 | 304 | } |
282 | 305 | } |
283 | 306 | |
@@ -286,14 +309,16 @@ discard block |
||
286 | 309 | if (!is_array($_POST[$key])) |
287 | 310 | { |
288 | 311 | // For UTF-8, replace any kind of space with a normal space, and remove any kind of control character (incl. "\n" and "\r"), then trim. |
289 | - if ($context['utf8']) |
|
290 | - $_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key])); |
|
312 | + if ($context['utf8']) { |
|
313 | + $_POST[$key] = $smcFunc['htmltrim'](preg_replace(array('~\p{Z}+~u', '~\p{C}+~u'), array(' ', ''), $_POST[$key])); |
|
314 | + } |
|
291 | 315 | // Otherwise, just remove "\n" and "\r", then trim. |
292 | - else |
|
293 | - $_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
316 | + else { |
|
317 | + $_POST[$key] = $smcFunc['htmltrim'](str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
318 | + } |
|
319 | + } else { |
|
320 | + $_POST[$key] = htmltrim__recursive($_POST[$key]); |
|
294 | 321 | } |
295 | - else |
|
296 | - $_POST[$key] = htmltrim__recursive($_POST[$key]); |
|
297 | 322 | } |
298 | 323 | |
299 | 324 | // Collect all extra registration fields someone might have filled in. |
@@ -328,13 +353,15 @@ discard block |
||
328 | 353 | $possible_strings = array_merge(array('website_url', 'website_title'), $possible_strings); |
329 | 354 | |
330 | 355 | // Make sure their website URL is squeaky clean |
331 | - if (isset($_POST['website_url'])) |
|
332 | - $_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url'])); |
|
356 | + if (isset($_POST['website_url'])) { |
|
357 | + $_POST['website_url'] = (string) validate_iri(sanitize_iri($_POST['website_url'])); |
|
358 | + } |
|
333 | 359 | } |
334 | 360 | } |
335 | 361 | |
336 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
337 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
362 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
363 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
364 | + } |
|
338 | 365 | |
339 | 366 | // Needed for isReservedName() and registerMember(). |
340 | 367 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -343,8 +370,9 @@ discard block |
||
343 | 370 | if (isset($_POST['real_name'])) |
344 | 371 | { |
345 | 372 | // Are you already allowed to edit the displayed name? |
346 | - if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) |
|
347 | - $canEditDisplayName = true; |
|
373 | + if (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')) { |
|
374 | + $canEditDisplayName = true; |
|
375 | + } |
|
348 | 376 | |
349 | 377 | // If you are a guest, will you be allowed to once you register? |
350 | 378 | else |
@@ -363,32 +391,37 @@ discard block |
||
363 | 391 | } |
364 | 392 | |
365 | 393 | // Only set it if you can and if we are sure it is good |
366 | - if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
367 | - $possible_strings[] = 'real_name'; |
|
394 | + if ($canEditDisplayName && $smcFunc['htmltrim']($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
395 | + $possible_strings[] = 'real_name'; |
|
396 | + } |
|
368 | 397 | } |
369 | 398 | |
370 | 399 | // Handle a string as a birthdate... |
371 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
372 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
400 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
401 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
402 | + } |
|
373 | 403 | // Or birthdate parts... |
374 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
375 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
404 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
405 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
406 | + } |
|
376 | 407 | |
377 | 408 | // Validate the passed language file. |
378 | 409 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
379 | 410 | { |
380 | 411 | // Do we have any languages? |
381 | - if (empty($context['languages'])) |
|
382 | - getLanguages(); |
|
412 | + if (empty($context['languages'])) { |
|
413 | + getLanguages(); |
|
414 | + } |
|
383 | 415 | |
384 | 416 | // Did we find it? |
385 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
386 | - $_SESSION['language'] = $_POST['lngfile']; |
|
387 | - else |
|
417 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
418 | + $_SESSION['language'] = $_POST['lngfile']; |
|
419 | + } else { |
|
420 | + unset($_POST['lngfile']); |
|
421 | + } |
|
422 | + } else { |
|
388 | 423 | unset($_POST['lngfile']); |
389 | 424 | } |
390 | - else |
|
391 | - unset($_POST['lngfile']); |
|
392 | 425 | |
393 | 426 | // Set the options needed for registration. |
394 | 427 | $regOptions = array( |
@@ -408,22 +441,27 @@ discard block |
||
408 | 441 | ); |
409 | 442 | |
410 | 443 | // Include the additional options that might have been filled in. |
411 | - foreach ($possible_strings as $var) |
|
412 | - if (isset($_POST[$var])) |
|
444 | + foreach ($possible_strings as $var) { |
|
445 | + if (isset($_POST[$var])) |
|
413 | 446 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
414 | - foreach ($possible_ints as $var) |
|
415 | - if (isset($_POST[$var])) |
|
447 | + } |
|
448 | + foreach ($possible_ints as $var) { |
|
449 | + if (isset($_POST[$var])) |
|
416 | 450 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
417 | - foreach ($possible_floats as $var) |
|
418 | - if (isset($_POST[$var])) |
|
451 | + } |
|
452 | + foreach ($possible_floats as $var) { |
|
453 | + if (isset($_POST[$var])) |
|
419 | 454 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
420 | - foreach ($possible_bools as $var) |
|
421 | - if (isset($_POST[$var])) |
|
455 | + } |
|
456 | + foreach ($possible_bools as $var) { |
|
457 | + if (isset($_POST[$var])) |
|
422 | 458 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
459 | + } |
|
423 | 460 | |
424 | 461 | // Registration options are always default options... |
425 | - if (isset($_POST['default_options'])) |
|
426 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
462 | + if (isset($_POST['default_options'])) { |
|
463 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
464 | + } |
|
427 | 465 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
428 | 466 | |
429 | 467 | // Make sure they are clean, dammit! |
@@ -443,12 +481,14 @@ discard block |
||
443 | 481 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
444 | 482 | { |
445 | 483 | // Don't allow overriding of the theme variables. |
446 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
447 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
484 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
485 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
486 | + } |
|
448 | 487 | |
449 | 488 | // Not actually showing it then? |
450 | - if (!$row['show_reg']) |
|
451 | - continue; |
|
489 | + if (!$row['show_reg']) { |
|
490 | + continue; |
|
491 | + } |
|
452 | 492 | |
453 | 493 | // Prepare the value! |
454 | 494 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -457,24 +497,27 @@ discard block |
||
457 | 497 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
458 | 498 | { |
459 | 499 | // Is it too long? |
460 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
461 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
500 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
501 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
502 | + } |
|
462 | 503 | |
463 | 504 | // Any masks to apply? |
464 | 505 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
465 | 506 | { |
466 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
467 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
468 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
469 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
470 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
471 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
507 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
508 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
509 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
510 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
511 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
512 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
513 | + } |
|
472 | 514 | } |
473 | 515 | } |
474 | 516 | |
475 | 517 | // Is this required but not there? |
476 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
477 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
518 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
519 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
520 | + } |
|
478 | 521 | } |
479 | 522 | $smcFunc['db_free_result']($request); |
480 | 523 | |
@@ -482,8 +525,9 @@ discard block |
||
482 | 525 | if (!empty($custom_field_errors)) |
483 | 526 | { |
484 | 527 | loadLanguage('Errors'); |
485 | - foreach ($custom_field_errors as $error) |
|
486 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
528 | + foreach ($custom_field_errors as $error) { |
|
529 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
530 | + } |
|
487 | 531 | } |
488 | 532 | |
489 | 533 | // Lets check for other errors before trying to register the member. |
@@ -528,8 +572,9 @@ discard block |
||
528 | 572 | } |
529 | 573 | |
530 | 574 | // If COPPA has been selected then things get complicated, setup the template. |
531 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
532 | - redirectexit('action=coppa;member=' . $memberID); |
|
575 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
576 | + redirectexit('action=coppa;member=' . $memberID); |
|
577 | + } |
|
533 | 578 | // Basic template variable setup. |
534 | 579 | elseif (!empty($modSettings['registration_method'])) |
535 | 580 | { |
@@ -541,8 +586,7 @@ discard block |
||
541 | 586 | 'sub_template' => 'after', |
542 | 587 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
543 | 588 | ); |
544 | - } |
|
545 | - else |
|
589 | + } else |
|
546 | 590 | { |
547 | 591 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
548 | 592 | |
@@ -562,16 +606,18 @@ discard block |
||
562 | 606 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
563 | 607 | |
564 | 608 | // Logged in users should not bother to activate their accounts |
565 | - if (!empty($user_info['id'])) |
|
566 | - redirectexit(); |
|
609 | + if (!empty($user_info['id'])) { |
|
610 | + redirectexit(); |
|
611 | + } |
|
567 | 612 | |
568 | 613 | loadLanguage('Login'); |
569 | 614 | loadTemplate('Login'); |
570 | 615 | |
571 | 616 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
572 | 617 | { |
573 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
574 | - fatal_lang_error('no_access', false); |
|
618 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
619 | + fatal_lang_error('no_access', false); |
|
620 | + } |
|
575 | 621 | |
576 | 622 | $context['member_id'] = 0; |
577 | 623 | $context['sub_template'] = 'resend'; |
@@ -611,11 +657,13 @@ discard block |
||
611 | 657 | // Change their email address? (they probably tried a fake one first :P.) |
612 | 658 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
613 | 659 | { |
614 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
615 | - fatal_lang_error('no_access', false); |
|
660 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
661 | + fatal_lang_error('no_access', false); |
|
662 | + } |
|
616 | 663 | |
617 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
618 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
664 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
665 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
666 | + } |
|
619 | 667 | |
620 | 668 | // Make sure their email isn't banned. |
621 | 669 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -631,8 +679,9 @@ discard block |
||
631 | 679 | ) |
632 | 680 | ); |
633 | 681 | |
634 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
635 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
682 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
683 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
684 | + } |
|
636 | 685 | $smcFunc['db_free_result']($request); |
637 | 686 | |
638 | 687 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -670,9 +719,9 @@ discard block |
||
670 | 719 | // Quit if this code is not right. |
671 | 720 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
672 | 721 | { |
673 | - if (!empty($row['is_activated'])) |
|
674 | - fatal_lang_error('already_activated', false); |
|
675 | - elseif ($row['validation_code'] == '') |
|
722 | + if (!empty($row['is_activated'])) { |
|
723 | + fatal_lang_error('already_activated', false); |
|
724 | + } elseif ($row['validation_code'] == '') |
|
676 | 725 | { |
677 | 726 | loadLanguage('Profile'); |
678 | 727 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -722,8 +771,9 @@ discard block |
||
722 | 771 | loadTemplate('Register'); |
723 | 772 | |
724 | 773 | // No User ID?? |
725 | - if (!isset($_GET['member'])) |
|
726 | - fatal_lang_error('no_access', false); |
|
774 | + if (!isset($_GET['member'])) { |
|
775 | + fatal_lang_error('no_access', false); |
|
776 | + } |
|
727 | 777 | |
728 | 778 | // Get the user details... |
729 | 779 | $request = $smcFunc['db_query']('', ' |
@@ -736,8 +786,9 @@ discard block |
||
736 | 786 | 'is_coppa' => 5, |
737 | 787 | ) |
738 | 788 | ); |
739 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
740 | - fatal_lang_error('no_access', false); |
|
789 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
790 | + fatal_lang_error('no_access', false); |
|
791 | + } |
|
741 | 792 | list ($username) = $smcFunc['db_fetch_row']($request); |
742 | 793 | $smcFunc['db_free_result']($request); |
743 | 794 | |
@@ -775,8 +826,7 @@ discard block |
||
775 | 826 | echo $data; |
776 | 827 | obExit(false); |
777 | 828 | } |
778 | - } |
|
779 | - else |
|
829 | + } else |
|
780 | 830 | { |
781 | 831 | $context += array( |
782 | 832 | 'page_title' => $txt['coppa_title'], |
@@ -829,8 +879,9 @@ discard block |
||
829 | 879 | { |
830 | 880 | require_once($sourcedir . '/Subs-Graphics.php'); |
831 | 881 | |
832 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
833 | - send_http_status(400); |
|
882 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
883 | + send_http_status(400); |
|
884 | + } |
|
834 | 885 | |
835 | 886 | // Otherwise just show a pre-defined letter. |
836 | 887 | elseif (isset($_REQUEST['letter'])) |
@@ -848,14 +899,13 @@ discard block |
||
848 | 899 | header('content-type: image/gif'); |
849 | 900 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
850 | 901 | } |
851 | - } |
|
852 | - |
|
853 | - elseif ($_REQUEST['format'] === '.wav') |
|
902 | + } elseif ($_REQUEST['format'] === '.wav') |
|
854 | 903 | { |
855 | 904 | require_once($sourcedir . '/Subs-Sound.php'); |
856 | 905 | |
857 | - if (!createWaveFile($code)) |
|
858 | - send_http_status(400); |
|
906 | + if (!createWaveFile($code)) { |
|
907 | + send_http_status(400); |
|
908 | + } |
|
859 | 909 | } |
860 | 910 | |
861 | 911 | // We all die one day... |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Creates a wave file that spells the letters of $word. |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | global $settings, $user_info; |
33 | 34 | |
34 | 35 | // Allow max 2 requests per 20 seconds. |
35 | - if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) |
|
36 | - die(send_http_status(400)); |
|
36 | + if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) { |
|
37 | + die(send_http_status(400)); |
|
38 | + } |
|
37 | 39 | cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); |
38 | 40 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
39 | 41 | |
@@ -42,16 +44,19 @@ discard block |
||
42 | 44 | mt_srand(end($tmp)); |
43 | 45 | |
44 | 46 | // Try to see if there's a sound font in the user's language. |
45 | - if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) |
|
46 | - $sound_language = $user_info['language']; |
|
47 | + if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) { |
|
48 | + $sound_language = $user_info['language']; |
|
49 | + } |
|
47 | 50 | |
48 | 51 | // English should be there. |
49 | - elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) |
|
50 | - $sound_language = 'english'; |
|
52 | + elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) { |
|
53 | + $sound_language = 'english'; |
|
54 | + } |
|
51 | 55 | |
52 | 56 | // Guess not... |
53 | - else |
|
54 | - return false; |
|
57 | + else { |
|
58 | + return false; |
|
59 | + } |
|
55 | 60 | |
56 | 61 | // File names are in lower case so lets make sure that we are only using a lower case string |
57 | 62 | $word = strtolower($word); |
@@ -61,20 +66,25 @@ discard block |
||
61 | 66 | for ($i = 0; $i < strlen($word); $i++) |
62 | 67 | { |
63 | 68 | $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); |
64 | - if (strpos($sound_letter, 'data') === false) |
|
65 | - return false; |
|
69 | + if (strpos($sound_letter, 'data') === false) { |
|
70 | + return false; |
|
71 | + } |
|
66 | 72 | |
67 | 73 | $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); |
68 | 74 | switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) |
69 | 75 | { |
70 | - case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
|
71 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
72 | - $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
76 | + case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) { |
|
77 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); |
|
78 | + } |
|
79 | + $k < $m; $k++) { |
|
80 | + $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); |
|
81 | + } |
|
73 | 82 | break; |
74 | 83 | |
75 | 84 | case 1: |
76 | - for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) |
|
77 | - $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
85 | + for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) { |
|
86 | + $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); |
|
87 | + } |
|
78 | 88 | $sound_word .= str_repeat($sound_letter{$n}, 2); |
79 | 89 | break; |
80 | 90 | |
@@ -82,10 +92,12 @@ discard block |
||
82 | 92 | $shift = 0; |
83 | 93 | for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) |
84 | 94 | { |
85 | - if (mt_rand(0, 10) === 0) |
|
86 | - $shift += mt_rand(-3, 3); |
|
87 | - for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) |
|
88 | - $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
95 | + if (mt_rand(0, 10) === 0) { |
|
96 | + $shift += mt_rand(-3, 3); |
|
97 | + } |
|
98 | + for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) { |
|
99 | + $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); |
|
100 | + } |
|
89 | 101 | } |
90 | 102 | break; |
91 | 103 | } |
@@ -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 | * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count. |
@@ -40,11 +41,11 @@ discard block |
||
40 | 41 | |
41 | 42 | if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0) |
42 | 43 | { |
43 | - if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') |
|
44 | - $modSettings['enableCompressedOutput'] = 0; |
|
45 | - |
|
46 | - else |
|
47 | - ob_start('ob_gzhandler'); |
|
44 | + if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') { |
|
45 | + $modSettings['enableCompressedOutput'] = 0; |
|
46 | + } else { |
|
47 | + ob_start('ob_gzhandler'); |
|
48 | + } |
|
48 | 49 | } |
49 | 50 | |
50 | 51 | if (empty($modSettings['enableCompressedOutput'])) |
@@ -76,8 +77,9 @@ discard block |
||
76 | 77 | } |
77 | 78 | |
78 | 79 | // Use cache when possible. |
79 | - if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) |
|
80 | - list($file, $thumbFile) = $cache; |
|
80 | + if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) { |
|
81 | + list($file, $thumbFile) = $cache; |
|
82 | + } |
|
81 | 83 | |
82 | 84 | // Get the info from the DB. |
83 | 85 | if (empty($file) || empty($thumbFile) && !empty($file['id_thumb'])) |
@@ -85,10 +87,9 @@ discard block |
||
85 | 87 | // Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request. |
86 | 88 | $attachRequest = null; |
87 | 89 | call_integration_hook('integrate_download_request', array(&$attachRequest)); |
88 | - if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) |
|
89 | - $request = $attachRequest; |
|
90 | - |
|
91 | - else |
|
90 | + if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) { |
|
91 | + $request = $attachRequest; |
|
92 | + } else |
|
92 | 93 | { |
93 | 94 | // Make sure this attachment is on this board and load its info while we are at it. |
94 | 95 | $request = $smcFunc['db_query']('', ' |
@@ -181,13 +182,15 @@ discard block |
||
181 | 182 | } |
182 | 183 | |
183 | 184 | // Cache it. |
184 | - if (!empty($file) || !empty($thumbFile)) |
|
185 | - cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
185 | + if (!empty($file) || !empty($thumbFile)) { |
|
186 | + cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900)); |
|
187 | + } |
|
186 | 188 | } |
187 | 189 | |
188 | 190 | // Replace the normal file with its thumbnail if it has one! |
189 | - if (!empty($showThumb) && !empty($thumbFile)) |
|
190 | - $file = $thumbFile; |
|
191 | + if (!empty($showThumb) && !empty($thumbFile)) { |
|
192 | + $file = $thumbFile; |
|
193 | + } |
|
191 | 194 | |
192 | 195 | // No point in a nicer message, because this is supposed to be an attachment anyway... |
193 | 196 | if (!file_exists($file['filePath'])) |
@@ -237,8 +240,8 @@ discard block |
||
237 | 240 | } |
238 | 241 | |
239 | 242 | // Update the download counter (unless it's a thumbnail or resuming an incomplete download). |
240 | - if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) |
|
241 | - $smcFunc['db_query']('', ' |
|
243 | + if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) { |
|
244 | + $smcFunc['db_query']('', ' |
|
242 | 245 | UPDATE {db_prefix}attachments |
243 | 246 | SET downloads = downloads + 1 |
244 | 247 | WHERE id_attach = {int:id_attach}', |
@@ -246,12 +249,14 @@ discard block |
||
246 | 249 | 'id_attach' => $attachId, |
247 | 250 | ) |
248 | 251 | ); |
252 | + } |
|
249 | 253 | |
250 | 254 | // Send the attachment headers. |
251 | 255 | header('pragma: '); |
252 | 256 | |
253 | - if (!isBrowser('gecko')) |
|
254 | - header('content-transfer-encoding: binary'); |
|
257 | + if (!isBrowser('gecko')) { |
|
258 | + header('content-transfer-encoding: binary'); |
|
259 | + } |
|
255 | 260 | |
256 | 261 | header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); |
257 | 262 | header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT'); |
@@ -260,18 +265,19 @@ discard block |
||
260 | 265 | header('etag: ' . $eTag); |
261 | 266 | |
262 | 267 | // Make sure the mime type warrants an inline display. |
263 | - if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) |
|
264 | - unset($_REQUEST['image']); |
|
268 | + if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) { |
|
269 | + unset($_REQUEST['image']); |
|
270 | + } |
|
265 | 271 | |
266 | 272 | // Does this have a mime type? |
267 | - elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) |
|
268 | - header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
269 | - |
|
270 | - else |
|
273 | + elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) { |
|
274 | + header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp'))); |
|
275 | + } else |
|
271 | 276 | { |
272 | 277 | header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream')); |
273 | - if (isset($_REQUEST['image'])) |
|
274 | - unset($_REQUEST['image']); |
|
278 | + if (isset($_REQUEST['image'])) { |
|
279 | + unset($_REQUEST['image']); |
|
280 | + } |
|
275 | 281 | } |
276 | 282 | |
277 | 283 | // Convert the file to UTF-8, cuz most browsers dig that. |
@@ -279,24 +285,22 @@ discard block |
||
279 | 285 | $disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline'; |
280 | 286 | |
281 | 287 | // Different browsers like different standards... |
282 | - if (isBrowser('firefox')) |
|
283 | - header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
284 | - |
|
285 | - elseif (isBrowser('opera')) |
|
286 | - header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
287 | - |
|
288 | - elseif (isBrowser('ie')) |
|
289 | - header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
290 | - |
|
291 | - else |
|
292 | - header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
288 | + if (isBrowser('firefox')) { |
|
289 | + header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name))); |
|
290 | + } elseif (isBrowser('opera')) { |
|
291 | + header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"'); |
|
292 | + } elseif (isBrowser('ie')) { |
|
293 | + header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"'); |
|
294 | + } else { |
|
295 | + header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"'); |
|
296 | + } |
|
293 | 297 | |
294 | 298 | // If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE. |
295 | - if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) |
|
296 | - header('cache-control: no-cache'); |
|
297 | - |
|
298 | - else |
|
299 | - header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
299 | + if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) { |
|
300 | + header('cache-control: no-cache'); |
|
301 | + } else { |
|
302 | + header('cache-control: max-age=' . (525600 * 60) . ', private'); |
|
303 | + } |
|
300 | 304 | |
301 | 305 | // Multipart and resuming support |
302 | 306 | if (isset($_SERVER['HTTP_RANGE'])) |
@@ -304,9 +308,9 @@ discard block |
||
304 | 308 | send_http_status(206); |
305 | 309 | header("content-length: $new_length"); |
306 | 310 | header("content-range: bytes $range-$range_end/$size"); |
311 | + } else { |
|
312 | + header("content-length: " . $size); |
|
307 | 313 | } |
308 | - else |
|
309 | - header("content-length: " . $size); |
|
310 | 314 | |
311 | 315 | |
312 | 316 | // Try to buy some time... |
@@ -315,8 +319,9 @@ discard block |
||
315 | 319 | // For multipart/resumable downloads, send the requested chunk(s) of the file |
316 | 320 | if (isset($_SERVER['HTTP_RANGE'])) |
317 | 321 | { |
318 | - while (@ob_get_level() > 0) |
|
319 | - @ob_end_clean(); |
|
322 | + while (@ob_get_level() > 0) { |
|
323 | + @ob_end_clean(); |
|
324 | + } |
|
320 | 325 | |
321 | 326 | // 40 kilobytes is a good-ish amount |
322 | 327 | $chunksize = 40 * 1024; |
@@ -340,8 +345,9 @@ discard block |
||
340 | 345 | elseif ($size > 4194304) |
341 | 346 | { |
342 | 347 | // Forcibly end any output buffering going on. |
343 | - while (@ob_get_level() > 0) |
|
344 | - @ob_end_clean(); |
|
348 | + while (@ob_get_level() > 0) { |
|
349 | + @ob_end_clean(); |
|
350 | + } |
|
345 | 351 | |
346 | 352 | $fp = fopen($file['filePath'], 'rb'); |
347 | 353 | while (!feof($fp)) |
@@ -353,8 +359,9 @@ discard block |
||
353 | 359 | } |
354 | 360 | |
355 | 361 | // On some of the less-bright hosts, readfile() is disabled. It's just a faster, more byte safe, version of what's in the if. |
356 | - elseif (@readfile($file['filePath']) === null) |
|
357 | - echo file_get_contents($file['filePath']); |
|
362 | + elseif (@readfile($file['filePath']) === null) { |
|
363 | + echo file_get_contents($file['filePath']); |
|
364 | + } |
|
358 | 365 | |
359 | 366 | die(); |
360 | 367 | } |
@@ -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 | // This defines two version types for checking the API's are compatible with this version of SMF. |
20 | 21 | $GLOBALS['search_versions'] = array( |
@@ -39,8 +40,9 @@ discard block |
||
39 | 40 | global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir; |
40 | 41 | |
41 | 42 | // Is the load average too high to allow searching just now? |
42 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
43 | - fatal_lang_error('loadavg_search_disabled', false); |
|
43 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
44 | + fatal_lang_error('loadavg_search_disabled', false); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | loadLanguage('Search'); |
46 | 48 | // Don't load this in XML mode. |
@@ -88,23 +90,30 @@ discard block |
||
88 | 90 | @list ($k, $v) = explode('|\'|', $data); |
89 | 91 | $context['search_params'][$k] = $v; |
90 | 92 | } |
91 | - if (isset($context['search_params']['brd'])) |
|
92 | - $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
93 | + if (isset($context['search_params']['brd'])) { |
|
94 | + $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
95 | + } |
|
93 | 96 | } |
94 | 97 | |
95 | - if (isset($_REQUEST['search'])) |
|
96 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
98 | + if (isset($_REQUEST['search'])) { |
|
99 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
100 | + } |
|
97 | 101 | |
98 | - if (isset($context['search_params']['search'])) |
|
99 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
100 | - if (isset($context['search_params']['userspec'])) |
|
101 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
102 | - if (!empty($context['search_params']['searchtype'])) |
|
103 | - $context['search_params']['searchtype'] = 2; |
|
104 | - if (!empty($context['search_params']['minage'])) |
|
105 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
106 | - if (!empty($context['search_params']['maxage'])) |
|
107 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
102 | + if (isset($context['search_params']['search'])) { |
|
103 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
104 | + } |
|
105 | + if (isset($context['search_params']['userspec'])) { |
|
106 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
107 | + } |
|
108 | + if (!empty($context['search_params']['searchtype'])) { |
|
109 | + $context['search_params']['searchtype'] = 2; |
|
110 | + } |
|
111 | + if (!empty($context['search_params']['minage'])) { |
|
112 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
113 | + } |
|
114 | + if (!empty($context['search_params']['maxage'])) { |
|
115 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
116 | + } |
|
108 | 117 | |
109 | 118 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
110 | 119 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
@@ -116,11 +125,13 @@ discard block |
||
116 | 125 | $context['search_errors']['messages'] = array(); |
117 | 126 | foreach ($context['search_errors'] as $search_error => $dummy) |
118 | 127 | { |
119 | - if ($search_error === 'messages') |
|
120 | - continue; |
|
128 | + if ($search_error === 'messages') { |
|
129 | + continue; |
|
130 | + } |
|
121 | 131 | |
122 | - if ($search_error == 'string_too_long') |
|
123 | - $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
132 | + if ($search_error == 'string_too_long') { |
|
133 | + $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
134 | + } |
|
124 | 135 | |
125 | 136 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
126 | 137 | } |
@@ -143,12 +154,13 @@ discard block |
||
143 | 154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
144 | 155 | { |
145 | 156 | // This category hasn't been set up yet.. |
146 | - if (!isset($context['categories'][$row['id_cat']])) |
|
147 | - $context['categories'][$row['id_cat']] = array( |
|
157 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
158 | + $context['categories'][$row['id_cat']] = array( |
|
148 | 159 | 'id' => $row['id_cat'], |
149 | 160 | 'name' => $row['cat_name'], |
150 | 161 | 'boards' => array() |
151 | 162 | ); |
163 | + } |
|
152 | 164 | |
153 | 165 | // Set this board up, and let the template know when it's a child. (indent them..) |
154 | 166 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -159,8 +171,9 @@ discard block |
||
159 | 171 | ); |
160 | 172 | |
161 | 173 | // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
162 | - if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) |
|
163 | - $context['boards_check_all'] = false; |
|
174 | + if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) { |
|
175 | + $context['boards_check_all'] = false; |
|
176 | + } |
|
164 | 177 | } |
165 | 178 | $smcFunc['db_free_result']($request); |
166 | 179 | |
@@ -182,18 +195,20 @@ discard block |
||
182 | 195 | } |
183 | 196 | |
184 | 197 | $max_boards = ceil(count($temp_boards) / 2); |
185 | - if ($max_boards == 1) |
|
186 | - $max_boards = 2; |
|
198 | + if ($max_boards == 1) { |
|
199 | + $max_boards = 2; |
|
200 | + } |
|
187 | 201 | |
188 | 202 | // Now, alternate them so they can be shown left and right ;). |
189 | 203 | $context['board_columns'] = array(); |
190 | 204 | for ($i = 0; $i < $max_boards; $i++) |
191 | 205 | { |
192 | 206 | $context['board_columns'][] = $temp_boards[$i]; |
193 | - if (isset($temp_boards[$i + $max_boards])) |
|
194 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
195 | - else |
|
196 | - $context['board_columns'][] = array(); |
|
207 | + if (isset($temp_boards[$i + $max_boards])) { |
|
208 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
209 | + } else { |
|
210 | + $context['board_columns'][] = array(); |
|
211 | + } |
|
197 | 212 | } |
198 | 213 | |
199 | 214 | if (!empty($_REQUEST['topic'])) |
@@ -225,8 +240,9 @@ discard block |
||
225 | 240 | ) |
226 | 241 | ); |
227 | 242 | |
228 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
229 | - fatal_lang_error('topic_gone', false); |
|
243 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
244 | + fatal_lang_error('topic_gone', false); |
|
245 | + } |
|
230 | 246 | |
231 | 247 | list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request); |
232 | 248 | $smcFunc['db_free_result']($request); |
@@ -256,11 +272,13 @@ discard block |
||
256 | 272 | global $excludedWords, $participants, $smcFunc; |
257 | 273 | |
258 | 274 | // if comming from the quick search box, and we want to search on members, well we need to do that ;) |
259 | - if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') |
|
260 | - redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
275 | + if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') { |
|
276 | + redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
277 | + } |
|
261 | 278 | |
262 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
263 | - fatal_lang_error('loadavg_search_disabled', false); |
|
279 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
280 | + fatal_lang_error('loadavg_search_disabled', false); |
|
281 | + } |
|
264 | 282 | |
265 | 283 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
266 | 284 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -307,8 +325,9 @@ discard block |
||
307 | 325 | } |
308 | 326 | |
309 | 327 | // Zero weight. Weightless :P. |
310 | - if (empty($weight_total)) |
|
311 | - fatal_lang_error('search_invalid_weights'); |
|
328 | + if (empty($weight_total)) { |
|
329 | + fatal_lang_error('search_invalid_weights'); |
|
330 | + } |
|
312 | 331 | |
313 | 332 | // These vars don't require an interface, they're just here for tweaking. |
314 | 333 | $recentPercentage = 0.30; |
@@ -326,11 +345,13 @@ discard block |
||
326 | 345 | $context['search_string_limit'] = 100; |
327 | 346 | |
328 | 347 | loadLanguage('Search'); |
329 | - if (!isset($_REQUEST['xml'])) |
|
330 | - loadTemplate('Search'); |
|
348 | + if (!isset($_REQUEST['xml'])) { |
|
349 | + loadTemplate('Search'); |
|
350 | + } |
|
331 | 351 | //If we're doing XML we need to use the results template regardless really. |
332 | - else |
|
333 | - $context['sub_template'] = 'results'; |
|
352 | + else { |
|
353 | + $context['sub_template'] = 'results'; |
|
354 | + } |
|
334 | 355 | |
335 | 356 | // Are you allowed? |
336 | 357 | isAllowedTo('search_posts'); |
@@ -363,34 +384,39 @@ discard block |
||
363 | 384 | $search_params[$k] = $v; |
364 | 385 | } |
365 | 386 | |
366 | - if (isset($search_params['brd'])) |
|
367 | - $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
387 | + if (isset($search_params['brd'])) { |
|
388 | + $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
389 | + } |
|
368 | 390 | } |
369 | 391 | |
370 | 392 | // Store whether simple search was used (needed if the user wants to do another query). |
371 | - if (!isset($search_params['advanced'])) |
|
372 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
393 | + if (!isset($search_params['advanced'])) { |
|
394 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
395 | + } |
|
373 | 396 | |
374 | 397 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
375 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
376 | - $search_params['searchtype'] = 2; |
|
398 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
399 | + $search_params['searchtype'] = 2; |
|
400 | + } |
|
377 | 401 | |
378 | 402 | // Minimum age of messages. Default to zero (don't set param in that case). |
379 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
380 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
403 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
404 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
405 | + } |
|
381 | 406 | |
382 | 407 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
383 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) |
|
384 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
408 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) { |
|
409 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
410 | + } |
|
385 | 411 | |
386 | 412 | // Searching a specific topic? |
387 | 413 | if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic')) |
388 | 414 | { |
389 | 415 | $search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : ''); |
390 | 416 | $search_params['show_complete'] = true; |
417 | + } elseif (!empty($search_params['topic'])) { |
|
418 | + $search_params['topic'] = (int) $search_params['topic']; |
|
391 | 419 | } |
392 | - elseif (!empty($search_params['topic'])) |
|
393 | - $search_params['topic'] = (int) $search_params['topic']; |
|
394 | 420 | |
395 | 421 | if (!empty($search_params['minage']) || !empty($search_params['maxage'])) |
396 | 422 | { |
@@ -408,19 +434,21 @@ discard block |
||
408 | 434 | ) |
409 | 435 | ); |
410 | 436 | list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request); |
411 | - if ($minMsgID < 0 || $maxMsgID < 0) |
|
412 | - $context['search_errors']['no_messages_in_time_frame'] = true; |
|
437 | + if ($minMsgID < 0 || $maxMsgID < 0) { |
|
438 | + $context['search_errors']['no_messages_in_time_frame'] = true; |
|
439 | + } |
|
413 | 440 | $smcFunc['db_free_result']($request); |
414 | 441 | } |
415 | 442 | |
416 | 443 | // Default the user name to a wildcard matching every user (*). |
417 | - if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
418 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
444 | + if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
445 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
446 | + } |
|
419 | 447 | |
420 | 448 | // If there's no specific user, then don't mention it in the main query. |
421 | - if (empty($search_params['userspec'])) |
|
422 | - $userQuery = ''; |
|
423 | - else |
|
449 | + if (empty($search_params['userspec'])) { |
|
450 | + $userQuery = ''; |
|
451 | + } else |
|
424 | 452 | { |
425 | 453 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
426 | 454 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -432,19 +460,21 @@ discard block |
||
432 | 460 | { |
433 | 461 | $possible_users[$k] = trim($possible_users[$k]); |
434 | 462 | |
435 | - if (strlen($possible_users[$k]) == 0) |
|
436 | - unset($possible_users[$k]); |
|
463 | + if (strlen($possible_users[$k]) == 0) { |
|
464 | + unset($possible_users[$k]); |
|
465 | + } |
|
437 | 466 | } |
438 | 467 | |
439 | 468 | // Create a list of database-escaped search names. |
440 | 469 | $realNameMatches = array(); |
441 | - foreach ($possible_users as $possible_user) |
|
442 | - $realNameMatches[] = $smcFunc['db_quote']( |
|
470 | + foreach ($possible_users as $possible_user) { |
|
471 | + $realNameMatches[] = $smcFunc['db_quote']( |
|
443 | 472 | '{string:possible_user}', |
444 | 473 | array( |
445 | 474 | 'possible_user' => $possible_user |
446 | 475 | ) |
447 | 476 | ); |
477 | + } |
|
448 | 478 | |
449 | 479 | // Retrieve a list of possible members. |
450 | 480 | $request = $smcFunc['db_query']('', ' |
@@ -456,9 +486,9 @@ discard block |
||
456 | 486 | ) |
457 | 487 | ); |
458 | 488 | // Simply do nothing if there're too many members matching the criteria. |
459 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
460 | - $userQuery = ''; |
|
461 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
489 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
490 | + $userQuery = ''; |
|
491 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
462 | 492 | { |
463 | 493 | $userQuery = $smcFunc['db_quote']( |
464 | 494 | 'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})', |
@@ -467,12 +497,12 @@ discard block |
||
467 | 497 | 'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches), |
468 | 498 | ) |
469 | 499 | ); |
470 | - } |
|
471 | - else |
|
500 | + } else |
|
472 | 501 | { |
473 | 502 | $memberlist = array(); |
474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
475 | - $memberlist[] = $row['id_member']; |
|
503 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
504 | + $memberlist[] = $row['id_member']; |
|
505 | + } |
|
476 | 506 | $userQuery = $smcFunc['db_quote']( |
477 | 507 | '(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))', |
478 | 508 | array( |
@@ -486,22 +516,25 @@ discard block |
||
486 | 516 | } |
487 | 517 | |
488 | 518 | // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. |
489 | - if (!empty($search_params['brd']) && is_array($search_params['brd'])) |
|
490 | - $_REQUEST['brd'] = $search_params['brd']; |
|
519 | + if (!empty($search_params['brd']) && is_array($search_params['brd'])) { |
|
520 | + $_REQUEST['brd'] = $search_params['brd']; |
|
521 | + } |
|
491 | 522 | |
492 | 523 | // Ensure that brd is an array. |
493 | 524 | if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) |
494 | 525 | { |
495 | - if (!empty($_REQUEST['brd'])) |
|
496 | - $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
497 | - else |
|
498 | - $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
526 | + if (!empty($_REQUEST['brd'])) { |
|
527 | + $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
528 | + } else { |
|
529 | + $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
530 | + } |
|
499 | 531 | } |
500 | 532 | |
501 | 533 | // Make sure all boards are integers. |
502 | - if (!empty($_REQUEST['brd'])) |
|
503 | - foreach ($_REQUEST['brd'] as $id => $brd) |
|
534 | + if (!empty($_REQUEST['brd'])) { |
|
535 | + foreach ($_REQUEST['brd'] as $id => $brd) |
|
504 | 536 | $_REQUEST['brd'][$id] = (int) $brd; |
537 | + } |
|
505 | 538 | |
506 | 539 | // Special case for boards: searching just one topic? |
507 | 540 | if (!empty($search_params['topic'])) |
@@ -520,17 +553,18 @@ discard block |
||
520 | 553 | ) |
521 | 554 | ); |
522 | 555 | |
523 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
524 | - fatal_lang_error('topic_gone', false); |
|
556 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
557 | + fatal_lang_error('topic_gone', false); |
|
558 | + } |
|
525 | 559 | |
526 | 560 | $search_params['brd'] = array(); |
527 | 561 | list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request); |
528 | 562 | $smcFunc['db_free_result']($request); |
529 | 563 | } |
530 | 564 | // Select all boards you've selected AND are allowed to see. |
531 | - elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) |
|
532 | - $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
533 | - else |
|
565 | + elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) { |
|
566 | + $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
567 | + } else |
|
534 | 568 | { |
535 | 569 | $see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board'; |
536 | 570 | $request = $smcFunc['db_query']('', ' |
@@ -548,19 +582,22 @@ discard block |
||
548 | 582 | ) |
549 | 583 | ); |
550 | 584 | $search_params['brd'] = array(); |
551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
552 | - $search_params['brd'][] = $row['id_board']; |
|
585 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
586 | + $search_params['brd'][] = $row['id_board']; |
|
587 | + } |
|
553 | 588 | $smcFunc['db_free_result']($request); |
554 | 589 | |
555 | 590 | // This error should pro'bly only happen for hackers. |
556 | - if (empty($search_params['brd'])) |
|
557 | - $context['search_errors']['no_boards_selected'] = true; |
|
591 | + if (empty($search_params['brd'])) { |
|
592 | + $context['search_errors']['no_boards_selected'] = true; |
|
593 | + } |
|
558 | 594 | } |
559 | 595 | |
560 | 596 | if (count($search_params['brd']) != 0) |
561 | 597 | { |
562 | - foreach ($search_params['brd'] as $k => $v) |
|
563 | - $search_params['brd'][$k] = (int) $v; |
|
598 | + foreach ($search_params['brd'] as $k => $v) { |
|
599 | + $search_params['brd'][$k] = (int) $v; |
|
600 | + } |
|
564 | 601 | |
565 | 602 | // If we've selected all boards, this parameter can be left empty. |
566 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -574,15 +611,16 @@ discard block |
||
574 | 611 | list ($num_boards) = $smcFunc['db_fetch_row']($request); |
575 | 612 | $smcFunc['db_free_result']($request); |
576 | 613 | |
577 | - if (count($search_params['brd']) == $num_boards) |
|
614 | + if (count($search_params['brd']) == $num_boards) { |
|
615 | + $boardQuery = ''; |
|
616 | + } elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) { |
|
617 | + $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
618 | + } else { |
|
619 | + $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
620 | + } |
|
621 | + } else { |
|
578 | 622 | $boardQuery = ''; |
579 | - elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) |
|
580 | - $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
581 | - else |
|
582 | - $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
583 | 623 | } |
584 | - else |
|
585 | - $boardQuery = ''; |
|
586 | 624 | |
587 | 625 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
588 | 626 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
@@ -596,11 +634,13 @@ discard block |
||
596 | 634 | 'id_msg', |
597 | 635 | ); |
598 | 636 | call_integration_hook('integrate_search_sort_columns', array(&$sort_columns)); |
599 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
600 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
637 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
638 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
639 | + } |
|
601 | 640 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance'; |
602 | - if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') |
|
603 | - $search_params['sort'] = 'id_msg'; |
|
641 | + if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') { |
|
642 | + $search_params['sort'] = 'id_msg'; |
|
643 | + } |
|
604 | 644 | |
605 | 645 | // Sorting direction: descending unless stated otherwise. |
606 | 646 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
@@ -624,17 +664,19 @@ discard block |
||
624 | 664 | // What are we searching for? |
625 | 665 | if (empty($search_params['search'])) |
626 | 666 | { |
627 | - if (isset($_GET['search'])) |
|
628 | - $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
629 | - elseif (isset($_POST['search'])) |
|
630 | - $search_params['search'] = $_POST['search']; |
|
631 | - else |
|
632 | - $search_params['search'] = ''; |
|
667 | + if (isset($_GET['search'])) { |
|
668 | + $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
669 | + } elseif (isset($_POST['search'])) { |
|
670 | + $search_params['search'] = $_POST['search']; |
|
671 | + } else { |
|
672 | + $search_params['search'] = ''; |
|
673 | + } |
|
633 | 674 | } |
634 | 675 | |
635 | 676 | // Nothing?? |
636 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
637 | - $context['search_errors']['invalid_search_string'] = true; |
|
677 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
678 | + $context['search_errors']['invalid_search_string'] = true; |
|
679 | + } |
|
638 | 680 | // Too long? |
639 | 681 | elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit']) |
640 | 682 | { |
@@ -648,8 +690,9 @@ discard block |
||
648 | 690 | $stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query)); |
649 | 691 | |
650 | 692 | // This (hidden) setting will do fulltext searching in the most basic way. |
651 | - if (!empty($modSettings['search_simple_fulltext'])) |
|
652 | - $stripped_query = strtr($stripped_query, array('"' => '')); |
|
693 | + if (!empty($modSettings['search_simple_fulltext'])) { |
|
694 | + $stripped_query = strtr($stripped_query, array('"' => '')); |
|
695 | + } |
|
653 | 696 | |
654 | 697 | $no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1; |
655 | 698 | |
@@ -672,8 +715,9 @@ discard block |
||
672 | 715 | { |
673 | 716 | if ($word === '-') |
674 | 717 | { |
675 | - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
676 | - $excludedWords[] = $word; |
|
718 | + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
719 | + $excludedWords[] = $word; |
|
720 | + } |
|
677 | 721 | unset($phraseArray[$index]); |
678 | 722 | } |
679 | 723 | } |
@@ -683,8 +727,9 @@ discard block |
||
683 | 727 | { |
684 | 728 | if (strpos(trim($word), '-') === 0) |
685 | 729 | { |
686 | - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
687 | - $excludedWords[] = $word; |
|
730 | + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
731 | + $excludedWords[] = $word; |
|
732 | + } |
|
688 | 733 | unset($wordArray[$index]); |
689 | 734 | } |
690 | 735 | } |
@@ -697,8 +742,9 @@ discard block |
||
697 | 742 | foreach ($searchArray as $index => $value) |
698 | 743 | { |
699 | 744 | // Skip anything practically empty. |
700 | - if (($searchArray[$index] = trim($value, '-_\' ')) === '') |
|
701 | - unset($searchArray[$index]); |
|
745 | + if (($searchArray[$index] = trim($value, '-_\' ')) === '') { |
|
746 | + unset($searchArray[$index]); |
|
747 | + } |
|
702 | 748 | // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. |
703 | 749 | elseif (in_array($searchArray[$index], $blacklisted_words)) |
704 | 750 | { |
@@ -716,31 +762,37 @@ discard block |
||
716 | 762 | |
717 | 763 | // Create an array of replacements for highlighting. |
718 | 764 | $context['mark'] = array(); |
719 | - foreach ($searchArray as $word) |
|
720 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
765 | + foreach ($searchArray as $word) { |
|
766 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
767 | + } |
|
721 | 768 | |
722 | 769 | // Initialize two arrays storing the words that have to be searched for. |
723 | 770 | $orParts = array(); |
724 | 771 | $searchWords = array(); |
725 | 772 | |
726 | 773 | // Make sure at least one word is being searched for. |
727 | - if (empty($searchArray)) |
|
728 | - $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
774 | + if (empty($searchArray)) { |
|
775 | + $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
776 | + } |
|
729 | 777 | // All words/sentences must match. |
730 | - elseif (empty($search_params['searchtype'])) |
|
731 | - $orParts[0] = $searchArray; |
|
778 | + elseif (empty($search_params['searchtype'])) { |
|
779 | + $orParts[0] = $searchArray; |
|
780 | + } |
|
732 | 781 | // Any word/sentence must match. |
733 | - else |
|
734 | - foreach ($searchArray as $index => $value) |
|
782 | + else { |
|
783 | + foreach ($searchArray as $index => $value) |
|
735 | 784 | $orParts[$index] = array($value); |
785 | + } |
|
736 | 786 | |
737 | 787 | // Don't allow duplicate error messages if one string is too short. |
738 | - if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
|
739 | - unset($context['search_errors']['invalid_search_string']); |
|
788 | + if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) { |
|
789 | + unset($context['search_errors']['invalid_search_string']); |
|
790 | + } |
|
740 | 791 | // Make sure the excluded words are in all or-branches. |
741 | - foreach ($orParts as $orIndex => $andParts) |
|
742 | - foreach ($excludedWords as $word) |
|
792 | + foreach ($orParts as $orIndex => $andParts) { |
|
793 | + foreach ($excludedWords as $word) |
|
743 | 794 | $orParts[$orIndex][] = $word; |
795 | + } |
|
744 | 796 | |
745 | 797 | // Determine the or-branches and the fulltext search words. |
746 | 798 | foreach ($orParts as $orIndex => $andParts) |
@@ -754,8 +806,9 @@ discard block |
||
754 | 806 | ); |
755 | 807 | |
756 | 808 | // Sort the indexed words (large words -> small words -> excluded words). |
757 | - if ($searchAPI->supportsMethod('searchSort')) |
|
758 | - usort($orParts[$orIndex], 'searchSort'); |
|
809 | + if ($searchAPI->supportsMethod('searchSort')) { |
|
810 | + usort($orParts[$orIndex], 'searchSort'); |
|
811 | + } |
|
759 | 812 | |
760 | 813 | foreach ($orParts[$orIndex] as $word) |
761 | 814 | { |
@@ -767,15 +820,17 @@ discard block |
||
767 | 820 | if (!$is_excluded || count($subjectWords) === 1) |
768 | 821 | { |
769 | 822 | $searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords); |
770 | - if ($is_excluded) |
|
771 | - $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
823 | + if ($is_excluded) { |
|
824 | + $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
825 | + } |
|
826 | + } else { |
|
827 | + $excludedPhrases[] = $word; |
|
772 | 828 | } |
773 | - else |
|
774 | - $excludedPhrases[] = $word; |
|
775 | 829 | |
776 | 830 | // Have we got indexes to prepare? |
777 | - if ($searchAPI->supportsMethod('prepareIndexes')) |
|
778 | - $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
831 | + if ($searchAPI->supportsMethod('prepareIndexes')) { |
|
832 | + $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
833 | + } |
|
779 | 834 | } |
780 | 835 | |
781 | 836 | // Search_force_index requires all AND parts to have at least one fulltext word. |
@@ -783,8 +838,7 @@ discard block |
||
783 | 838 | { |
784 | 839 | $context['search_errors']['query_not_specific_enough'] = true; |
785 | 840 | break; |
786 | - } |
|
787 | - elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
841 | + } elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
788 | 842 | { |
789 | 843 | $context['search_errors']['query_not_specific_enough'] = true; |
790 | 844 | break; |
@@ -812,8 +866,9 @@ discard block |
||
812 | 866 | $found_misspelling = false; |
813 | 867 | foreach ($searchArray as $word) |
814 | 868 | { |
815 | - if (empty($link)) |
|
816 | - continue; |
|
869 | + if (empty($link)) { |
|
870 | + continue; |
|
871 | + } |
|
817 | 872 | |
818 | 873 | // Don't check phrases. |
819 | 874 | if (preg_match('~^\w+$~', $word) === 0) |
@@ -828,8 +883,7 @@ discard block |
||
828 | 883 | $did_you_mean['search'][] = $word; |
829 | 884 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
830 | 885 | continue; |
831 | - } |
|
832 | - elseif (spell_check($link, $word)) |
|
886 | + } elseif (spell_check($link, $word)) |
|
833 | 887 | { |
834 | 888 | $did_you_mean['search'][] = $word; |
835 | 889 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -840,11 +894,13 @@ discard block |
||
840 | 894 | foreach ($suggestions as $i => $s) |
841 | 895 | { |
842 | 896 | // Search is case insensitive. |
843 | - if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) |
|
844 | - unset($suggestions[$i]); |
|
897 | + if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) { |
|
898 | + unset($suggestions[$i]); |
|
899 | + } |
|
845 | 900 | // Plus, don't suggest something the user thinks is rude! |
846 | - elseif ($suggestions[$i] != censorText($s)) |
|
847 | - unset($suggestions[$i]); |
|
901 | + elseif ($suggestions[$i] != censorText($s)) { |
|
902 | + unset($suggestions[$i]); |
|
903 | + } |
|
848 | 904 | } |
849 | 905 | |
850 | 906 | // Anything found? If so, correct it! |
@@ -854,8 +910,7 @@ discard block |
||
854 | 910 | $did_you_mean['search'][] = $suggestions[0]; |
855 | 911 | $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>'; |
856 | 912 | $found_misspelling = true; |
857 | - } |
|
858 | - else |
|
913 | + } else |
|
859 | 914 | { |
860 | 915 | $did_you_mean['search'][] = $word; |
861 | 916 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -872,8 +927,7 @@ discard block |
||
872 | 927 | { |
873 | 928 | $temp_excluded['search'][] = '-"' . $word . '"'; |
874 | 929 | $temp_excluded['display'][] = '-"' . $smcFunc['htmlspecialchars']($word) . '"'; |
875 | - } |
|
876 | - else |
|
930 | + } else |
|
877 | 931 | { |
878 | 932 | $temp_excluded['search'][] = '-' . $word; |
879 | 933 | $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word); |
@@ -885,11 +939,13 @@ discard block |
||
885 | 939 | |
886 | 940 | $temp_params = $search_params; |
887 | 941 | $temp_params['search'] = implode(' ', $did_you_mean['search']); |
888 | - if (isset($temp_params['brd'])) |
|
889 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
942 | + if (isset($temp_params['brd'])) { |
|
943 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
944 | + } |
|
890 | 945 | $context['params'] = array(); |
891 | - foreach ($temp_params as $k => $v) |
|
892 | - $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
946 | + foreach ($temp_params as $k => $v) { |
|
947 | + $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
948 | + } |
|
893 | 949 | $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params'])); |
894 | 950 | $context['did_you_mean'] = implode(' ', $did_you_mean['display']); |
895 | 951 | } |
@@ -897,18 +953,20 @@ discard block |
||
897 | 953 | |
898 | 954 | // Let the user adjust the search query, should they wish? |
899 | 955 | $context['search_params'] = $search_params; |
900 | - if (isset($context['search_params']['search'])) |
|
901 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
902 | - if (isset($context['search_params']['userspec'])) |
|
903 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
956 | + if (isset($context['search_params']['search'])) { |
|
957 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
958 | + } |
|
959 | + if (isset($context['search_params']['userspec'])) { |
|
960 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
961 | + } |
|
904 | 962 | |
905 | 963 | // Do we have captcha enabled? |
906 | 964 | if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])) |
907 | 965 | { |
908 | 966 | // If we come from another search box tone down the error... |
909 | - if (!isset($_REQUEST['search_vv'])) |
|
910 | - $context['search_errors']['need_verification_code'] = true; |
|
911 | - else |
|
967 | + if (!isset($_REQUEST['search_vv'])) { |
|
968 | + $context['search_errors']['need_verification_code'] = true; |
|
969 | + } else |
|
912 | 970 | { |
913 | 971 | require_once($sourcedir . '/Subs-Editor.php'); |
914 | 972 | $verificationOptions = array( |
@@ -918,12 +976,14 @@ discard block |
||
918 | 976 | |
919 | 977 | if (is_array($context['require_verification'])) |
920 | 978 | { |
921 | - foreach ($context['require_verification'] as $error) |
|
922 | - $context['search_errors'][$error] = true; |
|
979 | + foreach ($context['require_verification'] as $error) { |
|
980 | + $context['search_errors'][$error] = true; |
|
981 | + } |
|
923 | 982 | } |
924 | 983 | // Don't keep asking for it - they've proven themselves worthy. |
925 | - else |
|
926 | - $_SESSION['ss_vv_passed'] = true; |
|
984 | + else { |
|
985 | + $_SESSION['ss_vv_passed'] = true; |
|
986 | + } |
|
927 | 987 | } |
928 | 988 | } |
929 | 989 | |
@@ -931,19 +991,22 @@ discard block |
||
931 | 991 | |
932 | 992 | // All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below. |
933 | 993 | $temp_params = $search_params; |
934 | - if (isset($temp_params['brd'])) |
|
935 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
994 | + if (isset($temp_params['brd'])) { |
|
995 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
996 | + } |
|
936 | 997 | $context['params'] = array(); |
937 | - foreach ($temp_params as $k => $v) |
|
938 | - $context['params'][] = $k . '|\'|' . $v; |
|
998 | + foreach ($temp_params as $k => $v) { |
|
999 | + $context['params'][] = $k . '|\'|' . $v; |
|
1000 | + } |
|
939 | 1001 | |
940 | 1002 | if (!empty($context['params'])) |
941 | 1003 | { |
942 | 1004 | // Due to old IE's 2083 character limit, we have to compress long search strings |
943 | 1005 | $params = @gzcompress(implode('|"|', $context['params'])); |
944 | 1006 | // Gzcompress failed, use try non-gz |
945 | - if (empty($params)) |
|
946 | - $params = implode('|"|', $context['params']); |
|
1007 | + if (empty($params)) { |
|
1008 | + $params = implode('|"|', $context['params']); |
|
1009 | + } |
|
947 | 1010 | // Base64 encode, then replace +/= with uri safe ones that can be reverted |
948 | 1011 | $context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params)); |
949 | 1012 | } |
@@ -969,8 +1032,9 @@ discard block |
||
969 | 1032 | } |
970 | 1033 | |
971 | 1034 | // Spam me not, Spam-a-lot? |
972 | - if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) |
|
973 | - spamProtection('search'); |
|
1035 | + if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) { |
|
1036 | + spamProtection('search'); |
|
1037 | + } |
|
974 | 1038 | // Store the last search string to allow pages of results to be browsed. |
975 | 1039 | $_SESSION['last_ss'] = $search_params['search']; |
976 | 1040 | |
@@ -1007,8 +1071,9 @@ discard block |
||
1007 | 1071 | ) |
1008 | 1072 | ); |
1009 | 1073 | |
1010 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
1011 | - $update_cache = true; |
|
1074 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
1075 | + $update_cache = true; |
|
1076 | + } |
|
1012 | 1077 | } |
1013 | 1078 | |
1014 | 1079 | if ($update_cache) |
@@ -1047,8 +1112,9 @@ discard block |
||
1047 | 1112 | 'where' => array(), |
1048 | 1113 | ); |
1049 | 1114 | |
1050 | - if ($modSettings['postmod_active']) |
|
1051 | - $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1115 | + if ($modSettings['postmod_active']) { |
|
1116 | + $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1117 | + } |
|
1052 | 1118 | |
1053 | 1119 | $numTables = 0; |
1054 | 1120 | $prev_join = 0; |
@@ -1060,8 +1126,7 @@ discard block |
||
1060 | 1126 | { |
1061 | 1127 | $subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)'; |
1062 | 1128 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1063 | - } |
|
1064 | - else |
|
1129 | + } else |
|
1065 | 1130 | { |
1066 | 1131 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
1067 | 1132 | $subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}'); |
@@ -1079,14 +1144,18 @@ discard block |
||
1079 | 1144 | } |
1080 | 1145 | $subject_query['where'][] = $userQuery; |
1081 | 1146 | } |
1082 | - if (!empty($search_params['topic'])) |
|
1083 | - $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1084 | - if (!empty($minMsgID)) |
|
1085 | - $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1086 | - if (!empty($maxMsgID)) |
|
1087 | - $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1088 | - if (!empty($boardQuery)) |
|
1089 | - $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1147 | + if (!empty($search_params['topic'])) { |
|
1148 | + $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1149 | + } |
|
1150 | + if (!empty($minMsgID)) { |
|
1151 | + $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1152 | + } |
|
1153 | + if (!empty($maxMsgID)) { |
|
1154 | + $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1155 | + } |
|
1156 | + if (!empty($boardQuery)) { |
|
1157 | + $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1158 | + } |
|
1090 | 1159 | if (!empty($excludedPhrases)) |
1091 | 1160 | { |
1092 | 1161 | if ($subject_query['from'] != '{db_prefix}messages AS m') |
@@ -1106,8 +1175,9 @@ discard block |
||
1106 | 1175 | foreach ($weight_factors as $type => $value) |
1107 | 1176 | { |
1108 | 1177 | $relevance .= $weight[$type]; |
1109 | - if (!empty($value['results'])) |
|
1110 | - $relevance .= ' * ' . $value['results']; |
|
1178 | + if (!empty($value['results'])) { |
|
1179 | + $relevance .= ' * ' . $value['results']; |
|
1180 | + } |
|
1111 | 1181 | $relevance .= ' + '; |
1112 | 1182 | } |
1113 | 1183 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1145,20 +1215,23 @@ discard block |
||
1145 | 1215 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1146 | 1216 | { |
1147 | 1217 | // No duplicates! |
1148 | - if (isset($inserts[$row[1]])) |
|
1149 | - continue; |
|
1218 | + if (isset($inserts[$row[1]])) { |
|
1219 | + continue; |
|
1220 | + } |
|
1150 | 1221 | |
1151 | - foreach ($row as $key => $value) |
|
1152 | - $inserts[$row[1]][] = (int) $row[$key]; |
|
1222 | + foreach ($row as $key => $value) { |
|
1223 | + $inserts[$row[1]][] = (int) $row[$key]; |
|
1224 | + } |
|
1153 | 1225 | } |
1154 | 1226 | $smcFunc['db_free_result']($ignoreRequest); |
1155 | 1227 | $numSubjectResults = count($inserts); |
1228 | + } else { |
|
1229 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1156 | 1230 | } |
1157 | - else |
|
1158 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1159 | 1231 | |
1160 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1161 | - break; |
|
1232 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1233 | + break; |
|
1234 | + } |
|
1162 | 1235 | } |
1163 | 1236 | |
1164 | 1237 | // If there's data to be inserted for non-IGNORE databases do it here! |
@@ -1173,8 +1246,7 @@ discard block |
||
1173 | 1246 | } |
1174 | 1247 | |
1175 | 1248 | $_SESSION['search_cache']['num_results'] = $numSubjectResults; |
1176 | - } |
|
1177 | - else |
|
1249 | + } else |
|
1178 | 1250 | { |
1179 | 1251 | $main_query = array( |
1180 | 1252 | 'select' => array( |
@@ -1206,8 +1278,7 @@ discard block |
||
1206 | 1278 | $main_query['weights'] = $weight_factors; |
1207 | 1279 | |
1208 | 1280 | $main_query['group_by'][] = 't.id_topic'; |
1209 | - } |
|
1210 | - else |
|
1281 | + } else |
|
1211 | 1282 | { |
1212 | 1283 | // This is outrageous! |
1213 | 1284 | $main_query['select']['id_topic'] = 'm.id_msg AS id_topic'; |
@@ -1228,8 +1299,9 @@ discard block |
||
1228 | 1299 | $main_query['where'][] = 't.id_topic = {int:topic}'; |
1229 | 1300 | $main_query['parameters']['topic'] = $search_params['topic']; |
1230 | 1301 | } |
1231 | - if (!empty($search_params['show_complete'])) |
|
1232 | - $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1302 | + if (!empty($search_params['show_complete'])) { |
|
1303 | + $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1304 | + } |
|
1233 | 1305 | } |
1234 | 1306 | |
1235 | 1307 | // *** Get the subject results. |
@@ -1254,14 +1326,15 @@ discard block |
||
1254 | 1326 | ) !== false; |
1255 | 1327 | |
1256 | 1328 | // Clean up some previous cache. |
1257 | - if (!$createTemporary) |
|
1258 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1329 | + if (!$createTemporary) { |
|
1330 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1259 | 1331 | DELETE FROM {db_prefix}log_search_topics |
1260 | 1332 | WHERE id_search = {int:search_id}', |
1261 | 1333 | array( |
1262 | 1334 | 'search_id' => $_SESSION['search_cache']['id_search'], |
1263 | 1335 | ) |
1264 | 1336 | ); |
1337 | + } |
|
1265 | 1338 | |
1266 | 1339 | foreach ($searchWords as $orIndex => $words) |
1267 | 1340 | { |
@@ -1293,8 +1366,7 @@ discard block |
||
1293 | 1366 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1294 | 1367 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
1295 | 1368 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
1296 | - } |
|
1297 | - else |
|
1369 | + } else |
|
1298 | 1370 | { |
1299 | 1371 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
1300 | 1372 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1349,8 +1421,9 @@ discard block |
||
1349 | 1421 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
1350 | 1422 | |
1351 | 1423 | // Nothing to search for? |
1352 | - if (empty($subject_query['where'])) |
|
1353 | - continue; |
|
1424 | + if (empty($subject_query['where'])) { |
|
1425 | + continue; |
|
1426 | + } |
|
1354 | 1427 | |
1355 | 1428 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
1356 | 1429 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1373,19 +1446,21 @@ discard block |
||
1373 | 1446 | { |
1374 | 1447 | $ind = $createTemporary ? 0 : 1; |
1375 | 1448 | // No duplicates! |
1376 | - if (isset($inserts[$row[$ind]])) |
|
1377 | - continue; |
|
1449 | + if (isset($inserts[$row[$ind]])) { |
|
1450 | + continue; |
|
1451 | + } |
|
1378 | 1452 | |
1379 | 1453 | $inserts[$row[$ind]] = $row; |
1380 | 1454 | } |
1381 | 1455 | $smcFunc['db_free_result']($ignoreRequest); |
1382 | 1456 | $numSubjectResults = count($inserts); |
1457 | + } else { |
|
1458 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1383 | 1459 | } |
1384 | - else |
|
1385 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1386 | 1460 | |
1387 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1388 | - break; |
|
1461 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1462 | + break; |
|
1463 | + } |
|
1389 | 1464 | } |
1390 | 1465 | |
1391 | 1466 | // Got some non-MySQL data to plonk in? |
@@ -1403,8 +1478,9 @@ discard block |
||
1403 | 1478 | { |
1404 | 1479 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
1405 | 1480 | $main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)'; |
1406 | - if (!$createTemporary) |
|
1407 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1481 | + if (!$createTemporary) { |
|
1482 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1483 | + } |
|
1408 | 1484 | } |
1409 | 1485 | } |
1410 | 1486 | |
@@ -1430,14 +1506,15 @@ discard block |
||
1430 | 1506 | ) !== false; |
1431 | 1507 | |
1432 | 1508 | // Clear, all clear! |
1433 | - if (!$createTemporary) |
|
1434 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1509 | + if (!$createTemporary) { |
|
1510 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1435 | 1511 | DELETE FROM {db_prefix}log_search_messages |
1436 | 1512 | WHERE id_search = {int:id_search}', |
1437 | 1513 | array( |
1438 | 1514 | 'id_search' => $_SESSION['search_cache']['id_search'], |
1439 | 1515 | ) |
1440 | 1516 | ); |
1517 | + } |
|
1441 | 1518 | |
1442 | 1519 | foreach ($searchWords as $orIndex => $words) |
1443 | 1520 | { |
@@ -1471,19 +1548,21 @@ discard block |
||
1471 | 1548 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1472 | 1549 | { |
1473 | 1550 | // No duplicates! |
1474 | - if (isset($inserts[$row[0]])) |
|
1475 | - continue; |
|
1551 | + if (isset($inserts[$row[0]])) { |
|
1552 | + continue; |
|
1553 | + } |
|
1476 | 1554 | |
1477 | 1555 | $inserts[$row[0]] = $row; |
1478 | 1556 | } |
1479 | 1557 | $smcFunc['db_free_result']($ignoreRequest); |
1480 | 1558 | $indexedResults = count($inserts); |
1559 | + } else { |
|
1560 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
1481 | 1561 | } |
1482 | - else |
|
1483 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
1484 | 1562 | |
1485 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
1486 | - break; |
|
1563 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
1564 | + break; |
|
1565 | + } |
|
1487 | 1566 | } |
1488 | 1567 | } |
1489 | 1568 | |
@@ -1503,8 +1582,7 @@ discard block |
||
1503 | 1582 | $context['search_errors']['query_not_specific_enough'] = true; |
1504 | 1583 | $_REQUEST['params'] = $context['params']; |
1505 | 1584 | return PlushSearch1(); |
1506 | - } |
|
1507 | - elseif (!empty($indexedResults)) |
|
1585 | + } elseif (!empty($indexedResults)) |
|
1508 | 1586 | { |
1509 | 1587 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
1510 | 1588 | if (!$createTemporary) |
@@ -1526,15 +1604,18 @@ discard block |
||
1526 | 1604 | foreach ($words['all_words'] as $regularWord) |
1527 | 1605 | { |
1528 | 1606 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
1529 | - if (in_array($regularWord, $excludedWords)) |
|
1530 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1607 | + if (in_array($regularWord, $excludedWords)) { |
|
1608 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1609 | + } |
|
1531 | 1610 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
1532 | 1611 | } |
1533 | - if (!empty($where)) |
|
1534 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1612 | + if (!empty($where)) { |
|
1613 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1614 | + } |
|
1615 | + } |
|
1616 | + if (!empty($orWhere)) { |
|
1617 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1535 | 1618 | } |
1536 | - if (!empty($orWhere)) |
|
1537 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1538 | 1619 | |
1539 | 1620 | if (!empty($userQuery)) |
1540 | 1621 | { |
@@ -1572,8 +1653,9 @@ discard block |
||
1572 | 1653 | foreach ($main_query['weights'] as $type => $value) |
1573 | 1654 | { |
1574 | 1655 | $relevance .= $weight[$type]; |
1575 | - if (!empty($value['search'])) |
|
1576 | - $relevance .= ' * ' . $value['search']; |
|
1656 | + if (!empty($value['search'])) { |
|
1657 | + $relevance .= ' * ' . $value['search']; |
|
1658 | + } |
|
1577 | 1659 | $relevance .= ' + '; |
1578 | 1660 | $new_weight_total += $weight[$type]; |
1579 | 1661 | } |
@@ -1604,11 +1686,13 @@ discard block |
||
1604 | 1686 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1605 | 1687 | { |
1606 | 1688 | // No duplicates! |
1607 | - if (isset($inserts[$row[2]])) |
|
1608 | - continue; |
|
1689 | + if (isset($inserts[$row[2]])) { |
|
1690 | + continue; |
|
1691 | + } |
|
1609 | 1692 | |
1610 | - foreach ($row as $key => $value) |
|
1611 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
1693 | + foreach ($row as $key => $value) { |
|
1694 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
1695 | + } |
|
1612 | 1696 | } |
1613 | 1697 | $smcFunc['db_free_result']($ignoreRequest); |
1614 | 1698 | |
@@ -1616,8 +1700,9 @@ discard block |
||
1616 | 1700 | if (!empty($inserts)) |
1617 | 1701 | { |
1618 | 1702 | $query_columns = array(); |
1619 | - foreach ($main_query['select'] as $k => $v) |
|
1620 | - $query_columns[$k] = 'int'; |
|
1703 | + foreach ($main_query['select'] as $k => $v) { |
|
1704 | + $query_columns[$k] = 'int'; |
|
1705 | + } |
|
1621 | 1706 | |
1622 | 1707 | $smcFunc['db_insert']('', |
1623 | 1708 | '{db_prefix}log_search_results', |
@@ -1627,21 +1712,23 @@ discard block |
||
1627 | 1712 | ); |
1628 | 1713 | } |
1629 | 1714 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1715 | + } else { |
|
1716 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1630 | 1717 | } |
1631 | - else |
|
1632 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1633 | 1718 | } |
1634 | 1719 | |
1635 | 1720 | // Insert subject-only matches. |
1636 | 1721 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
1637 | 1722 | { |
1638 | 1723 | $relevance = '1000 * ('; |
1639 | - foreach ($weight_factors as $type => $value) |
|
1640 | - if (isset($value['results'])) |
|
1724 | + foreach ($weight_factors as $type => $value) { |
|
1725 | + if (isset($value['results'])) |
|
1641 | 1726 | { |
1642 | 1727 | $relevance .= $weight[$type]; |
1643 | - if (!empty($value['results'])) |
|
1644 | - $relevance .= ' * ' . $value['results']; |
|
1728 | + } |
|
1729 | + if (!empty($value['results'])) { |
|
1730 | + $relevance .= ' * ' . $value['results']; |
|
1731 | + } |
|
1645 | 1732 | $relevance .= ' + '; |
1646 | 1733 | } |
1647 | 1734 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1675,8 +1762,9 @@ discard block |
||
1675 | 1762 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1676 | 1763 | { |
1677 | 1764 | // No duplicates! |
1678 | - if (isset($usedIDs[$row[1]])) |
|
1679 | - continue; |
|
1765 | + if (isset($usedIDs[$row[1]])) { |
|
1766 | + continue; |
|
1767 | + } |
|
1680 | 1768 | |
1681 | 1769 | $usedIDs[$row[1]] = true; |
1682 | 1770 | $inserts[] = $row; |
@@ -1694,12 +1782,12 @@ discard block |
||
1694 | 1782 | ); |
1695 | 1783 | } |
1696 | 1784 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1785 | + } else { |
|
1786 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1697 | 1787 | } |
1698 | - else |
|
1699 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1788 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
1789 | + $_SESSION['search_cache']['num_results'] = 0; |
|
1700 | 1790 | } |
1701 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
1702 | - $_SESSION['search_cache']['num_results'] = 0; |
|
1703 | 1791 | } |
1704 | 1792 | } |
1705 | 1793 | |
@@ -1769,14 +1857,16 @@ discard block |
||
1769 | 1857 | ) |
1770 | 1858 | ); |
1771 | 1859 | $posters = array(); |
1772 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1773 | - $posters[] = $row['id_member']; |
|
1860 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1861 | + $posters[] = $row['id_member']; |
|
1862 | + } |
|
1774 | 1863 | $smcFunc['db_free_result']($request); |
1775 | 1864 | |
1776 | 1865 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
1777 | 1866 | |
1778 | - if (!empty($posters)) |
|
1779 | - loadMemberData(array_unique($posters)); |
|
1867 | + if (!empty($posters)) { |
|
1868 | + loadMemberData(array_unique($posters)); |
|
1869 | + } |
|
1780 | 1870 | |
1781 | 1871 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
1782 | 1872 | $messages_request = $smcFunc['db_query']('', ' |
@@ -1809,8 +1899,9 @@ discard block |
||
1809 | 1899 | ); |
1810 | 1900 | |
1811 | 1901 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
1812 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
1813 | - $context['topics'] = array(); |
|
1902 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
1903 | + $context['topics'] = array(); |
|
1904 | + } |
|
1814 | 1905 | |
1815 | 1906 | // If we want to know who participated in what then load this now. |
1816 | 1907 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1828,8 +1919,9 @@ discard block |
||
1828 | 1919 | 'limit' => count($participants), |
1829 | 1920 | ) |
1830 | 1921 | ); |
1831 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1832 | - $participants[$row['id_topic']] = true; |
|
1922 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1923 | + $participants[$row['id_topic']] = true; |
|
1924 | + } |
|
1833 | 1925 | $smcFunc['db_free_result']($result); |
1834 | 1926 | } |
1835 | 1927 | } |
@@ -1838,15 +1930,17 @@ discard block |
||
1838 | 1930 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
1839 | 1931 | |
1840 | 1932 | // Consider the search complete! |
1841 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1842 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1933 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1934 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1935 | + } |
|
1843 | 1936 | |
1844 | 1937 | $context['key_words'] = &$searchArray; |
1845 | 1938 | |
1846 | 1939 | // Setup the default topic icons... for checking they exist and the like! |
1847 | 1940 | $context['icon_sources'] = array(); |
1848 | - foreach ($context['stable_icons'] as $icon) |
|
1849 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1941 | + foreach ($context['stable_icons'] as $icon) { |
|
1942 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1943 | + } |
|
1850 | 1944 | |
1851 | 1945 | $context['sub_template'] = 'results'; |
1852 | 1946 | $context['page_title'] = $txt['search_results']; |
@@ -1877,26 +1971,31 @@ discard block |
||
1877 | 1971 | global $boards_can, $participants, $smcFunc; |
1878 | 1972 | static $recycle_board = null; |
1879 | 1973 | |
1880 | - if ($recycle_board === null) |
|
1881 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1974 | + if ($recycle_board === null) { |
|
1975 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1976 | + } |
|
1882 | 1977 | |
1883 | 1978 | // Remember which message this is. (ie. reply #83) |
1884 | 1979 | static $counter = null; |
1885 | - if ($counter == null || $reset) |
|
1886 | - $counter = $_REQUEST['start'] + 1; |
|
1980 | + if ($counter == null || $reset) { |
|
1981 | + $counter = $_REQUEST['start'] + 1; |
|
1982 | + } |
|
1887 | 1983 | |
1888 | 1984 | // If the query returned false, bail. |
1889 | - if ($messages_request == false) |
|
1890 | - return false; |
|
1985 | + if ($messages_request == false) { |
|
1986 | + return false; |
|
1987 | + } |
|
1891 | 1988 | |
1892 | 1989 | // Start from the beginning... |
1893 | - if ($reset) |
|
1894 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1990 | + if ($reset) { |
|
1991 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1992 | + } |
|
1895 | 1993 | |
1896 | 1994 | // Attempt to get the next message. |
1897 | 1995 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1898 | - if (!$message) |
|
1899 | - return false; |
|
1996 | + if (!$message) { |
|
1997 | + return false; |
|
1998 | + } |
|
1900 | 1999 | |
1901 | 2000 | // Can't have an empty subject can we? |
1902 | 2001 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1935,9 +2034,9 @@ discard block |
||
1935 | 2034 | |
1936 | 2035 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
1937 | 2036 | { |
1938 | - if (empty($context['key_words'])) |
|
1939 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
1940 | - else |
|
2037 | + if (empty($context['key_words'])) { |
|
2038 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
2039 | + } else |
|
1941 | 2040 | { |
1942 | 2041 | $matchString = ''; |
1943 | 2042 | $force_partial_word = false; |
@@ -1946,18 +2045,20 @@ discard block |
||
1946 | 2045 | $keyword = un_htmlspecialchars($keyword); |
1947 | 2046 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
1948 | 2047 | |
1949 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
1950 | - $force_partial_word = true; |
|
2048 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
2049 | + $force_partial_word = true; |
|
2050 | + } |
|
1951 | 2051 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
1952 | 2052 | } |
1953 | 2053 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
1954 | 2054 | |
1955 | 2055 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
1956 | 2056 | |
1957 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
1958 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
1959 | - else |
|
1960 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2057 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
2058 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2059 | + } else { |
|
2060 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2061 | + } |
|
1961 | 2062 | |
1962 | 2063 | $message['body'] = ''; |
1963 | 2064 | foreach ($matches[0] as $index => $match) |
@@ -1970,8 +2071,7 @@ discard block |
||
1970 | 2071 | // Re-fix the international characters. |
1971 | 2072 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
1972 | 2073 | } |
1973 | - } |
|
1974 | - else |
|
2074 | + } else |
|
1975 | 2075 | { |
1976 | 2076 | // Run BBC interpreter on the message. |
1977 | 2077 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1990,21 +2090,26 @@ discard block |
||
1990 | 2090 | // Sadly, we need to check the icon ain't broke. |
1991 | 2091 | if (!empty($modSettings['messageIconChecks_enable'])) |
1992 | 2092 | { |
1993 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1994 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1995 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1996 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1997 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1998 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1999 | - } |
|
2000 | - else |
|
2093 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2094 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2095 | + } |
|
2096 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2097 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2098 | + } |
|
2099 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2100 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2101 | + } |
|
2102 | + } else |
|
2001 | 2103 | { |
2002 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
2003 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2004 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
2005 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2006 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
2007 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2104 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2105 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2106 | + } |
|
2107 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2108 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2109 | + } |
|
2110 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2111 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2112 | + } |
|
2008 | 2113 | } |
2009 | 2114 | |
2010 | 2115 | // Do we have quote tag enabled? |
@@ -2014,12 +2119,14 @@ discard block |
||
2014 | 2119 | $colorClass = 'windowbg'; |
2015 | 2120 | |
2016 | 2121 | // Sticky topics should get a different color, too. |
2017 | - if ($message['is_sticky']) |
|
2018 | - $colorClass .= ' sticky'; |
|
2122 | + if ($message['is_sticky']) { |
|
2123 | + $colorClass .= ' sticky'; |
|
2124 | + } |
|
2019 | 2125 | |
2020 | 2126 | // Locked topics get special treatment as well. |
2021 | - if ($message['locked']) |
|
2022 | - $colorClass .= ' locked'; |
|
2127 | + if ($message['locked']) { |
|
2128 | + $colorClass .= ' locked'; |
|
2129 | + } |
|
2023 | 2130 | |
2024 | 2131 | $output = array_merge($context['topics'][$message['id_msg']], array( |
2025 | 2132 | 'id' => $message['id_topic'], |
@@ -2113,8 +2220,9 @@ discard block |
||
2113 | 2220 | $query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\'')); |
2114 | 2221 | |
2115 | 2222 | // Highlighting empty strings would make a terrible mess... |
2116 | - if (strlen($query) == 0) |
|
2117 | - continue; |
|
2223 | + if (strlen($query) == 0) { |
|
2224 | + continue; |
|
2225 | + } |
|
2118 | 2226 | |
2119 | 2227 | $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
2120 | 2228 | { |
@@ -2167,8 +2275,9 @@ discard block |
||
2167 | 2275 | |
2168 | 2276 | // Load up the search API we are going to use. |
2169 | 2277 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
2170 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
2171 | - fatal_lang_error('search_api_missing'); |
|
2278 | + if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) { |
|
2279 | + fatal_lang_error('search_api_missing'); |
|
2280 | + } |
|
2172 | 2281 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
2173 | 2282 | |
2174 | 2283 | // Create an instance of the search API and check it is valid for this version of SMF. |
@@ -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 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -65,13 +66,16 @@ discard block |
||
65 | 66 | 'db_native_replace' => 'smf_db_native_replace', |
66 | 67 | 'db_cte_support' => 'smf_db_cte_support', |
67 | 68 | ); |
69 | + } |
|
68 | 70 | |
69 | - if (!empty($db_options['persist'])) |
|
70 | - $db_server = 'p:' . $db_server; |
|
71 | + if (!empty($db_options['persist'])) { |
|
72 | + $db_server = 'p:' . $db_server; |
|
73 | + } |
|
71 | 74 | |
72 | 75 | // We are not going to make it very far without these. |
73 | - if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) |
|
74 | - display_db_error(); |
|
76 | + if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) { |
|
77 | + display_db_error(); |
|
78 | + } |
|
75 | 79 | |
76 | 80 | $connection = mysqli_init(); |
77 | 81 | |
@@ -81,29 +85,33 @@ discard block |
||
81 | 85 | |
82 | 86 | if ($connection) |
83 | 87 | { |
84 | - if (!empty($db_options['port'])) |
|
85 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
86 | - else |
|
87 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
88 | + if (!empty($db_options['port'])) { |
|
89 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags); |
|
90 | + } else { |
|
91 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags); |
|
92 | + } |
|
88 | 93 | } |
89 | 94 | |
90 | 95 | // Something's wrong, show an error if its fatal (which we assume it is) |
91 | 96 | if ($success === false) |
92 | 97 | { |
93 | - if (!empty($db_options['non_fatal'])) |
|
94 | - return null; |
|
95 | - else |
|
96 | - display_db_error(); |
|
98 | + if (!empty($db_options['non_fatal'])) { |
|
99 | + return null; |
|
100 | + } else { |
|
101 | + display_db_error(); |
|
102 | + } |
|
97 | 103 | } |
98 | 104 | |
99 | 105 | // Select the database, unless told not to |
100 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
101 | - display_db_error(); |
|
106 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
107 | + display_db_error(); |
|
108 | + } |
|
102 | 109 | |
103 | 110 | mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\''); |
104 | 111 | |
105 | - if (!empty($db_options['db_mb4'])) |
|
106 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
112 | + if (!empty($db_options['db_mb4'])) { |
|
113 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
114 | + } |
|
107 | 115 | |
108 | 116 | return $connection; |
109 | 117 | } |
@@ -174,34 +182,42 @@ discard block |
||
174 | 182 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
175 | 183 | |
176 | 184 | list ($values, $connection) = $db_callback; |
177 | - if (!is_object($connection)) |
|
178 | - display_db_error(); |
|
185 | + if (!is_object($connection)) { |
|
186 | + display_db_error(); |
|
187 | + } |
|
179 | 188 | |
180 | - if ($matches[1] === 'db_prefix') |
|
181 | - return $db_prefix; |
|
189 | + if ($matches[1] === 'db_prefix') { |
|
190 | + return $db_prefix; |
|
191 | + } |
|
182 | 192 | |
183 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
184 | - return $user_info[$matches[1]]; |
|
193 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
194 | + return $user_info[$matches[1]]; |
|
195 | + } |
|
185 | 196 | |
186 | - if ($matches[1] === 'empty') |
|
187 | - return '\'\''; |
|
197 | + if ($matches[1] === 'empty') { |
|
198 | + return '\'\''; |
|
199 | + } |
|
188 | 200 | |
189 | - if (!isset($matches[2])) |
|
190 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + if (!isset($matches[2])) { |
|
202 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
203 | + } |
|
191 | 204 | |
192 | - if ($matches[1] === 'literal') |
|
193 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
205 | + if ($matches[1] === 'literal') { |
|
206 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
207 | + } |
|
194 | 208 | |
195 | - if (!isset($values[$matches[2]])) |
|
196 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!isset($values[$matches[2]])) { |
|
210 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
197 | 212 | |
198 | 213 | $replacement = $values[$matches[2]]; |
199 | 214 | |
200 | 215 | switch ($matches[1]) |
201 | 216 | { |
202 | 217 | case 'int': |
203 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
219 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
220 | + } |
|
205 | 221 | return (string) (int) $replacement; |
206 | 222 | break; |
207 | 223 | |
@@ -213,65 +229,73 @@ discard block |
||
213 | 229 | case 'array_int': |
214 | 230 | if (is_array($replacement)) |
215 | 231 | { |
216 | - if (empty($replacement)) |
|
217 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
232 | + if (empty($replacement)) { |
|
233 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } |
|
218 | 235 | |
219 | 236 | foreach ($replacement as $key => $value) |
220 | 237 | { |
221 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
222 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
238 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
239 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + } |
|
223 | 241 | |
224 | 242 | $replacement[$key] = (string) (int) $value; |
225 | 243 | } |
226 | 244 | |
227 | 245 | return implode(', ', $replacement); |
246 | + } else { |
|
247 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
228 | 248 | } |
229 | - else |
|
230 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | 249 | |
232 | 250 | break; |
233 | 251 | |
234 | 252 | case 'array_string': |
235 | 253 | if (is_array($replacement)) |
236 | 254 | { |
237 | - if (empty($replacement)) |
|
238 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if (empty($replacement)) { |
|
256 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
257 | + } |
|
239 | 258 | |
240 | - foreach ($replacement as $key => $value) |
|
241 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
259 | + foreach ($replacement as $key => $value) { |
|
260 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
261 | + } |
|
242 | 262 | |
243 | 263 | return implode(', ', $replacement); |
264 | + } else { |
|
265 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
244 | 266 | } |
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | 267 | break; |
248 | 268 | |
249 | 269 | case 'date': |
250 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
251 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
270 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
271 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
272 | + } else { |
|
273 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
274 | + } |
|
254 | 275 | break; |
255 | 276 | |
256 | 277 | case 'time': |
257 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
258 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
259 | - else |
|
260 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
278 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
279 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
280 | + } else { |
|
281 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
282 | + } |
|
261 | 283 | break; |
262 | 284 | |
263 | 285 | case 'datetime': |
264 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
265 | - return 'str_to_date('. |
|
286 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
287 | + return 'str_to_date('. |
|
266 | 288 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
267 | 289 | ',\'%Y-%m-%d %h:%i:%s\')'; |
268 | - else |
|
269 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
290 | + } else { |
|
291 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
292 | + } |
|
270 | 293 | break; |
271 | 294 | |
272 | 295 | case 'float': |
273 | - if (!is_numeric($replacement)) |
|
274 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
296 | + if (!is_numeric($replacement)) { |
|
297 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
298 | + } |
|
275 | 299 | return (string) (float) $replacement; |
276 | 300 | break; |
277 | 301 | |
@@ -285,32 +309,37 @@ discard block |
||
285 | 309 | break; |
286 | 310 | |
287 | 311 | case 'inet': |
288 | - if ($replacement == 'null' || $replacement == '') |
|
289 | - return 'null'; |
|
290 | - if (!isValidIP($replacement)) |
|
291 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
312 | + if ($replacement == 'null' || $replacement == '') { |
|
313 | + return 'null'; |
|
314 | + } |
|
315 | + if (!isValidIP($replacement)) { |
|
316 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
292 | 318 | //we don't use the native support of mysql > 5.6.2 |
293 | 319 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
294 | 320 | |
295 | 321 | case 'array_inet': |
296 | 322 | if (is_array($replacement)) |
297 | 323 | { |
298 | - if (empty($replacement)) |
|
299 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
324 | + if (empty($replacement)) { |
|
325 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | |
301 | 328 | foreach ($replacement as $key => $value) |
302 | 329 | { |
303 | - if ($replacement == 'null' || $replacement == '') |
|
304 | - $replacement[$key] = 'null'; |
|
305 | - if (!isValidIP($value)) |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
330 | + if ($replacement == 'null' || $replacement == '') { |
|
331 | + $replacement[$key] = 'null'; |
|
332 | + } |
|
333 | + if (!isValidIP($value)) { |
|
334 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
335 | + } |
|
307 | 336 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
308 | 337 | } |
309 | 338 | |
310 | 339 | return implode(', ', $replacement); |
340 | + } else { |
|
341 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
311 | 342 | } |
312 | - else |
|
313 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
314 | 343 | break; |
315 | 344 | |
316 | 345 | default: |
@@ -381,18 +410,20 @@ discard block |
||
381 | 410 | // One more query.... |
382 | 411 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
383 | 412 | |
384 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
385 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
413 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
414 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
415 | + } |
|
386 | 416 | |
387 | 417 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
388 | 418 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
389 | 419 | { |
390 | 420 | // Add before LIMIT |
391 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
392 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
393 | - else |
|
394 | - // Append it. |
|
421 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
422 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
423 | + } else { |
|
424 | + // Append it. |
|
395 | 425 | $db_string .= "\n\t\t\tORDER BY null"; |
426 | + } |
|
396 | 427 | } |
397 | 428 | |
398 | 429 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -418,17 +449,18 @@ discard block |
||
418 | 449 | while (true) |
419 | 450 | { |
420 | 451 | $pos = strpos($db_string_1, '\'', $pos + 1); |
421 | - if ($pos === false) |
|
422 | - break; |
|
452 | + if ($pos === false) { |
|
453 | + break; |
|
454 | + } |
|
423 | 455 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
424 | 456 | |
425 | 457 | while (true) |
426 | 458 | { |
427 | 459 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
428 | 460 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
429 | - if ($pos1 === false) |
|
430 | - break; |
|
431 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
461 | + if ($pos1 === false) { |
|
462 | + break; |
|
463 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
432 | 464 | { |
433 | 465 | $pos = $pos1; |
434 | 466 | break; |
@@ -444,16 +476,19 @@ discard block |
||
444 | 476 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
445 | 477 | |
446 | 478 | // Comments? We don't use comments in our queries, we leave 'em outside! |
447 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
448 | - $fail = true; |
|
479 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
480 | + $fail = true; |
|
481 | + } |
|
449 | 482 | // Trying to change passwords, slow us down, or something? |
450 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
451 | - $fail = true; |
|
452 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
453 | - $fail = true; |
|
483 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
484 | + $fail = true; |
|
485 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
486 | + $fail = true; |
|
487 | + } |
|
454 | 488 | |
455 | - if (!empty($fail) && function_exists('log_error')) |
|
456 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
489 | + if (!empty($fail) && function_exists('log_error')) { |
|
490 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
491 | + } |
|
457 | 492 | } |
458 | 493 | |
459 | 494 | // Debugging. |
@@ -463,8 +498,9 @@ discard block |
||
463 | 498 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
464 | 499 | |
465 | 500 | // Initialize $db_cache if not already initialized. |
466 | - if (!isset($db_cache)) |
|
467 | - $db_cache = array(); |
|
501 | + if (!isset($db_cache)) { |
|
502 | + $db_cache = array(); |
|
503 | + } |
|
468 | 504 | |
469 | 505 | if (!empty($_SESSION['debug_redirect'])) |
470 | 506 | { |
@@ -480,17 +516,20 @@ discard block |
||
480 | 516 | $db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start; |
481 | 517 | } |
482 | 518 | |
483 | - if (empty($db_unbuffered)) |
|
484 | - $ret = @mysqli_query($connection, $db_string); |
|
485 | - else |
|
486 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
519 | + if (empty($db_unbuffered)) { |
|
520 | + $ret = @mysqli_query($connection, $db_string); |
|
521 | + } else { |
|
522 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
523 | + } |
|
487 | 524 | |
488 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
489 | - $ret = smf_db_error($db_string, $connection); |
|
525 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
526 | + $ret = smf_db_error($db_string, $connection); |
|
527 | + } |
|
490 | 528 | |
491 | 529 | // Debugging. |
492 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
493 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
532 | + } |
|
494 | 533 | |
495 | 534 | return $ret; |
496 | 535 | } |
@@ -537,12 +576,13 @@ discard block |
||
537 | 576 | // Decide which connection to use |
538 | 577 | $connection = $connection === null ? $db_connection : $connection; |
539 | 578 | |
540 | - if ($type == 'begin') |
|
541 | - return @mysqli_query($connection, 'BEGIN'); |
|
542 | - elseif ($type == 'rollback') |
|
543 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
544 | - elseif ($type == 'commit') |
|
545 | - return @mysqli_query($connection, 'COMMIT'); |
|
579 | + if ($type == 'begin') { |
|
580 | + return @mysqli_query($connection, 'BEGIN'); |
|
581 | + } elseif ($type == 'rollback') { |
|
582 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
583 | + } elseif ($type == 'commit') { |
|
584 | + return @mysqli_query($connection, 'COMMIT'); |
|
585 | + } |
|
546 | 586 | |
547 | 587 | return false; |
548 | 588 | } |
@@ -580,8 +620,9 @@ discard block |
||
580 | 620 | // 1213: Deadlock found. |
581 | 621 | |
582 | 622 | // Log the error. |
583 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
584 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
623 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
624 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
625 | + } |
|
585 | 626 | |
586 | 627 | // Database error auto fixing ;). |
587 | 628 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -590,8 +631,9 @@ discard block |
||
590 | 631 | $old_cache = @$modSettings['cache_enable']; |
591 | 632 | $modSettings['cache_enable'] = '1'; |
592 | 633 | |
593 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
594 | - $db_last_error = max(@$db_last_error, $temp); |
|
634 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
635 | + $db_last_error = max(@$db_last_error, $temp); |
|
636 | + } |
|
595 | 637 | |
596 | 638 | if (@$db_last_error < time() - 3600 * 24 * 3) |
597 | 639 | { |
@@ -607,8 +649,9 @@ discard block |
||
607 | 649 | foreach ($tables as $table) |
608 | 650 | { |
609 | 651 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
610 | - if (trim($table) != '') |
|
611 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
652 | + if (trim($table) != '') { |
|
653 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
654 | + } |
|
612 | 655 | } |
613 | 656 | } |
614 | 657 | |
@@ -617,8 +660,9 @@ discard block |
||
617 | 660 | // Table crashed. Let's try to fix it. |
618 | 661 | elseif ($query_errno == 1016) |
619 | 662 | { |
620 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
621 | - $fix_tables = array('`' . $match[1] . '`'); |
|
663 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
664 | + $fix_tables = array('`' . $match[1] . '`'); |
|
665 | + } |
|
622 | 666 | } |
623 | 667 | // Indexes crashed. Should be easy to fix! |
624 | 668 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -637,13 +681,15 @@ discard block |
||
637 | 681 | |
638 | 682 | // Make a note of the REPAIR... |
639 | 683 | cache_put_data('db_last_error', time(), 600); |
640 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
641 | - updateSettingsFile(array('db_last_error' => time())); |
|
684 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
685 | + updateSettingsFile(array('db_last_error' => time())); |
|
686 | + } |
|
642 | 687 | |
643 | 688 | // Attempt to find and repair the broken table. |
644 | - foreach ($fix_tables as $table) |
|
645 | - $smcFunc['db_query']('', " |
|
689 | + foreach ($fix_tables as $table) { |
|
690 | + $smcFunc['db_query']('', " |
|
646 | 691 | REPAIR TABLE $table", false, false); |
692 | + } |
|
647 | 693 | |
648 | 694 | // And send off an email! |
649 | 695 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -652,11 +698,12 @@ discard block |
||
652 | 698 | |
653 | 699 | // Try the query again...? |
654 | 700 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
655 | - if ($ret !== false) |
|
656 | - return $ret; |
|
701 | + if ($ret !== false) { |
|
702 | + return $ret; |
|
703 | + } |
|
704 | + } else { |
|
705 | + $modSettings['cache_enable'] = $old_cache; |
|
657 | 706 | } |
658 | - else |
|
659 | - $modSettings['cache_enable'] = $old_cache; |
|
660 | 707 | |
661 | 708 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
662 | 709 | if (in_array($query_errno, array(1205, 1213))) |
@@ -669,24 +716,27 @@ discard block |
||
669 | 716 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
670 | 717 | |
671 | 718 | $new_errno = mysqli_errno($db_connection); |
672 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
673 | - break; |
|
719 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
720 | + break; |
|
721 | + } |
|
674 | 722 | } |
675 | 723 | |
676 | 724 | // If it failed again, shucks to be you... we're not trying it over and over. |
677 | - if ($ret !== false) |
|
678 | - return $ret; |
|
725 | + if ($ret !== false) { |
|
726 | + return $ret; |
|
727 | + } |
|
679 | 728 | } |
680 | 729 | } |
681 | 730 | // Are they out of space, perhaps? |
682 | 731 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
683 | 732 | { |
684 | - if (!isset($txt)) |
|
685 | - $query_error .= ' - check database storage space.'; |
|
686 | - else |
|
733 | + if (!isset($txt)) { |
|
734 | + $query_error .= ' - check database storage space.'; |
|
735 | + } else |
|
687 | 736 | { |
688 | - if (!isset($txt['mysql_error_space'])) |
|
689 | - loadLanguage('Errors'); |
|
737 | + if (!isset($txt['mysql_error_space'])) { |
|
738 | + loadLanguage('Errors'); |
|
739 | + } |
|
690 | 740 | |
691 | 741 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
692 | 742 | } |
@@ -694,15 +744,17 @@ discard block |
||
694 | 744 | } |
695 | 745 | |
696 | 746 | // Nothing's defined yet... just die with it. |
697 | - if (empty($context) || empty($txt)) |
|
698 | - die($query_error); |
|
747 | + if (empty($context) || empty($txt)) { |
|
748 | + die($query_error); |
|
749 | + } |
|
699 | 750 | |
700 | 751 | // Show an error message, if possible. |
701 | 752 | $context['error_title'] = $txt['database_error']; |
702 | - if (allowedTo('admin_forum')) |
|
703 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
704 | - else |
|
705 | - $context['error_message'] = $txt['try_again']; |
|
753 | + if (allowedTo('admin_forum')) { |
|
754 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
755 | + } else { |
|
756 | + $context['error_message'] = $txt['try_again']; |
|
757 | + } |
|
706 | 758 | |
707 | 759 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
708 | 760 | { |
@@ -734,8 +786,9 @@ discard block |
||
734 | 786 | $return_var = null; |
735 | 787 | |
736 | 788 | // With nothing to insert, simply return. |
737 | - if (empty($data)) |
|
738 | - return; |
|
789 | + if (empty($data)) { |
|
790 | + return; |
|
791 | + } |
|
739 | 792 | |
740 | 793 | // Replace the prefix holder with the actual prefix. |
741 | 794 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -745,23 +798,26 @@ discard block |
||
745 | 798 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
746 | 799 | { |
747 | 800 | $with_returning = true; |
748 | - if ($returnmode == 2) |
|
749 | - $return_var = array(); |
|
801 | + if ($returnmode == 2) { |
|
802 | + $return_var = array(); |
|
803 | + } |
|
750 | 804 | } |
751 | 805 | |
752 | 806 | // Inserting data as a single row can be done as a single array. |
753 | - if (!is_array($data[array_rand($data)])) |
|
754 | - $data = array($data); |
|
807 | + if (!is_array($data[array_rand($data)])) { |
|
808 | + $data = array($data); |
|
809 | + } |
|
755 | 810 | |
756 | 811 | // Create the mold for a single row insert. |
757 | 812 | $insertData = '('; |
758 | 813 | foreach ($columns as $columnName => $type) |
759 | 814 | { |
760 | 815 | // Are we restricting the length? |
761 | - if (strpos($type, 'string-') !== false) |
|
762 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
763 | - else |
|
764 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
816 | + if (strpos($type, 'string-') !== false) { |
|
817 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
818 | + } else { |
|
819 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
820 | + } |
|
765 | 821 | } |
766 | 822 | $insertData = substr($insertData, 0, -2) . ')'; |
767 | 823 | |
@@ -770,8 +826,9 @@ discard block |
||
770 | 826 | |
771 | 827 | // Here's where the variables are injected to the query. |
772 | 828 | $insertRows = array(); |
773 | - foreach ($data as $dataRow) |
|
774 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
829 | + foreach ($data as $dataRow) { |
|
830 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
831 | + } |
|
775 | 832 | |
776 | 833 | // Determine the method of insertion. |
777 | 834 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -790,8 +847,7 @@ discard block |
||
790 | 847 | ), |
791 | 848 | $connection |
792 | 849 | ); |
793 | - } |
|
794 | - else //special way for ignore method with returning |
|
850 | + } else //special way for ignore method with returning |
|
795 | 851 | { |
796 | 852 | $count = count($insertRows); |
797 | 853 | $ai = 0; |
@@ -811,19 +867,21 @@ discard block |
||
811 | 867 | ); |
812 | 868 | $new_id = $smcFunc['db_insert_id'](); |
813 | 869 | |
814 | - if ($last_id != $new_id) //the inserted value was new |
|
870 | + if ($last_id != $new_id) { |
|
871 | + //the inserted value was new |
|
815 | 872 | { |
816 | 873 | $ai = $new_id; |
817 | 874 | } |
818 | - else // the inserted value already exists we need to find the pk |
|
875 | + } else // the inserted value already exists we need to find the pk |
|
819 | 876 | { |
820 | 877 | $where_string = ''; |
821 | 878 | $count2 = count($indexed_columns); |
822 | 879 | for ($x = 0; $x < $count2; $x++) |
823 | 880 | { |
824 | 881 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
825 | - if (($x + 1) < $count2) |
|
826 | - $where_string += ' AND '; |
|
882 | + if (($x + 1) < $count2) { |
|
883 | + $where_string += ' AND '; |
|
884 | + } |
|
827 | 885 | } |
828 | 886 | |
829 | 887 | $request = $smcFunc['db_query']('',' |
@@ -839,25 +897,27 @@ discard block |
||
839 | 897 | } |
840 | 898 | } |
841 | 899 | |
842 | - if ($returnmode == 1) |
|
843 | - $return_var = $ai; |
|
844 | - else if ($returnmode == 2) |
|
845 | - $return_var[] = $ai; |
|
900 | + if ($returnmode == 1) { |
|
901 | + $return_var = $ai; |
|
902 | + } else if ($returnmode == 2) { |
|
903 | + $return_var[] = $ai; |
|
904 | + } |
|
846 | 905 | } |
847 | 906 | } |
848 | 907 | |
849 | 908 | |
850 | 909 | if ($with_returning) |
851 | 910 | { |
852 | - if ($returnmode == 1 && empty($return_var)) |
|
853 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
854 | - else if ($returnmode == 2 && empty($return_var)) |
|
911 | + if ($returnmode == 1 && empty($return_var)) { |
|
912 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
913 | + } else if ($returnmode == 2 && empty($return_var)) |
|
855 | 914 | { |
856 | 915 | $return_var = array(); |
857 | 916 | $count = count($insertRows); |
858 | 917 | $start = smf_db_insert_id($table, $keys[0]); |
859 | - for ($i = 0; $i < $count; $i++ ) |
|
860 | - $return_var[] = $start + $i; |
|
918 | + for ($i = 0; $i < $count; $i++ ) { |
|
919 | + $return_var[] = $start + $i; |
|
920 | + } |
|
861 | 921 | } |
862 | 922 | return $return_var; |
863 | 923 | } |
@@ -875,8 +935,9 @@ discard block |
||
875 | 935 | */ |
876 | 936 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
877 | 937 | { |
878 | - if (empty($log_message)) |
|
879 | - $log_message = $error_message; |
|
938 | + if (empty($log_message)) { |
|
939 | + $log_message = $error_message; |
|
940 | + } |
|
880 | 941 | |
881 | 942 | foreach (debug_backtrace() as $step) |
882 | 943 | { |
@@ -895,12 +956,14 @@ discard block |
||
895 | 956 | } |
896 | 957 | |
897 | 958 | // A special case - we want the file and line numbers for debugging. |
898 | - if ($error_type == 'return') |
|
899 | - return array($file, $line); |
|
959 | + if ($error_type == 'return') { |
|
960 | + return array($file, $line); |
|
961 | + } |
|
900 | 962 | |
901 | 963 | // Is always a critical error. |
902 | - if (function_exists('log_error')) |
|
903 | - log_error($log_message, 'critical', $file, $line); |
|
964 | + if (function_exists('log_error')) { |
|
965 | + log_error($log_message, 'critical', $file, $line); |
|
966 | + } |
|
904 | 967 | |
905 | 968 | if (function_exists('fatal_error')) |
906 | 969 | { |
@@ -908,12 +971,12 @@ discard block |
||
908 | 971 | |
909 | 972 | // Cannot continue... |
910 | 973 | exit; |
974 | + } elseif ($error_type) { |
|
975 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
976 | + } else { |
|
977 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
978 | + } |
|
911 | 979 | } |
912 | - elseif ($error_type) |
|
913 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
914 | - else |
|
915 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
916 | -} |
|
917 | 980 | |
918 | 981 | /** |
919 | 982 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -930,10 +993,11 @@ discard block |
||
930 | 993 | '\\' => '\\\\', |
931 | 994 | ); |
932 | 995 | |
933 | - if ($translate_human_wildcards) |
|
934 | - $replacements += array( |
|
996 | + if ($translate_human_wildcards) { |
|
997 | + $replacements += array( |
|
935 | 998 | '*' => '%', |
936 | 999 | ); |
1000 | + } |
|
937 | 1001 | |
938 | 1002 | return strtr($string, $replacements); |
939 | 1003 | } |
@@ -947,8 +1011,9 @@ discard block |
||
947 | 1011 | */ |
948 | 1012 | function smf_is_resource($result) |
949 | 1013 | { |
950 | - if ($result instanceof mysqli_result) |
|
951 | - return true; |
|
1014 | + if ($result instanceof mysqli_result) { |
|
1015 | + return true; |
|
1016 | + } |
|
952 | 1017 | |
953 | 1018 | return false; |
954 | 1019 | } |
@@ -977,19 +1042,22 @@ discard block |
||
977 | 1042 | static $mysql_error_data_prep; |
978 | 1043 | |
979 | 1044 | // without database we can't do anything |
980 | - if (empty($db_connection)) |
|
981 | - return; |
|
1045 | + if (empty($db_connection)) { |
|
1046 | + return; |
|
1047 | + } |
|
982 | 1048 | |
983 | - if (empty($mysql_error_data_prep)) |
|
984 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1049 | + if (empty($mysql_error_data_prep)) { |
|
1050 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
985 | 1051 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
986 | 1052 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?, ?)' |
987 | 1053 | ); |
1054 | + } |
|
988 | 1055 | |
989 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
990 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
991 | - else |
|
992 | - $error_array[2] = null; |
|
1056 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1057 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1058 | + } else { |
|
1059 | + $error_array[2] = null; |
|
1060 | + } |
|
993 | 1061 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis', |
994 | 1062 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
995 | 1063 | $error_array[7], $error_array[8], $error_array[9]); |
@@ -1011,8 +1079,9 @@ discard block |
||
1011 | 1079 | $count = count($array_values); |
1012 | 1080 | $then = ($desc ? ' THEN -' : ' THEN '); |
1013 | 1081 | |
1014 | - for ($i = 0; $i < $count; $i++) |
|
1015 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1082 | + for ($i = 0; $i < $count; $i++) { |
|
1083 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1084 | + } |
|
1016 | 1085 | |
1017 | 1086 | $return .= 'END'; |
1018 | 1087 | return $return; |
@@ -1038,17 +1107,20 @@ discard block |
||
1038 | 1107 | global $smcFunc; |
1039 | 1108 | static $return; |
1040 | 1109 | |
1041 | - if (isset($return)) |
|
1042 | - return $return; |
|
1110 | + if (isset($return)) { |
|
1111 | + return $return; |
|
1112 | + } |
|
1043 | 1113 | |
1044 | 1114 | db_extend('extra'); |
1045 | 1115 | |
1046 | 1116 | $version = $smcFunc['db_get_version'](); |
1047 | 1117 | |
1048 | - if (strpos(strtolower($version), 'mariadb') !== false) |
|
1049 | - $return = version_compare($version, '10.2.2', '>='); |
|
1050 | - else //mysql |
|
1118 | + if (strpos(strtolower($version), 'mariadb') !== false) { |
|
1119 | + $return = version_compare($version, '10.2.2', '>='); |
|
1120 | + } else { |
|
1121 | + //mysql |
|
1051 | 1122 | $return = version_compare($version, '8.0.1', '>='); |
1123 | + } |
|
1052 | 1124 | |
1053 | 1125 | return $return; |
1054 | 1126 | } |
@@ -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 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -66,15 +67,18 @@ discard block |
||
66 | 67 | 'db_native_replace' => 'smf_db_native_replace', |
67 | 68 | 'db_cte_support' => 'smf_db_cte_support', |
68 | 69 | ); |
70 | + } |
|
69 | 71 | |
70 | 72 | // We are not going to make it very far without these. |
71 | - if (!function_exists('pg_pconnect')) |
|
72 | - display_db_error(); |
|
73 | + if (!function_exists('pg_pconnect')) { |
|
74 | + display_db_error(); |
|
75 | + } |
|
73 | 76 | |
74 | - if (!empty($db_options['persist'])) |
|
75 | - $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
76 | - else |
|
77 | - $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
77 | + if (!empty($db_options['persist'])) { |
|
78 | + $connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
79 | + } else { |
|
80 | + $connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
81 | + } |
|
78 | 82 | |
79 | 83 | // Something's wrong, show an error if its fatal (which we assume it is) |
80 | 84 | if (!$connection) |
@@ -82,15 +86,15 @@ discard block |
||
82 | 86 | if (!empty($db_options['non_fatal'])) |
83 | 87 | { |
84 | 88 | return null; |
85 | - } |
|
86 | - else |
|
89 | + } else |
|
87 | 90 | { |
88 | 91 | display_db_error(); |
89 | 92 | } |
90 | 93 | } |
91 | 94 | |
92 | - if (!empty($db_options['db_mb4'])) |
|
93 | - $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
95 | + if (!empty($db_options['db_mb4'])) { |
|
96 | + $smcFunc['db_mb4'] = (bool) $db_options['db_mb4']; |
|
97 | + } |
|
94 | 98 | |
95 | 99 | return $connection; |
96 | 100 | } |
@@ -137,31 +141,38 @@ discard block |
||
137 | 141 | |
138 | 142 | list ($values, $connection) = $db_callback; |
139 | 143 | |
140 | - if ($matches[1] === 'db_prefix') |
|
141 | - return $db_prefix; |
|
144 | + if ($matches[1] === 'db_prefix') { |
|
145 | + return $db_prefix; |
|
146 | + } |
|
142 | 147 | |
143 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
144 | - return $user_info[$matches[1]]; |
|
148 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
149 | + return $user_info[$matches[1]]; |
|
150 | + } |
|
145 | 151 | |
146 | - if ($matches[1] === 'empty') |
|
147 | - return '\'\''; |
|
152 | + if ($matches[1] === 'empty') { |
|
153 | + return '\'\''; |
|
154 | + } |
|
148 | 155 | |
149 | - if (!isset($matches[2])) |
|
150 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
156 | + if (!isset($matches[2])) { |
|
157 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
158 | + } |
|
151 | 159 | |
152 | - if ($matches[1] === 'literal') |
|
153 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
160 | + if ($matches[1] === 'literal') { |
|
161 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
162 | + } |
|
154 | 163 | |
155 | - if (!isset($values[$matches[2]])) |
|
156 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
164 | + if (!isset($values[$matches[2]])) { |
|
165 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
166 | + } |
|
157 | 167 | |
158 | 168 | $replacement = $values[$matches[2]]; |
159 | 169 | |
160 | 170 | switch ($matches[1]) |
161 | 171 | { |
162 | 172 | case 'int': |
163 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
164 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
173 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
174 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
175 | + } |
|
165 | 176 | return (string) (int) $replacement; |
166 | 177 | break; |
167 | 178 | |
@@ -173,65 +184,73 @@ discard block |
||
173 | 184 | case 'array_int': |
174 | 185 | if (is_array($replacement)) |
175 | 186 | { |
176 | - if (empty($replacement)) |
|
177 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
187 | + if (empty($replacement)) { |
|
188 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
189 | + } |
|
178 | 190 | |
179 | 191 | foreach ($replacement as $key => $value) |
180 | 192 | { |
181 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
182 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
193 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
194 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | + } |
|
183 | 196 | |
184 | 197 | $replacement[$key] = (string) (int) $value; |
185 | 198 | } |
186 | 199 | |
187 | 200 | return implode(', ', $replacement); |
201 | + } else { |
|
202 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
188 | 203 | } |
189 | - else |
|
190 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
191 | 204 | |
192 | 205 | break; |
193 | 206 | |
194 | 207 | case 'array_string': |
195 | 208 | if (is_array($replacement)) |
196 | 209 | { |
197 | - if (empty($replacement)) |
|
198 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
210 | + if (empty($replacement)) { |
|
211 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
212 | + } |
|
199 | 213 | |
200 | - foreach ($replacement as $key => $value) |
|
201 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
214 | + foreach ($replacement as $key => $value) { |
|
215 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
216 | + } |
|
202 | 217 | |
203 | 218 | return implode(', ', $replacement); |
219 | + } else { |
|
220 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
204 | 221 | } |
205 | - else |
|
206 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
207 | 222 | break; |
208 | 223 | |
209 | 224 | case 'date': |
210 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
211 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
212 | - else |
|
213 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
226 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
227 | + } else { |
|
228 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + } |
|
214 | 230 | break; |
215 | 231 | |
216 | 232 | case 'time': |
217 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
218 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
233 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
234 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
235 | + } else { |
|
236 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | + } |
|
221 | 238 | break; |
222 | 239 | |
223 | 240 | case 'datetime': |
224 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
225 | - return 'to_timestamp('. |
|
241 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
242 | + return 'to_timestamp('. |
|
226 | 243 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
227 | 244 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
228 | - else |
|
229 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
245 | + } else { |
|
246 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
247 | + } |
|
230 | 248 | break; |
231 | 249 | |
232 | 250 | case 'float': |
233 | - if (!is_numeric($replacement)) |
|
234 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
251 | + if (!is_numeric($replacement)) { |
|
252 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
253 | + } |
|
235 | 254 | return (string) (float) $replacement; |
236 | 255 | break; |
237 | 256 | |
@@ -244,31 +263,36 @@ discard block |
||
244 | 263 | break; |
245 | 264 | |
246 | 265 | case 'inet': |
247 | - if ($replacement == 'null' || $replacement == '') |
|
248 | - return 'null'; |
|
249 | - if (inet_pton($replacement) === false) |
|
250 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if ($replacement == 'null' || $replacement == '') { |
|
267 | + return 'null'; |
|
268 | + } |
|
269 | + if (inet_pton($replacement) === false) { |
|
270 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
271 | + } |
|
251 | 272 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
252 | 273 | |
253 | 274 | case 'array_inet': |
254 | 275 | if (is_array($replacement)) |
255 | 276 | { |
256 | - if (empty($replacement)) |
|
257 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + if (empty($replacement)) { |
|
278 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
279 | + } |
|
258 | 280 | |
259 | 281 | foreach ($replacement as $key => $value) |
260 | 282 | { |
261 | - if ($replacement == 'null' || $replacement == '') |
|
262 | - $replacement[$key] = 'null'; |
|
263 | - if (!isValidIP($value)) |
|
264 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + if ($replacement == 'null' || $replacement == '') { |
|
284 | + $replacement[$key] = 'null'; |
|
285 | + } |
|
286 | + if (!isValidIP($value)) { |
|
287 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
288 | + } |
|
265 | 289 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
266 | 290 | } |
267 | 291 | |
268 | 292 | return implode(', ', $replacement); |
293 | + } else { |
|
294 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | 295 | } |
270 | - else |
|
271 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | 296 | break; |
273 | 297 | |
274 | 298 | default: |
@@ -356,14 +380,16 @@ discard block |
||
356 | 380 | ), |
357 | 381 | ); |
358 | 382 | |
359 | - if (isset($replacements[$identifier])) |
|
360 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
383 | + if (isset($replacements[$identifier])) { |
|
384 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
385 | + } |
|
361 | 386 | |
362 | 387 | // Limits need to be a little different. |
363 | 388 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
364 | 389 | |
365 | - if (trim($db_string) == '') |
|
366 | - return false; |
|
390 | + if (trim($db_string) == '') { |
|
391 | + return false; |
|
392 | + } |
|
367 | 393 | |
368 | 394 | // Comments that are allowed in a query are preg_removed. |
369 | 395 | static $allowed_comments_from = array( |
@@ -383,8 +409,9 @@ discard block |
||
383 | 409 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
384 | 410 | $db_replace_result = 0; |
385 | 411 | |
386 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
387 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
412 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
413 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
414 | + } |
|
388 | 415 | |
389 | 416 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
390 | 417 | { |
@@ -409,17 +436,18 @@ discard block |
||
409 | 436 | while (true) |
410 | 437 | { |
411 | 438 | $pos = strpos($db_string_1, '\'', $pos + 1); |
412 | - if ($pos === false) |
|
413 | - break; |
|
439 | + if ($pos === false) { |
|
440 | + break; |
|
441 | + } |
|
414 | 442 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
415 | 443 | |
416 | 444 | while (true) |
417 | 445 | { |
418 | 446 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
419 | 447 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
420 | - if ($pos1 === false) |
|
421 | - break; |
|
422 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
448 | + if ($pos1 === false) { |
|
449 | + break; |
|
450 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
423 | 451 | { |
424 | 452 | $pos = $pos1; |
425 | 453 | break; |
@@ -435,16 +463,19 @@ discard block |
||
435 | 463 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
436 | 464 | |
437 | 465 | // Comments? We don't use comments in our queries, we leave 'em outside! |
438 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
439 | - $fail = true; |
|
466 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
467 | + $fail = true; |
|
468 | + } |
|
440 | 469 | // Trying to change passwords, slow us down, or something? |
441 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
442 | - $fail = true; |
|
443 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
444 | - $fail = true; |
|
470 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
471 | + $fail = true; |
|
472 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
473 | + $fail = true; |
|
474 | + } |
|
445 | 475 | |
446 | - if (!empty($fail) && function_exists('log_error')) |
|
447 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
476 | + if (!empty($fail) && function_exists('log_error')) { |
|
477 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
478 | + } |
|
448 | 479 | } |
449 | 480 | |
450 | 481 | // Set optimize stuff |
@@ -471,8 +502,9 @@ discard block |
||
471 | 502 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
472 | 503 | |
473 | 504 | // Initialize $db_cache if not already initialized. |
474 | - if (!isset($db_cache)) |
|
475 | - $db_cache = array(); |
|
505 | + if (!isset($db_cache)) { |
|
506 | + $db_cache = array(); |
|
507 | + } |
|
476 | 508 | |
477 | 509 | if (!empty($_SESSION['debug_redirect'])) |
478 | 510 | { |
@@ -490,12 +522,14 @@ discard block |
||
490 | 522 | |
491 | 523 | $db_last_result = @pg_query($connection, $db_string); |
492 | 524 | |
493 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
494 | - $db_last_result = smf_db_error($db_string, $connection); |
|
525 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
526 | + $db_last_result = smf_db_error($db_string, $connection); |
|
527 | + } |
|
495 | 528 | |
496 | 529 | // Debugging. |
497 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
498 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
530 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
531 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
532 | + } |
|
499 | 533 | |
500 | 534 | return $db_last_result; |
501 | 535 | } |
@@ -512,10 +546,11 @@ discard block |
||
512 | 546 | { |
513 | 547 | global $db_last_result, $db_replace_result; |
514 | 548 | |
515 | - if ($db_replace_result) |
|
516 | - return $db_replace_result; |
|
517 | - elseif ($result === null && !$db_last_result) |
|
518 | - return 0; |
|
549 | + if ($db_replace_result) { |
|
550 | + return $db_replace_result; |
|
551 | + } elseif ($result === null && !$db_last_result) { |
|
552 | + return 0; |
|
553 | + } |
|
519 | 554 | |
520 | 555 | return pg_affected_rows($result === null ? $db_last_result : $result); |
521 | 556 | } |
@@ -539,8 +574,9 @@ discard block |
||
539 | 574 | array( |
540 | 575 | ) |
541 | 576 | ); |
542 | - if (!$request) |
|
543 | - return false; |
|
577 | + if (!$request) { |
|
578 | + return false; |
|
579 | + } |
|
544 | 580 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
545 | 581 | $smcFunc['db_free_result']($request); |
546 | 582 | |
@@ -561,12 +597,13 @@ discard block |
||
561 | 597 | // Decide which connection to use |
562 | 598 | $connection = $connection === null ? $db_connection : $connection; |
563 | 599 | |
564 | - if ($type == 'begin') |
|
565 | - return @pg_query($connection, 'BEGIN'); |
|
566 | - elseif ($type == 'rollback') |
|
567 | - return @pg_query($connection, 'ROLLBACK'); |
|
568 | - elseif ($type == 'commit') |
|
569 | - return @pg_query($connection, 'COMMIT'); |
|
600 | + if ($type == 'begin') { |
|
601 | + return @pg_query($connection, 'BEGIN'); |
|
602 | + } elseif ($type == 'rollback') { |
|
603 | + return @pg_query($connection, 'ROLLBACK'); |
|
604 | + } elseif ($type == 'commit') { |
|
605 | + return @pg_query($connection, 'COMMIT'); |
|
606 | + } |
|
570 | 607 | |
571 | 608 | return false; |
572 | 609 | } |
@@ -594,19 +631,22 @@ discard block |
||
594 | 631 | $query_error = @pg_last_error($connection); |
595 | 632 | |
596 | 633 | // Log the error. |
597 | - if (function_exists('log_error')) |
|
598 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
634 | + if (function_exists('log_error')) { |
|
635 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
636 | + } |
|
599 | 637 | |
600 | 638 | // Nothing's defined yet... just die with it. |
601 | - if (empty($context) || empty($txt)) |
|
602 | - die($query_error); |
|
639 | + if (empty($context) || empty($txt)) { |
|
640 | + die($query_error); |
|
641 | + } |
|
603 | 642 | |
604 | 643 | // Show an error message, if possible. |
605 | 644 | $context['error_title'] = $txt['database_error']; |
606 | - if (allowedTo('admin_forum')) |
|
607 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
608 | - else |
|
609 | - $context['error_message'] = $txt['try_again']; |
|
645 | + if (allowedTo('admin_forum')) { |
|
646 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
647 | + } else { |
|
648 | + $context['error_message'] = $txt['try_again']; |
|
649 | + } |
|
610 | 650 | |
611 | 651 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
612 | 652 | { |
@@ -628,12 +668,14 @@ discard block |
||
628 | 668 | { |
629 | 669 | global $db_row_count; |
630 | 670 | |
631 | - if ($counter !== false) |
|
632 | - return pg_fetch_row($request, $counter); |
|
671 | + if ($counter !== false) { |
|
672 | + return pg_fetch_row($request, $counter); |
|
673 | + } |
|
633 | 674 | |
634 | 675 | // Reset the row counter... |
635 | - if (!isset($db_row_count[(int) $request])) |
|
636 | - $db_row_count[(int) $request] = 0; |
|
676 | + if (!isset($db_row_count[(int) $request])) { |
|
677 | + $db_row_count[(int) $request] = 0; |
|
678 | + } |
|
637 | 679 | |
638 | 680 | // Return the right row. |
639 | 681 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -650,12 +692,14 @@ discard block |
||
650 | 692 | { |
651 | 693 | global $db_row_count; |
652 | 694 | |
653 | - if ($counter !== false) |
|
654 | - return pg_fetch_assoc($request, $counter); |
|
695 | + if ($counter !== false) { |
|
696 | + return pg_fetch_assoc($request, $counter); |
|
697 | + } |
|
655 | 698 | |
656 | 699 | // Reset the row counter... |
657 | - if (!isset($db_row_count[(int) $request])) |
|
658 | - $db_row_count[(int) $request] = 0; |
|
700 | + if (!isset($db_row_count[(int) $request])) { |
|
701 | + $db_row_count[(int) $request] = 0; |
|
702 | + } |
|
659 | 703 | |
660 | 704 | // Return the right row. |
661 | 705 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -708,11 +752,13 @@ discard block |
||
708 | 752 | |
709 | 753 | $replace = ''; |
710 | 754 | |
711 | - if (empty($data)) |
|
712 | - return; |
|
755 | + if (empty($data)) { |
|
756 | + return; |
|
757 | + } |
|
713 | 758 | |
714 | - if (!is_array($data[array_rand($data)])) |
|
715 | - $data = array($data); |
|
759 | + if (!is_array($data[array_rand($data)])) { |
|
760 | + $data = array($data); |
|
761 | + } |
|
716 | 762 | |
717 | 763 | // Replace the prefix holder with the actual prefix. |
718 | 764 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -738,32 +784,35 @@ discard block |
||
738 | 784 | $key_str .= ($count_pk > 0 ? ',' : ''); |
739 | 785 | $key_str .= $columnName; |
740 | 786 | $count_pk++; |
741 | - } |
|
742 | - else if ($method == 'replace') //normal field |
|
787 | + } else if ($method == 'replace') { |
|
788 | + //normal field |
|
743 | 789 | { |
744 | 790 | $col_str .= ($count > 0 ? ',' : ''); |
791 | + } |
|
745 | 792 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
746 | 793 | $count++; |
747 | 794 | } |
748 | 795 | } |
749 | - if ($method == 'replace') |
|
750 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
751 | - else |
|
752 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
753 | - } |
|
754 | - else if ($method == 'replace') |
|
796 | + if ($method == 'replace') { |
|
797 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
798 | + } else { |
|
799 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
800 | + } |
|
801 | + } else if ($method == 'replace') |
|
755 | 802 | { |
756 | 803 | foreach ($columns as $columnName => $type) |
757 | 804 | { |
758 | 805 | // Are we restricting the length? |
759 | - if (strpos($type, 'string-') !== false) |
|
760 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
761 | - else |
|
762 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
806 | + if (strpos($type, 'string-') !== false) { |
|
807 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
808 | + } else { |
|
809 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
810 | + } |
|
763 | 811 | |
764 | 812 | // A key? That's what we were looking for. |
765 | - if (in_array($columnName, $keys)) |
|
766 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
813 | + if (in_array($columnName, $keys)) { |
|
814 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
815 | + } |
|
767 | 816 | $count++; |
768 | 817 | } |
769 | 818 | |
@@ -799,10 +848,11 @@ discard block |
||
799 | 848 | foreach ($columns as $columnName => $type) |
800 | 849 | { |
801 | 850 | // Are we restricting the length? |
802 | - if (strpos($type, 'string-') !== false) |
|
803 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
804 | - else |
|
805 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
851 | + if (strpos($type, 'string-') !== false) { |
|
852 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
853 | + } else { |
|
854 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
855 | + } |
|
806 | 856 | } |
807 | 857 | $insertData = substr($insertData, 0, -2) . ')'; |
808 | 858 | |
@@ -811,8 +861,9 @@ discard block |
||
811 | 861 | |
812 | 862 | // Here's where the variables are injected to the query. |
813 | 863 | $insertRows = array(); |
814 | - foreach ($data as $dataRow) |
|
815 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
864 | + foreach ($data as $dataRow) { |
|
865 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
866 | + } |
|
816 | 867 | |
817 | 868 | // Do the insert. |
818 | 869 | $request = $smcFunc['db_query']('', ' |
@@ -829,19 +880,21 @@ discard block |
||
829 | 880 | |
830 | 881 | if ($with_returning && $request !== false) |
831 | 882 | { |
832 | - if ($returnmode === 2) |
|
833 | - $return_var = array(); |
|
883 | + if ($returnmode === 2) { |
|
884 | + $return_var = array(); |
|
885 | + } |
|
834 | 886 | |
835 | 887 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
836 | 888 | { |
837 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
889 | + if (is_numeric($row[0])) { |
|
890 | + // try to emulate mysql limitation |
|
838 | 891 | { |
839 | 892 | if ($returnmode === 1) |
840 | 893 | $return_var = $row[0]; |
841 | - elseif ($returnmode === 2) |
|
842 | - $return_var[] = $row[0]; |
|
843 | - } |
|
844 | - else |
|
894 | + } elseif ($returnmode === 2) { |
|
895 | + $return_var[] = $row[0]; |
|
896 | + } |
|
897 | + } else |
|
845 | 898 | { |
846 | 899 | $with_returning = false; |
847 | 900 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -850,9 +903,10 @@ discard block |
||
850 | 903 | } |
851 | 904 | } |
852 | 905 | |
853 | - if ($with_returning && !empty($return_var)) |
|
854 | - return $return_var; |
|
855 | -} |
|
906 | + if ($with_returning && !empty($return_var)) { |
|
907 | + return $return_var; |
|
908 | + } |
|
909 | + } |
|
856 | 910 | |
857 | 911 | /** |
858 | 912 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -889,8 +943,9 @@ discard block |
||
889 | 943 | */ |
890 | 944 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
891 | 945 | { |
892 | - if (empty($log_message)) |
|
893 | - $log_message = $error_message; |
|
946 | + if (empty($log_message)) { |
|
947 | + $log_message = $error_message; |
|
948 | + } |
|
894 | 949 | |
895 | 950 | foreach (debug_backtrace() as $step) |
896 | 951 | { |
@@ -909,12 +964,14 @@ discard block |
||
909 | 964 | } |
910 | 965 | |
911 | 966 | // A special case - we want the file and line numbers for debugging. |
912 | - if ($error_type == 'return') |
|
913 | - return array($file, $line); |
|
967 | + if ($error_type == 'return') { |
|
968 | + return array($file, $line); |
|
969 | + } |
|
914 | 970 | |
915 | 971 | // Is always a critical error. |
916 | - if (function_exists('log_error')) |
|
917 | - log_error($log_message, 'critical', $file, $line); |
|
972 | + if (function_exists('log_error')) { |
|
973 | + log_error($log_message, 'critical', $file, $line); |
|
974 | + } |
|
918 | 975 | |
919 | 976 | if (function_exists('fatal_error')) |
920 | 977 | { |
@@ -922,12 +979,12 @@ discard block |
||
922 | 979 | |
923 | 980 | // Cannot continue... |
924 | 981 | exit; |
982 | + } elseif ($error_type) { |
|
983 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
984 | + } else { |
|
985 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
986 | + } |
|
925 | 987 | } |
926 | - elseif ($error_type) |
|
927 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
928 | - else |
|
929 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
930 | -} |
|
931 | 988 | |
932 | 989 | /** |
933 | 990 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -944,10 +1001,11 @@ discard block |
||
944 | 1001 | '\\' => '\\\\', |
945 | 1002 | ); |
946 | 1003 | |
947 | - if ($translate_human_wildcards) |
|
948 | - $replacements += array( |
|
1004 | + if ($translate_human_wildcards) { |
|
1005 | + $replacements += array( |
|
949 | 1006 | '*' => '%', |
950 | 1007 | ); |
1008 | + } |
|
951 | 1009 | |
952 | 1010 | return strtr($string, $replacements); |
953 | 1011 | } |
@@ -976,14 +1034,16 @@ discard block |
||
976 | 1034 | static $pg_error_data_prep; |
977 | 1035 | |
978 | 1036 | // without database we can't do anything |
979 | - if (empty($db_connection)) |
|
980 | - return; |
|
1037 | + if (empty($db_connection)) { |
|
1038 | + return; |
|
1039 | + } |
|
981 | 1040 | |
982 | - if (empty($pg_error_data_prep)) |
|
983 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1041 | + if (empty($pg_error_data_prep)) { |
|
1042 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
984 | 1043 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace) |
985 | 1044 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)' |
986 | 1045 | ); |
1046 | + } |
|
987 | 1047 | |
988 | 1048 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
989 | 1049 | } |
@@ -1003,8 +1063,9 @@ discard block |
||
1003 | 1063 | $count = count($array_values); |
1004 | 1064 | $then = ($desc ? ' THEN -' : ' THEN '); |
1005 | 1065 | |
1006 | - for ($i = 0; $i < $count; $i++) |
|
1007 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1066 | + for ($i = 0; $i < $count; $i++) { |
|
1067 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1068 | + } |
|
1008 | 1069 | |
1009 | 1070 | $return .= 'END'; |
1010 | 1071 | return $return; |
@@ -1027,11 +1088,13 @@ discard block |
||
1027 | 1088 | //pg 9.5 got replace support |
1028 | 1089 | $pg_version = $smcFunc['db_get_version'](); |
1029 | 1090 | // if we got a Beta Version |
1030 | - if (stripos($pg_version, 'beta') !== false) |
|
1031 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1091 | + if (stripos($pg_version, 'beta') !== false) { |
|
1092 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
1093 | + } |
|
1032 | 1094 | // or RC |
1033 | - if (stripos($pg_version, 'rc') !== false) |
|
1034 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1095 | + if (stripos($pg_version, 'rc') !== false) { |
|
1096 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
1097 | + } |
|
1035 | 1098 | |
1036 | 1099 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
1037 | 1100 | } |
@@ -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 | * Fetches a list of boards and (optional) categories including |
@@ -37,19 +38,21 @@ discard block |
||
37 | 38 | require_once($sourcedir . '/Subs-Boards.php'); |
38 | 39 | |
39 | 40 | // For performance, track the latest post while going through the boards. |
40 | - if (!empty($boardIndexOptions['set_latest_post'])) |
|
41 | - $latest_post = array( |
|
41 | + if (!empty($boardIndexOptions['set_latest_post'])) { |
|
42 | + $latest_post = array( |
|
42 | 43 | 'timestamp' => 0, |
43 | 44 | 'ref' => 0, |
44 | 45 | ); |
46 | + } |
|
45 | 47 | |
46 | 48 | // This setting is not allowed to be empty |
47 | - if (empty($modSettings['boardindex_max_depth'])) |
|
48 | - $modSettings['boardindex_max_depth'] = 1; |
|
49 | + if (empty($modSettings['boardindex_max_depth'])) { |
|
50 | + $modSettings['boardindex_max_depth'] = 1; |
|
51 | + } |
|
49 | 52 | |
50 | 53 | // Find all boards and categories, as well as related information. This will be sorted by the natural order of boards and categories, which we control. |
51 | - if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) |
|
52 | - $result_boards = $smcFunc['db_query']('', ' |
|
54 | + if ($boardIndexOptions['parent_id'] != 0 && $smcFunc['db_cte_support']()) { |
|
55 | + $result_boards = $smcFunc['db_query']('', ' |
|
53 | 56 | WITH RECURSIVE |
54 | 57 | boards_cte (child_level, id_board, name , description, redirect, num_posts, num_topics, unapproved_posts, unapproved_topics, id_parent, id_msg_updated, id_cat, id_last_msg, board_order) |
55 | 58 | as |
@@ -90,8 +93,8 @@ discard block |
||
90 | 93 | 'id_parent' => $boardIndexOptions['parent_id'], |
91 | 94 | ) |
92 | 95 | ); |
93 | - else |
|
94 | - $result_boards = $smcFunc['db_query']('', ' |
|
96 | + } else { |
|
97 | + $result_boards = $smcFunc['db_query']('', ' |
|
95 | 98 | SELECT' . ($boardIndexOptions['include_categories'] ? ' |
96 | 99 | c.id_cat, c.name AS cat_name, c.description AS cat_desc,' : '') . ' |
97 | 100 | b.id_board, b.name AS board_name, b.description, |
@@ -119,18 +122,21 @@ discard block |
||
119 | 122 | 'blank_string' => '', |
120 | 123 | ) |
121 | 124 | ); |
125 | + } |
|
122 | 126 | |
123 | 127 | // Start with an empty array. |
124 | - if ($boardIndexOptions['include_categories']) |
|
125 | - $categories = array(); |
|
126 | - else |
|
127 | - $this_category = array(); |
|
128 | + if ($boardIndexOptions['include_categories']) { |
|
129 | + $categories = array(); |
|
130 | + } else { |
|
131 | + $this_category = array(); |
|
132 | + } |
|
128 | 133 | $boards = array(); |
129 | 134 | |
130 | 135 | // Children can affect parents, so we need to gather all the boards first and then process them after. |
131 | 136 | $row_boards = array(); |
132 | - while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) |
|
133 | - $row_boards[$row_board['id_board']] = $row_board; |
|
137 | + while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) { |
|
138 | + $row_boards[$row_board['id_board']] = $row_board; |
|
139 | + } |
|
134 | 140 | $smcFunc['db_free_result']($result_boards); |
135 | 141 | |
136 | 142 | // Run through the categories and boards (or only boards).... |
@@ -143,8 +149,9 @@ discard block |
||
143 | 149 | $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0'; |
144 | 150 | |
145 | 151 | // Add parent boards to the $boards list later used to fetch moderators |
146 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) |
|
147 | - $boards[] = $row_board['id_board']; |
|
152 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) { |
|
153 | + $boards[] = $row_board['id_board']; |
|
154 | + } |
|
148 | 155 | |
149 | 156 | if ($boardIndexOptions['include_categories']) |
150 | 157 | { |
@@ -166,8 +173,9 @@ discard block |
||
166 | 173 | } |
167 | 174 | |
168 | 175 | // If this board has new posts in it (and isn't the recycle bin!) then the category is new. |
169 | - if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) |
|
170 | - $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
176 | + if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) { |
|
177 | + $categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']); |
|
178 | + } |
|
171 | 179 | |
172 | 180 | // Avoid showing category unread link where it only has redirection boards. |
173 | 181 | $categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect']; |
@@ -186,8 +194,9 @@ discard block |
||
186 | 194 | $isChild = false; |
187 | 195 | |
188 | 196 | // We might or might not have already added this board, so... |
189 | - if (!isset($this_category[$row_board['id_board']])) |
|
190 | - $this_category[$row_board['id_board']] = array(); |
|
197 | + if (!isset($this_category[$row_board['id_board']])) { |
|
198 | + $this_category[$row_board['id_board']] = array(); |
|
199 | + } |
|
191 | 200 | |
192 | 201 | $this_category[$row_board['id_board']] += array( |
193 | 202 | 'new' => empty($row_board['is_read']), |
@@ -220,14 +229,12 @@ discard block |
||
220 | 229 | { |
221 | 230 | $this_category[$row_board['id_board']]['board_class'] = 'redirect'; |
222 | 231 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board']; |
223 | - } |
|
224 | - elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
232 | + } elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest']) |
|
225 | 233 | { |
226 | 234 | // If we're showing to guests, we want to give them the idea that something interesting is going on! |
227 | 235 | $this_category[$row_board['id_board']]['board_class'] = 'on'; |
228 | 236 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts']; |
229 | - } |
|
230 | - else |
|
237 | + } else |
|
231 | 238 | { |
232 | 239 | $this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts']; |
233 | 240 | } |
@@ -239,12 +246,13 @@ discard block |
||
239 | 246 | $isChild = true; |
240 | 247 | |
241 | 248 | // Ensure the parent has at least the most important info defined |
242 | - if (!isset($this_category[$row_board['id_parent']])) |
|
243 | - $this_category[$row_board['id_parent']] = array( |
|
249 | + if (!isset($this_category[$row_board['id_parent']])) { |
|
250 | + $this_category[$row_board['id_parent']] = array( |
|
244 | 251 | 'children' => array(), |
245 | 252 | 'children_new' => false, |
246 | 253 | 'board_class' => 'off', |
247 | 254 | ); |
255 | + } |
|
248 | 256 | |
249 | 257 | $this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array( |
250 | 258 | 'id' => $row_board['id_board'], |
@@ -288,8 +296,9 @@ discard block |
||
288 | 296 | // Propagate some values to the parent board |
289 | 297 | if (isset($row_boards[$row_board['id_parent']])) |
290 | 298 | { |
291 | - if (empty($row_board['is_read'])) |
|
292 | - $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
299 | + if (empty($row_board['is_read'])) { |
|
300 | + $row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read']; |
|
301 | + } |
|
293 | 302 | |
294 | 303 | if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect']) |
295 | 304 | { |
@@ -320,12 +329,13 @@ discard block |
||
320 | 329 | 'topic' => $row_board['id_topic'] |
321 | 330 | ); |
322 | 331 | |
323 | - if (!empty($settings['avatars_on_boardIndex'])) |
|
324 | - $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
332 | + if (!empty($settings['avatars_on_boardIndex'])) { |
|
333 | + $this_last_post['member']['avatar'] = set_avatar_data(array( |
|
325 | 334 | 'avatar' => $row_board['avatar'], |
326 | 335 | 'email' => $row_board['email_address'], |
327 | 336 | 'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '', |
328 | 337 | )); |
338 | + } |
|
329 | 339 | |
330 | 340 | // Provide the href and link. |
331 | 341 | if ($row_board['subject'] != '') |
@@ -337,8 +347,7 @@ discard block |
||
337 | 347 | link, href, subject, start (where they should go for the first unread post.), |
338 | 348 | and member. (which has id, name, link, href, username in it.) */ |
339 | 349 | $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']); |
340 | - } |
|
341 | - else |
|
350 | + } else |
|
342 | 351 | { |
343 | 352 | $this_last_post['href'] = ''; |
344 | 353 | $this_last_post['link'] = $txt['not_applicable']; |
@@ -346,18 +355,21 @@ discard block |
||
346 | 355 | } |
347 | 356 | |
348 | 357 | // Set the last post in the parent board. |
349 | - if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) |
|
350 | - $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
358 | + if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) { |
|
359 | + $this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post; |
|
360 | + } |
|
351 | 361 | // Just in the child...? |
352 | - if ($isChild) |
|
353 | - $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
362 | + if ($isChild) { |
|
363 | + $this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post; |
|
364 | + } |
|
354 | 365 | |
355 | 366 | // Determine a global most recent topic. |
356 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) |
|
357 | - $latest_post = array( |
|
367 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) { |
|
368 | + $latest_post = array( |
|
358 | 369 | 'timestamp' => $row_board['poster_time'], |
359 | 370 | 'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'], |
360 | 371 | ); |
372 | + } |
|
361 | 373 | } |
362 | 374 | |
363 | 375 | // Fetch the board's moderators and moderator groups |
@@ -373,8 +385,9 @@ discard block |
||
373 | 385 | if (!empty($moderators[$board['id']])) |
374 | 386 | { |
375 | 387 | $categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']]; |
376 | - foreach ($moderators[$board['id']] as $moderator) |
|
377 | - $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
388 | + foreach ($moderators[$board['id']] as $moderator) { |
|
389 | + $categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link']; |
|
390 | + } |
|
378 | 391 | } |
379 | 392 | if (!empty($groups[$board['id']])) |
380 | 393 | { |
@@ -387,16 +400,16 @@ discard block |
||
387 | 400 | } |
388 | 401 | } |
389 | 402 | } |
390 | - } |
|
391 | - else |
|
403 | + } else |
|
392 | 404 | { |
393 | 405 | foreach ($this_category as $k => $board) |
394 | 406 | { |
395 | 407 | if (!empty($moderators[$board['id']])) |
396 | 408 | { |
397 | 409 | $this_category[$k]['moderators'] = $moderators[$board['id']]; |
398 | - foreach ($moderators[$board['id']] as $moderator) |
|
399 | - $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
410 | + foreach ($moderators[$board['id']] as $moderator) { |
|
411 | + $this_category[$k]['link_moderators'][] = $moderator['link']; |
|
412 | + } |
|
400 | 413 | } |
401 | 414 | if (!empty($groups[$board['id']])) |
402 | 415 | { |
@@ -410,20 +423,23 @@ discard block |
||
410 | 423 | } |
411 | 424 | } |
412 | 425 | |
413 | - if ($boardIndexOptions['include_categories']) |
|
414 | - sortCategories($categories); |
|
415 | - else |
|
416 | - sortBoards($this_category); |
|
426 | + if ($boardIndexOptions['include_categories']) { |
|
427 | + sortCategories($categories); |
|
428 | + } else { |
|
429 | + sortBoards($this_category); |
|
430 | + } |
|
417 | 431 | |
418 | 432 | // By now we should know the most recent post...if we wanna know it that is. |
419 | - if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) |
|
420 | - $context['latest_post'] = $latest_post['ref']; |
|
433 | + if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) { |
|
434 | + $context['latest_post'] = $latest_post['ref']; |
|
435 | + } |
|
421 | 436 | |
422 | 437 | // I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea. |
423 | - if ($boardIndexOptions['include_categories']) |
|
424 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
425 | - else |
|
426 | - call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
438 | + if ($boardIndexOptions['include_categories']) { |
|
439 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories)); |
|
440 | + } else { |
|
441 | + call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category)); |
|
442 | + } |
|
427 | 443 | |
428 | 444 | return $boardIndexOptions['include_categories'] ? $categories : $this_category; |
429 | 445 | } |