@@ -168,7 +168,9 @@ discard block |
||
168 | 168 | |
169 | 169 | // Nothing to do, then we are done |
170 | 170 | if (count($this->_combine_files) === 0) |
171 | - return true; |
|
171 | + { |
|
172 | + return true; |
|
173 | + } |
|
172 | 174 | |
173 | 175 | // Create the archive name |
174 | 176 | $this->_buildName('.js'); |
@@ -226,7 +228,9 @@ discard block |
||
226 | 228 | |
227 | 229 | // Nothing to do so return |
228 | 230 | if (count($this->_combine_files) === 0) |
229 | - return true; |
|
231 | + { |
|
232 | + return true; |
|
233 | + } |
|
230 | 234 | |
231 | 235 | // Create the css archive name |
232 | 236 | $this->_buildName('.css'); |
@@ -373,7 +377,9 @@ discard block |
||
373 | 377 | foreach ($this->_combine_files as $file) |
374 | 378 | { |
375 | 379 | if ($file['filemtime'] > $filemtime) |
376 | - return true; |
|
380 | + { |
|
381 | + return true; |
|
382 | + } |
|
377 | 383 | } |
378 | 384 | |
379 | 385 | return false; |
@@ -390,7 +396,9 @@ discard block |
||
390 | 396 | |
391 | 397 | // Create this groups archive name |
392 | 398 | foreach ($this->_combine_files as $file) |
393 | - $this->_archive_filenames .= $file['basename'] . ' '; |
|
399 | + { |
|
400 | + $this->_archive_filenames .= $file['basename'] . ' '; |
|
401 | + } |
|
394 | 402 | |
395 | 403 | // Add in the actual theme url to make the sha1 unique to this hive |
396 | 404 | $this->_archive_filenames = $settings['actual_theme_url'] . '/' . trim($this->_archive_filenames); |
@@ -400,7 +408,9 @@ discard block |
||
400 | 408 | |
401 | 409 | // Create a unique cache stale for this hive ?x12345 |
402 | 410 | if (!empty($this->_stales)) |
403 | - $this->_archive_stale = '?x' . hash('crc32b', implode(' ', $this->_stales)); |
|
411 | + { |
|
412 | + $this->_archive_stale = '?x' . hash('crc32b', implode(' ', $this->_stales)); |
|
413 | + } |
|
404 | 414 | } |
405 | 415 | |
406 | 416 | /** |
@@ -445,9 +455,12 @@ discard block |
||
445 | 455 | |
446 | 456 | // Add the file to the correct array for processing |
447 | 457 | if ($file['minimized'] === false) |
448 | - $_cache[] = $tempfile; |
|
449 | - else |
|
450 | - $_min_cache[] = $tempfile; |
|
458 | + { |
|
459 | + $_cache[] = $tempfile; |
|
460 | + } |
|
461 | + else { |
|
462 | + $_min_cache[] = $tempfile; |
|
463 | + } |
|
451 | 464 | } |
452 | 465 | |
453 | 466 | // Build out our combined file strings |
@@ -463,7 +476,9 @@ discard block |
||
463 | 476 | { |
464 | 477 | // Add in the file header if available |
465 | 478 | if (!empty($this->_archive_header)) |
466 | - $this->_minified_cache = $this->_archive_header . $this->_minified_cache; |
|
479 | + { |
|
480 | + $this->_minified_cache = $this->_archive_header . $this->_minified_cache; |
|
481 | + } |
|
467 | 482 | |
468 | 483 | // First the plain text version |
469 | 484 | file_put_contents($this->_archive_dir . '/' . $this->_archive_name, $this->_minified_cache, LOCK_EX); |
@@ -500,7 +515,9 @@ discard block |
||
500 | 515 | // To prevent a stack overflow segmentation fault, which silently kills Apache, we need to limit |
501 | 516 | // recursion on windows. This may cause JSqueeze to fail, but at least its then catchable. |
502 | 517 | if (detectServer()->is('windows')) |
503 | - @ini_set('pcre.recursion_limit', '524'); |
|
518 | + { |
|
519 | + @ini_set('pcre.recursion_limit', '524'); |
|
520 | + } |
|
504 | 521 | |
505 | 522 | require_once(EXTDIR . '/JSqueeze.php'); |
506 | 523 | $jsqueeze = new Patchwork\JSqueeze; |
@@ -509,7 +526,9 @@ discard block |
||
509 | 526 | |
510 | 527 | // If we still have no data, then try the post js_code method to the closure compiler |
511 | 528 | if ($fetch_data === false || trim($fetch_data) == '') |
512 | - $fetch_data = $this->_closure_js_code(); |
|
529 | + { |
|
530 | + $fetch_data = $this->_closure_js_code(); |
|
531 | + } |
|
513 | 532 | |
514 | 533 | // If we have nothing to return, use the original data |
515 | 534 | $fetch_data = ($fetch_data === false || trim($fetch_data) == '') ? $this->_cache : $fetch_data; |
@@ -534,7 +553,9 @@ discard block |
||
534 | 553 | foreach ($this->_combine_files as $file) |
535 | 554 | { |
536 | 555 | if ($file['minimized'] === false) |
537 | - $post_data .= '&code_url=' . urlencode($file['url'] . '/scripts/' . $file['basename'] . $this->_archive_stale); |
|
556 | + { |
|
557 | + $post_data .= '&code_url=' . urlencode($file['url'] . '/scripts/' . $file['basename'] . $this->_archive_stale); |
|
558 | + } |
|
538 | 559 | } |
539 | 560 | |
540 | 561 | return fetch_web_data($this->_url, $this->_post_header . $post_data); |
@@ -558,8 +579,9 @@ discard block |
||
558 | 579 | $fetch_data = fetch_web_data($this->_url, $this->_post_header . $post_data); |
559 | 580 | } |
560 | 581 | // Simply to much data for a single post so break it down in to as few as possible |
561 | - else |
|
562 | - $fetch_data = $this->_closure_js_code_chunks(); |
|
582 | + else { |
|
583 | + $fetch_data = $this->_closure_js_code_chunks(); |
|
584 | + } |
|
563 | 585 | |
564 | 586 | return $fetch_data; |
565 | 587 | } |
@@ -97,7 +97,9 @@ discard block |
||
97 | 97 | $cache = Cache::instance(); |
98 | 98 | |
99 | 99 | if (empty($changeArray) || !is_array($changeArray)) |
100 | - return; |
|
100 | + { |
|
101 | + return; |
|
102 | + } |
|
101 | 103 | |
102 | 104 | // In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs. |
103 | 105 | if ($update) |
@@ -128,10 +130,14 @@ discard block |
||
128 | 130 | { |
129 | 131 | // Don't bother if it's already like that ;). |
130 | 132 | if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) |
131 | - continue; |
|
133 | + { |
|
134 | + continue; |
|
135 | + } |
|
132 | 136 | // If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it. |
133 | 137 | elseif (!isset($modSettings[$variable]) && empty($value)) |
134 | - continue; |
|
138 | + { |
|
139 | + continue; |
|
140 | + } |
|
135 | 141 | |
136 | 142 | $replaceArray[] = array($variable, $value); |
137 | 143 | |
@@ -139,7 +145,9 @@ discard block |
||
139 | 145 | } |
140 | 146 | |
141 | 147 | if (empty($replaceArray)) |
142 | - return; |
|
148 | + { |
|
149 | + return; |
|
150 | + } |
|
143 | 151 | |
144 | 152 | $db->insert('replace', |
145 | 153 | '{db_prefix}settings', |
@@ -164,10 +172,14 @@ discard block |
||
164 | 172 | $db = database(); |
165 | 173 | |
166 | 174 | if (empty($toRemove)) |
167 | - return; |
|
175 | + { |
|
176 | + return; |
|
177 | + } |
|
168 | 178 | |
169 | 179 | if (!is_array($toRemove)) |
170 | - $toRemove = array($toRemove); |
|
180 | + { |
|
181 | + $toRemove = array($toRemove); |
|
182 | + } |
|
171 | 183 | |
172 | 184 | // Remove the setting from the db |
173 | 185 | $db->query('', ' |
@@ -180,8 +192,10 @@ discard block |
||
180 | 192 | |
181 | 193 | // Remove it from $modSettings now so it does not persist |
182 | 194 | foreach ($toRemove as $setting) |
183 | - if (isset($modSettings[$setting])) |
|
195 | + { |
|
196 | + if (isset($modSettings[$setting])) |
|
184 | 197 | unset($modSettings[$setting]); |
198 | + } |
|
185 | 199 | |
186 | 200 | // Kill the cache - it needs redoing now, but we won't bother ourselves with that here. |
187 | 201 | Cache::instance()->remove('modSettings'); |
@@ -228,13 +242,18 @@ discard block |
||
228 | 242 | |
229 | 243 | // Make sure $start is a proper variable - not less than 0. |
230 | 244 | if ($start_invalid) |
231 | - $start = 0; |
|
245 | + { |
|
246 | + $start = 0; |
|
247 | + } |
|
232 | 248 | // Not greater than the upper bound. |
233 | 249 | elseif ($start >= $max_value) |
234 | - $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
250 | + { |
|
251 | + $start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page))); |
|
252 | + } |
|
235 | 253 | // And it has to be a multiple of $num_per_page! |
236 | - else |
|
237 | - $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
254 | + else { |
|
255 | + $start = max(0, (int) $start - ((int) $start % (int) $num_per_page)); |
|
256 | + } |
|
238 | 257 | |
239 | 258 | $context['current_page'] = $start / $num_per_page; |
240 | 259 | |
@@ -249,12 +268,16 @@ discard block |
||
249 | 268 | // Show all the pages. |
250 | 269 | $display_page = 1; |
251 | 270 | for ($counter = 0; $counter < $max_value; $counter += $num_per_page) |
252 | - $pageindex .= $start == $counter && !$start_invalid && empty($show['all_selected']) ? sprintf($settings['page_index_template']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
271 | + { |
|
272 | + $pageindex .= $start == $counter && !$start_invalid && empty($show['all_selected']) ? sprintf($settings['page_index_template']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++); |
|
273 | + } |
|
253 | 274 | |
254 | 275 | // Show the right arrow. |
255 | 276 | $display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page); |
256 | 277 | if ($start != $counter - $max_value && !$start_invalid && $show['prev_next'] && empty($show['all_selected'])) |
257 | - $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, str_replace('{next_txt}', $txt['next'], $settings['page_index_template']['next_page'])); |
|
278 | + { |
|
279 | + $pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, str_replace('{next_txt}', $txt['next'], $settings['page_index_template']['next_page'])); |
|
280 | + } |
|
258 | 281 | } |
259 | 282 | else |
260 | 283 | { |
@@ -263,61 +286,84 @@ discard block |
||
263 | 286 | |
264 | 287 | // Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page) |
265 | 288 | if (!empty($start) && $show['prev_next']) |
266 | - $pageindex = sprintf($base_link, $start - $num_per_page, str_replace('{prev_txt}', $txt['prev'], $settings['page_index_template']['previous_page'])); |
|
267 | - else |
|
268 | - $pageindex = ''; |
|
289 | + { |
|
290 | + $pageindex = sprintf($base_link, $start - $num_per_page, str_replace('{prev_txt}', $txt['prev'], $settings['page_index_template']['previous_page'])); |
|
291 | + } |
|
292 | + else { |
|
293 | + $pageindex = ''; |
|
294 | + } |
|
269 | 295 | |
270 | 296 | // Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15) |
271 | 297 | if ($start > $num_per_page * $PageContiguous) |
272 | - $pageindex .= sprintf($base_link, 0, '1'); |
|
298 | + { |
|
299 | + $pageindex .= sprintf($base_link, 0, '1'); |
|
300 | + } |
|
273 | 301 | |
274 | 302 | // Show the ... after the first page. (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page) |
275 | 303 | if ($start > $num_per_page * ($PageContiguous + 1)) |
276 | - $pageindex .= str_replace('{custom}', 'data-baseurl="' . htmlspecialchars(JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')), ENT_COMPAT, 'UTF-8') . '" data-perpage="' . $num_per_page . '" data-firstpage="' . $num_per_page . '" data-lastpage="' . ($start - $num_per_page * $PageContiguous) . '"', $settings['page_index_template']['expand_pages']); |
|
304 | + { |
|
305 | + $pageindex .= str_replace('{custom}', 'data-baseurl="' . htmlspecialchars(JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')), ENT_COMPAT, 'UTF-8') . '" data-perpage="' . $num_per_page . '" data-firstpage="' . $num_per_page . '" data-lastpage="' . ($start - $num_per_page * $PageContiguous) . '"', $settings['page_index_template']['expand_pages']); |
|
306 | + } |
|
277 | 307 | |
278 | 308 | // Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page) |
279 | 309 | for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) |
280 | - if ($start >= $num_per_page * $nCont) |
|
310 | + { |
|
311 | + if ($start >= $num_per_page * $nCont) |
|
281 | 312 | { |
282 | 313 | $tmpStart = $start - $num_per_page * $nCont; |
314 | + } |
|
283 | 315 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
284 | 316 | } |
285 | 317 | |
286 | 318 | // Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page) |
287 | 319 | if (!$start_invalid && empty($show['all_selected'])) |
288 | - $pageindex .= sprintf($settings['page_index_template']['current_page'], ($start / $num_per_page + 1)); |
|
289 | - else |
|
290 | - $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
320 | + { |
|
321 | + $pageindex .= sprintf($settings['page_index_template']['current_page'], ($start / $num_per_page + 1)); |
|
322 | + } |
|
323 | + else { |
|
324 | + $pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1); |
|
325 | + } |
|
291 | 326 | |
292 | 327 | // Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page) |
293 | 328 | $tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page; |
294 | 329 | for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) |
295 | - if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
330 | + { |
|
331 | + if ($start + $num_per_page * $nCont <= $tmpMaxPages) |
|
296 | 332 | { |
297 | 333 | $tmpStart = $start + $num_per_page * $nCont; |
334 | + } |
|
298 | 335 | $pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1); |
299 | 336 | } |
300 | 337 | |
301 | 338 | // Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page) |
302 | 339 | if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) |
303 | - $pageindex .= str_replace('{custom}', 'data-baseurl="' . htmlspecialchars(JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')), ENT_COMPAT, 'UTF-8') . '" data-perpage="' . $num_per_page . '" data-firstpage="' . ($start + $num_per_page * ($PageContiguous + 1)) . '" data-lastpage="' . $tmpMaxPages . '"', $settings['page_index_template']['expand_pages']); |
|
340 | + { |
|
341 | + $pageindex .= str_replace('{custom}', 'data-baseurl="' . htmlspecialchars(JavaScriptEscape(($flexible_start ? $base_url : strtr($base_url, array('%' => '%%')) . ';start=%1$d')), ENT_COMPAT, 'UTF-8') . '" data-perpage="' . $num_per_page . '" data-firstpage="' . ($start + $num_per_page * ($PageContiguous + 1)) . '" data-lastpage="' . $tmpMaxPages . '"', $settings['page_index_template']['expand_pages']); |
|
342 | + } |
|
304 | 343 | |
305 | 344 | // Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15< next page) |
306 | 345 | if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) |
307 | - $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
346 | + { |
|
347 | + $pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1); |
|
348 | + } |
|
308 | 349 | |
309 | 350 | // Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<) |
310 | 351 | if ($start != $tmpMaxPages && $show['prev_next'] && empty($show['all_selected'])) |
311 | - $pageindex .= sprintf($base_link, $start + $num_per_page, str_replace('{next_txt}', $txt['next'], $settings['page_index_template']['next_page'])); |
|
352 | + { |
|
353 | + $pageindex .= sprintf($base_link, $start + $num_per_page, str_replace('{next_txt}', $txt['next'], $settings['page_index_template']['next_page'])); |
|
354 | + } |
|
312 | 355 | } |
313 | 356 | |
314 | 357 | // The "all" button |
315 | 358 | if ($show['all']) |
316 | 359 | { |
317 | 360 | if (!empty($show['all_selected'])) |
318 | - $pageindex .= sprintf($settings['page_index_template']['current_page'], $txt['all']); |
|
319 | - else |
|
320 | - $pageindex .= sprintf(str_replace('%1$d', '%1$s', $base_link), '0;all', str_replace('{all_txt}', $txt['all'], $settings['page_index_template']['all'])); |
|
361 | + { |
|
362 | + $pageindex .= sprintf($settings['page_index_template']['current_page'], $txt['all']); |
|
363 | + } |
|
364 | + else { |
|
365 | + $pageindex .= sprintf(str_replace('%1$d', '%1$s', $base_link), '0;all', str_replace('{all_txt}', $txt['all'], $settings['page_index_template']['all'])); |
|
366 | + } |
|
321 | 367 | } |
322 | 368 | |
323 | 369 | return $pageindex; |
@@ -347,7 +393,9 @@ discard block |
||
347 | 393 | { |
348 | 394 | // Not set for whatever reason? |
349 | 395 | if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) |
350 | - return $number; |
|
396 | + { |
|
397 | + return $number; |
|
398 | + } |
|
351 | 399 | |
352 | 400 | // Cache these each load... |
353 | 401 | $thousands_separator = $matches[1]; |
@@ -436,16 +484,23 @@ discard block |
||
436 | 484 | |
437 | 485 | // Offset the time. |
438 | 486 | if (!$offset_type) |
439 | - $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
487 | + { |
|
488 | + $time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
489 | + } |
|
440 | 490 | // Just the forum offset? |
441 | 491 | elseif ($offset_type === 'forum') |
442 | - $time = $log_time + $modSettings['time_offset'] * 3600; |
|
443 | - else |
|
444 | - $time = $log_time; |
|
492 | + { |
|
493 | + $time = $log_time + $modSettings['time_offset'] * 3600; |
|
494 | + } |
|
495 | + else { |
|
496 | + $time = $log_time; |
|
497 | + } |
|
445 | 498 | |
446 | 499 | // We can't have a negative date (on Windows, at least.) |
447 | 500 | if ($log_time < 0) |
448 | - $log_time = 0; |
|
501 | + { |
|
502 | + $log_time = 0; |
|
503 | + } |
|
449 | 504 | |
450 | 505 | // Today and Yesterday? |
451 | 506 | if ($modSettings['todayMod'] >= 1 && $show_today === true) |
@@ -463,16 +518,21 @@ discard block |
||
463 | 518 | $h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l'; |
464 | 519 | $today_fmt = $h . ':%M' . $s . ' %p'; |
465 | 520 | } |
466 | - else |
|
467 | - $today_fmt = '%H:%M' . $s; |
|
521 | + else { |
|
522 | + $today_fmt = '%H:%M' . $s; |
|
523 | + } |
|
468 | 524 | |
469 | 525 | // Same day of the year, same year.... Today! |
470 | 526 | if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) |
471 | - return sprintf($txt['today'], standardTime($log_time, $today_fmt, $offset_type)); |
|
527 | + { |
|
528 | + return sprintf($txt['today'], standardTime($log_time, $today_fmt, $offset_type)); |
|
529 | + } |
|
472 | 530 | |
473 | 531 | // Day-of-year is one less and same year, or it's the first of the year and that's the last of the year... |
474 | 532 | if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) |
475 | - return sprintf($txt['yesterday'], standardTime($log_time, $today_fmt, $offset_type)); |
|
533 | + { |
|
534 | + return sprintf($txt['yesterday'], standardTime($log_time, $today_fmt, $offset_type)); |
|
535 | + } |
|
476 | 536 | } |
477 | 537 | |
478 | 538 | $str = !is_bool($show_today) ? $show_today : $user_info['time_format']; |
@@ -480,28 +540,40 @@ discard block |
||
480 | 540 | if (setlocale(LC_TIME, $txt['lang_locale'])) |
481 | 541 | { |
482 | 542 | if (!isset($non_twelve_hour)) |
483 | - $non_twelve_hour = trim(Util::strftime('%p')) === ''; |
|
543 | + { |
|
544 | + $non_twelve_hour = trim(Util::strftime('%p')) === ''; |
|
545 | + } |
|
484 | 546 | if ($non_twelve_hour && strpos($str, '%p') !== false) |
485 | - $str = str_replace('%p', (Util::strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
547 | + { |
|
548 | + $str = str_replace('%p', (Util::strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
549 | + } |
|
486 | 550 | |
487 | 551 | foreach (array('%a', '%A', '%b', '%B') as $token) |
488 | - if (strpos($str, $token) !== false) |
|
552 | + { |
|
553 | + if (strpos($str, $token) !== false) |
|
489 | 554 | $str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? Util::ucwords(Util::strftime($token, $time)) : Util::strftime($token, $time), $str); |
555 | + } |
|
490 | 556 | } |
491 | 557 | else |
492 | 558 | { |
493 | 559 | // Do-it-yourself time localization. Fun. |
494 | 560 | foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) |
495 | - if (strpos($str, $token) !== false) |
|
561 | + { |
|
562 | + if (strpos($str, $token) !== false) |
|
496 | 563 | $str = str_replace($token, $txt[$text_label][(int) Util::strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str); |
564 | + } |
|
497 | 565 | |
498 | 566 | if (strpos($str, '%p') !== false) |
499 | - $str = str_replace('%p', (Util::strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
567 | + { |
|
568 | + $str = str_replace('%p', (Util::strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str); |
|
569 | + } |
|
500 | 570 | } |
501 | 571 | |
502 | 572 | // Windows doesn't support %e; on some versions, Util::strftime fails altogether if used, so let's prevent that. |
503 | 573 | if ($support_e && strpos($str, '%e') !== false) |
504 | - $str = str_replace('%e', ltrim(Util::strftime('%d', $time), '0'), $str); |
|
574 | + { |
|
575 | + $str = str_replace('%e', ltrim(Util::strftime('%d', $time), '0'), $str); |
|
576 | + } |
|
505 | 577 | |
506 | 578 | // Format any other characters.. |
507 | 579 | return Util::strftime($str, $time); |
@@ -519,7 +591,9 @@ discard block |
||
519 | 591 | global $txt, $context; |
520 | 592 | |
521 | 593 | if (empty($timestamp)) |
522 | - return ''; |
|
594 | + { |
|
595 | + return ''; |
|
596 | + } |
|
523 | 597 | |
524 | 598 | $forumtime = forum_time(false, $timestamp); |
525 | 599 | $timestamp = forum_time(true, $timestamp); |
@@ -547,9 +621,13 @@ discard block |
||
547 | 621 | global $user_info, $modSettings; |
548 | 622 | |
549 | 623 | if ($timestamp === null) |
550 | - $timestamp = time(); |
|
624 | + { |
|
625 | + $timestamp = time(); |
|
626 | + } |
|
551 | 627 | elseif ($timestamp == 0) |
552 | - return 0; |
|
628 | + { |
|
629 | + return 0; |
|
630 | + } |
|
553 | 631 | |
554 | 632 | return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600; |
555 | 633 | } |
@@ -568,7 +646,9 @@ discard block |
||
568 | 646 | function un_htmlspecialchars($string) |
569 | 647 | { |
570 | 648 | if (empty($string)) |
571 | - return $string; |
|
649 | + { |
|
650 | + return $string; |
|
651 | + } |
|
572 | 652 | |
573 | 653 | $string = htmlspecialchars_decode($string, ENT_QUOTES); |
574 | 654 | $string = str_replace(' ', ' ', $string); |
@@ -609,7 +689,9 @@ discard block |
||
609 | 689 | $array[$j] = $temp; |
610 | 690 | |
611 | 691 | for ($i = 1; $p[$i] == 0; $i++) |
612 | - $p[$i] = $i; |
|
692 | + { |
|
693 | + $p[$i] = $i; |
|
694 | + } |
|
613 | 695 | |
614 | 696 | $orders[] = $array; |
615 | 697 | } |
@@ -691,7 +773,9 @@ discard block |
||
691 | 773 | { |
692 | 774 | // Don't waste cycles |
693 | 775 | if ($message === '') |
694 | - return ''; |
|
776 | + { |
|
777 | + return ''; |
|
778 | + } |
|
695 | 779 | |
696 | 780 | $parser = \BBC\ParserWrapper::instance(); |
697 | 781 | |
@@ -779,29 +863,40 @@ discard block |
||
779 | 863 | |
780 | 864 | // In case we have mail to send, better do that - as obExit doesn't always quite make it... |
781 | 865 | if (!empty($context['flush_mail'])) |
782 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
866 | + { |
|
867 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
783 | 868 | AddMailQueue(true); |
869 | + } |
|
784 | 870 | |
785 | 871 | Notifications::instance()->send(); |
786 | 872 | |
787 | 873 | $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:'; |
788 | 874 | |
789 | 875 | if ($add) |
790 | - $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
876 | + { |
|
877 | + $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : ''); |
|
878 | + } |
|
791 | 879 | |
792 | 880 | // Put the session ID in. |
793 | 881 | if (empty($_COOKIE) && defined('SID') && SID != '') |
794 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
882 | + { |
|
883 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation); |
|
884 | + } |
|
795 | 885 | // Keep that debug in their for template debugging! |
796 | 886 | elseif (isset($_GET['debug'])) |
797 | - $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
887 | + { |
|
888 | + $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation); |
|
889 | + } |
|
798 | 890 | |
799 | 891 | if (!empty($modSettings['queryless_urls']) && detectServer()->supportRewrite()) |
800 | 892 | { |
801 | 893 | if (defined('SID') && SID != '') |
802 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', 'redirectexit_callback', $setLocation); |
|
803 | - else |
|
804 | - $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', 'redirectexit_callback', $setLocation); |
|
894 | + { |
|
895 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&))((?:board|topic)=[^#]+?)(#[^"]*?)?$~', 'redirectexit_callback', $setLocation); |
|
896 | + } |
|
897 | + else { |
|
898 | + $setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~', 'redirectexit_callback', $setLocation); |
|
899 | + } |
|
805 | 900 | } |
806 | 901 | |
807 | 902 | // Maybe integrations want to change where we are heading? |
@@ -809,9 +904,12 @@ discard block |
||
809 | 904 | |
810 | 905 | // We send a Refresh header only in special cases because Location looks better. (and is quicker...) |
811 | 906 | if ($refresh) |
812 | - header('Refresh: 0; URL=' . strtr($setLocation, array(' ' => '%20'))); |
|
813 | - else |
|
814 | - header('Location: ' . str_replace(' ', '%20', $setLocation)); |
|
907 | + { |
|
908 | + header('Refresh: 0; URL=' . strtr($setLocation, array(' ' => '%20'))); |
|
909 | + } |
|
910 | + else { |
|
911 | + header('Location: ' . str_replace(' ', '%20', $setLocation)); |
|
912 | + } |
|
815 | 913 | |
816 | 914 | // Debugging. |
817 | 915 | if ($db_show_debug === true) |
@@ -837,10 +935,13 @@ discard block |
||
837 | 935 | global $scripturl; |
838 | 936 | |
839 | 937 | if (defined('SID') && SID != '') |
840 | - return $scripturl . '/' . strtr($matches[1], '&;=', '//,') . '.html?' . SID . (isset($matches[2]) ? $matches[2] : ''); |
|
841 | - else |
|
842 | - return $scripturl . '/' . strtr($matches[1], '&;=', '//,') . '.html' . (isset($matches[2]) ? $matches[2] : ''); |
|
843 | -} |
|
938 | + { |
|
939 | + return $scripturl . '/' . strtr($matches[1], '&;=', '//,') . '.html?' . SID . (isset($matches[2]) ? $matches[2] : ''); |
|
940 | + } |
|
941 | + else { |
|
942 | + return $scripturl . '/' . strtr($matches[1], '&;=', '//,') . '.html' . (isset($matches[2]) ? $matches[2] : ''); |
|
943 | + } |
|
944 | + } |
|
844 | 945 | |
845 | 946 | /** |
846 | 947 | * Ends execution. |
@@ -868,10 +969,14 @@ discard block |
||
868 | 969 | // Attempt to prevent a recursive loop. |
869 | 970 | ++$level; |
870 | 971 | if ($level > 1 && !$from_fatal_error && !$has_fatal_error) |
871 | - exit; |
|
972 | + { |
|
973 | + exit; |
|
974 | + } |
|
872 | 975 | |
873 | 976 | if ($from_fatal_error) |
874 | - $has_fatal_error = true; |
|
977 | + { |
|
978 | + $has_fatal_error = true; |
|
979 | + } |
|
875 | 980 | |
876 | 981 | // Clear out the stat cache. |
877 | 982 | trackStats(); |
@@ -880,19 +985,25 @@ discard block |
||
880 | 985 | |
881 | 986 | // If we have mail to send, send it. |
882 | 987 | if (!empty($context['flush_mail'])) |
883 | - // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
988 | + { |
|
989 | + // @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\ |
|
884 | 990 | AddMailQueue(true); |
991 | + } |
|
885 | 992 | |
886 | 993 | $do_header = $header === null ? !$header_done : $header; |
887 | 994 | if ($do_footer === null) |
888 | - $do_footer = $do_header; |
|
995 | + { |
|
996 | + $do_footer = $do_header; |
|
997 | + } |
|
889 | 998 | |
890 | 999 | // Has the template/header been done yet? |
891 | 1000 | if ($do_header) |
892 | 1001 | { |
893 | 1002 | // Was the page title set last minute? Also update the HTML safe one. |
894 | 1003 | if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) |
895 | - $context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
1004 | + { |
|
1005 | + $context['page_title_html_safe'] = Util::htmlspecialchars(un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : ''); |
|
1006 | + } |
|
896 | 1007 | |
897 | 1008 | // Start up the session URL fixer. |
898 | 1009 | ob_start('ob_sessrewrite'); |
@@ -940,8 +1051,10 @@ discard block |
||
940 | 1051 | |
941 | 1052 | // Don't exit if we're coming from index.php; that will pass through normally. |
942 | 1053 | if (!$from_index) |
943 | - exit; |
|
944 | -} |
|
1054 | + { |
|
1055 | + exit; |
|
1056 | + } |
|
1057 | + } |
|
945 | 1058 | |
946 | 1059 | function setOldUrl($index = 'old_url') |
947 | 1060 | { |
@@ -978,19 +1091,28 @@ discard block |
||
978 | 1091 | { |
979 | 1092 | // Set topic class depending on locked status and number of replies. |
980 | 1093 | if ($topic_context['is_very_hot']) |
981 | - $topic_context['class'] = 'veryhot'; |
|
1094 | + { |
|
1095 | + $topic_context['class'] = 'veryhot'; |
|
1096 | + } |
|
982 | 1097 | elseif ($topic_context['is_hot']) |
983 | - $topic_context['class'] = 'hot'; |
|
984 | - else |
|
985 | - $topic_context['class'] = 'normal'; |
|
1098 | + { |
|
1099 | + $topic_context['class'] = 'hot'; |
|
1100 | + } |
|
1101 | + else { |
|
1102 | + $topic_context['class'] = 'normal'; |
|
1103 | + } |
|
986 | 1104 | |
987 | 1105 | $topic_context['class'] .= !empty($topic_context['is_poll']) ? '_poll' : '_post'; |
988 | 1106 | |
989 | 1107 | if ($topic_context['is_locked']) |
990 | - $topic_context['class'] .= '_locked'; |
|
1108 | + { |
|
1109 | + $topic_context['class'] .= '_locked'; |
|
1110 | + } |
|
991 | 1111 | |
992 | 1112 | if ($topic_context['is_sticky']) |
993 | - $topic_context['class'] .= '_sticky'; |
|
1113 | + { |
|
1114 | + $topic_context['class'] .= '_sticky'; |
|
1115 | + } |
|
994 | 1116 | |
995 | 1117 | // This is so old themes will still work. |
996 | 1118 | // @deprecated since 1.0 do not rely on it |
@@ -1180,16 +1302,24 @@ discard block |
||
1180 | 1302 | $ip_array = array(); |
1181 | 1303 | |
1182 | 1304 | if (count($ip_parts) != 8) |
1183 | - return array(); |
|
1305 | + { |
|
1306 | + return array(); |
|
1307 | + } |
|
1184 | 1308 | |
1185 | 1309 | for ($i = 0; $i < 8; $i++) |
1186 | 1310 | { |
1187 | 1311 | if ($ip_parts[$i] == '*') |
1188 | - $ip_array[$i] = array('low' => '0', 'high' => hexdec('ffff')); |
|
1312 | + { |
|
1313 | + $ip_array[$i] = array('low' => '0', 'high' => hexdec('ffff')); |
|
1314 | + } |
|
1189 | 1315 | elseif (preg_match('/^([0-9A-Fa-f]{1,4})\-([0-9A-Fa-f]{1,4})$/', $ip_parts[$i], $range) == 1) |
1190 | - $ip_array[$i] = array('low' => hexdec($range[1]), 'high' => hexdec($range[2])); |
|
1316 | + { |
|
1317 | + $ip_array[$i] = array('low' => hexdec($range[1]), 'high' => hexdec($range[2])); |
|
1318 | + } |
|
1191 | 1319 | elseif (is_numeric(hexdec($ip_parts[$i]))) |
1192 | - $ip_array[$i] = array('low' => hexdec($ip_parts[$i]), 'high' => hexdec($ip_parts[$i])); |
|
1320 | + { |
|
1321 | + $ip_array[$i] = array('low' => hexdec($ip_parts[$i]), 'high' => hexdec($ip_parts[$i])); |
|
1322 | + } |
|
1193 | 1323 | } |
1194 | 1324 | |
1195 | 1325 | return $ip_array; |
@@ -1197,22 +1327,32 @@ discard block |
||
1197 | 1327 | |
1198 | 1328 | // Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.) |
1199 | 1329 | if ($fullip == 'unknown') |
1200 | - $fullip = '255.255.255.255'; |
|
1330 | + { |
|
1331 | + $fullip = '255.255.255.255'; |
|
1332 | + } |
|
1201 | 1333 | |
1202 | 1334 | $ip_parts = explode('.', $fullip); |
1203 | 1335 | $ip_array = array(); |
1204 | 1336 | |
1205 | 1337 | if (count($ip_parts) != 4) |
1206 | - return array(); |
|
1338 | + { |
|
1339 | + return array(); |
|
1340 | + } |
|
1207 | 1341 | |
1208 | 1342 | for ($i = 0; $i < 4; $i++) |
1209 | 1343 | { |
1210 | 1344 | if ($ip_parts[$i] == '*') |
1211 | - $ip_array[$i] = array('low' => '0', 'high' => '255'); |
|
1345 | + { |
|
1346 | + $ip_array[$i] = array('low' => '0', 'high' => '255'); |
|
1347 | + } |
|
1212 | 1348 | elseif (preg_match('/^(\d{1,3})\-(\d{1,3})$/', $ip_parts[$i], $range) == 1) |
1213 | - $ip_array[$i] = array('low' => $range[1], 'high' => $range[2]); |
|
1349 | + { |
|
1350 | + $ip_array[$i] = array('low' => $range[1], 'high' => $range[2]); |
|
1351 | + } |
|
1214 | 1352 | elseif (is_numeric($ip_parts[$i])) |
1215 | - $ip_array[$i] = array('low' => $ip_parts[$i], 'high' => $ip_parts[$i]); |
|
1353 | + { |
|
1354 | + $ip_array[$i] = array('low' => $ip_parts[$i], 'high' => $ip_parts[$i]); |
|
1355 | + } |
|
1216 | 1356 | } |
1217 | 1357 | |
1218 | 1358 | // Makes it simpler to work with. |
@@ -1239,7 +1379,9 @@ discard block |
||
1239 | 1379 | |
1240 | 1380 | $host = ''; |
1241 | 1381 | if ($cache->getVar($host, 'hostlookup-' . $ip, 600) || empty($ip)) |
1242 | - return $host; |
|
1382 | + { |
|
1383 | + return $host; |
|
1384 | + } |
|
1243 | 1385 | |
1244 | 1386 | $t = microtime(true); |
1245 | 1387 | |
@@ -1294,11 +1436,15 @@ discard block |
||
1294 | 1436 | |
1295 | 1437 | // This is the last try :/. |
1296 | 1438 | if (!isset($host) || $host === false) |
1297 | - $host = @gethostbyaddr($ip); |
|
1439 | + { |
|
1440 | + $host = @gethostbyaddr($ip); |
|
1441 | + } |
|
1298 | 1442 | |
1299 | 1443 | // It took a long time, so let's cache it! |
1300 | 1444 | if (microtime(true) - $t > 0.5) |
1301 | - $cache->put('hostlookup-' . $ip, $host, 600); |
|
1445 | + { |
|
1446 | + $cache->put('hostlookup-' . $ip, $host, 600); |
|
1447 | + } |
|
1302 | 1448 | |
1303 | 1449 | return $host; |
1304 | 1450 | } |
@@ -1338,7 +1484,9 @@ discard block |
||
1338 | 1484 | |
1339 | 1485 | // Create an integer representation |
1340 | 1486 | for ($i = 0; $i < $max_chars; $i++) |
1341 | - $total += $possible_chars[ord($encrypted[$i])] * pow(63, $i); |
|
1487 | + { |
|
1488 | + $total += $possible_chars[ord($encrypted[$i])] * pow(63, $i); |
|
1489 | + } |
|
1342 | 1490 | |
1343 | 1491 | // Return the value |
1344 | 1492 | $returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total; |
@@ -1351,8 +1499,10 @@ discard block |
||
1351 | 1499 | // Trim characters before and after and add slashes for database insertion. |
1352 | 1500 | $returned_words = array(); |
1353 | 1501 | foreach ($words as $word) |
1354 | - if (($word = trim($word, '-_\'')) !== '') |
|
1502 | + { |
|
1503 | + if (($word = trim($word, '-_\'')) !== '') |
|
1355 | 1504 | $returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars); |
1505 | + } |
|
1356 | 1506 | |
1357 | 1507 | // Filter out all words that occur more than once. |
1358 | 1508 | return array_unique($returned_words); |
@@ -1378,15 +1528,22 @@ discard block |
||
1378 | 1528 | |
1379 | 1529 | // Does the current loaded theme have this and we are not forcing the usage of this function? |
1380 | 1530 | if (function_exists('template_create_button') && !$force_use) |
1381 | - return template_create_button($name, $alt, $label = '', $custom = ''); |
|
1531 | + { |
|
1532 | + return template_create_button($name, $alt, $label = '', $custom = ''); |
|
1533 | + } |
|
1382 | 1534 | |
1383 | 1535 | if (!$settings['use_image_buttons']) |
1384 | - return $txt[$alt]; |
|
1536 | + { |
|
1537 | + return $txt[$alt]; |
|
1538 | + } |
|
1385 | 1539 | elseif (!empty($settings['use_buttons'])) |
1386 | - return '<img src="' . $settings['images_url'] . '/buttons/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
1387 | - else |
|
1388 | - return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />'; |
|
1389 | -} |
|
1540 | + { |
|
1541 | + return '<img src="' . $settings['images_url'] . '/buttons/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />' . ($label != '' ? ' <strong>' . $txt[$label] . '</strong>' : ''); |
|
1542 | + } |
|
1543 | + else { |
|
1544 | + return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . ' />'; |
|
1545 | + } |
|
1546 | + } |
|
1390 | 1547 | |
1391 | 1548 | /** |
1392 | 1549 | * Sets up all of the top menu buttons |
@@ -1413,8 +1570,10 @@ discard block |
||
1413 | 1570 | |
1414 | 1571 | // Change the seed. |
1415 | 1572 | if (mt_rand(1, 250) == 69 || empty($modSettings['rand_seed'])) |
1416 | - updateSettings(array('rand_seed' => mt_rand())); |
|
1417 | -} |
|
1573 | + { |
|
1574 | + updateSettings(array('rand_seed' => mt_rand())); |
|
1575 | + } |
|
1576 | + } |
|
1418 | 1577 | |
1419 | 1578 | /** |
1420 | 1579 | * Process functions of an integration hook. |
@@ -1500,35 +1659,50 @@ discard block |
||
1500 | 1659 | function replaceEntities__callback($matches) |
1501 | 1660 | { |
1502 | 1661 | if (!isset($matches[2])) |
1503 | - return ''; |
|
1662 | + { |
|
1663 | + return ''; |
|
1664 | + } |
|
1504 | 1665 | |
1505 | 1666 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
1506 | 1667 | |
1507 | 1668 | // remove left to right / right to left overrides |
1508 | 1669 | if ($num === 0x202D || $num === 0x202E) |
1509 | - return ''; |
|
1670 | + { |
|
1671 | + return ''; |
|
1672 | + } |
|
1510 | 1673 | |
1511 | 1674 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
1512 | 1675 | if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
1513 | - return '&#' . $num . ';'; |
|
1676 | + { |
|
1677 | + return '&#' . $num . ';'; |
|
1678 | + } |
|
1514 | 1679 | |
1515 | 1680 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
1516 | 1681 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
1517 | 1682 | if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
1518 | - return ''; |
|
1683 | + { |
|
1684 | + return ''; |
|
1685 | + } |
|
1519 | 1686 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
1520 | 1687 | elseif ($num < 0x80) |
1521 | - return chr($num); |
|
1688 | + { |
|
1689 | + return chr($num); |
|
1690 | + } |
|
1522 | 1691 | // <0x800 (2048) |
1523 | 1692 | elseif ($num < 0x800) |
1524 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
1693 | + { |
|
1694 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
1695 | + } |
|
1525 | 1696 | // < 0x10000 (65536) |
1526 | 1697 | elseif ($num < 0x10000) |
1527 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1698 | + { |
|
1699 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1700 | + } |
|
1528 | 1701 | // <= 0x10FFFF (1114111) |
1529 | - else |
|
1530 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1531 | -} |
|
1702 | + else { |
|
1703 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1704 | + } |
|
1705 | + } |
|
1532 | 1706 | |
1533 | 1707 | /** |
1534 | 1708 | * Converts html entities to utf8 equivalents |
@@ -1546,27 +1720,38 @@ discard block |
||
1546 | 1720 | function fixchar__callback($matches) |
1547 | 1721 | { |
1548 | 1722 | if (!isset($matches[1])) |
1549 | - return ''; |
|
1723 | + { |
|
1724 | + return ''; |
|
1725 | + } |
|
1550 | 1726 | |
1551 | 1727 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
1552 | 1728 | |
1553 | 1729 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
1554 | 1730 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
1555 | 1731 | if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
1556 | - return ''; |
|
1732 | + { |
|
1733 | + return ''; |
|
1734 | + } |
|
1557 | 1735 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
1558 | 1736 | elseif ($num < 0x80) |
1559 | - return chr($num); |
|
1737 | + { |
|
1738 | + return chr($num); |
|
1739 | + } |
|
1560 | 1740 | // <0x800 (2048) |
1561 | 1741 | elseif ($num < 0x800) |
1562 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
1742 | + { |
|
1743 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
1744 | + } |
|
1563 | 1745 | // < 0x10000 (65536) |
1564 | 1746 | elseif ($num < 0x10000) |
1565 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1747 | + { |
|
1748 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1749 | + } |
|
1566 | 1750 | // <= 0x10FFFF (1114111) |
1567 | - else |
|
1568 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1569 | -} |
|
1751 | + else { |
|
1752 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
1753 | + } |
|
1754 | + } |
|
1570 | 1755 | |
1571 | 1756 | /** |
1572 | 1757 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -1583,16 +1768,21 @@ discard block |
||
1583 | 1768 | function entity_fix__callback($matches) |
1584 | 1769 | { |
1585 | 1770 | if (!isset($matches[2])) |
1586 | - return ''; |
|
1771 | + { |
|
1772 | + return ''; |
|
1773 | + } |
|
1587 | 1774 | |
1588 | 1775 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
1589 | 1776 | |
1590 | 1777 | // We don't allow control characters, characters out of range, byte markers, etc |
1591 | 1778 | if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
1592 | - return ''; |
|
1593 | - else |
|
1594 | - return '&#' . $num . ';'; |
|
1595 | -} |
|
1779 | + { |
|
1780 | + return ''; |
|
1781 | + } |
|
1782 | + else { |
|
1783 | + return '&#' . $num . ';'; |
|
1784 | + } |
|
1785 | + } |
|
1596 | 1786 | |
1597 | 1787 | /** |
1598 | 1788 | * Retrieve additional search engines, if there are any, as an array. |
@@ -1608,7 +1798,9 @@ discard block |
||
1608 | 1798 | { |
1609 | 1799 | $search_engines = Util::unserialize($modSettings['additional_search_engines']); |
1610 | 1800 | foreach ($search_engines as $engine) |
1611 | - $engines[strtolower(preg_replace('~[^A-Za-z0-9 ]~', '', $engine['name']))] = $engine; |
|
1801 | + { |
|
1802 | + $engines[strtolower(preg_replace('~[^A-Za-z0-9 ]~', '', $engine['name']))] = $engine; |
|
1803 | + } |
|
1612 | 1804 | } |
1613 | 1805 | |
1614 | 1806 | return $engines; |
@@ -1634,11 +1826,15 @@ discard block |
||
1634 | 1826 | |
1635 | 1827 | // Start from the beginning... |
1636 | 1828 | if ($reset) |
1637 | - return $db->data_seek($messages_request, 0); |
|
1829 | + { |
|
1830 | + return $db->data_seek($messages_request, 0); |
|
1831 | + } |
|
1638 | 1832 | |
1639 | 1833 | // If the query has already returned false, get out of here |
1640 | 1834 | if (empty($messages_request)) |
1641 | - return false; |
|
1835 | + { |
|
1836 | + return false; |
|
1837 | + } |
|
1642 | 1838 | |
1643 | 1839 | // Attempt to get the next message. |
1644 | 1840 | $message = $db->fetch_assoc($messages_request); |
@@ -1671,22 +1867,32 @@ discard block |
||
1671 | 1867 | { |
1672 | 1868 | // Search for key names or values |
1673 | 1869 | if ($assoc) |
1674 | - $position = array_search($key, array_keys($input), $strict); |
|
1675 | - else |
|
1676 | - $position = array_search($key, $input, $strict); |
|
1870 | + { |
|
1871 | + $position = array_search($key, array_keys($input), $strict); |
|
1872 | + } |
|
1873 | + else { |
|
1874 | + $position = array_search($key, $input, $strict); |
|
1875 | + } |
|
1677 | 1876 | |
1678 | 1877 | // If the key is not found, just insert it at the end |
1679 | 1878 | if ($position === false) |
1680 | - return array_merge($input, $insert); |
|
1879 | + { |
|
1880 | + return array_merge($input, $insert); |
|
1881 | + } |
|
1681 | 1882 | |
1682 | 1883 | if ($where === 'after') |
1683 | - $position++; |
|
1884 | + { |
|
1885 | + $position++; |
|
1886 | + } |
|
1684 | 1887 | |
1685 | 1888 | // Insert as first |
1686 | 1889 | if ($position === 0) |
1687 | - $input = array_merge($insert, $input); |
|
1688 | - else |
|
1689 | - $input = array_merge(array_slice($input, 0, $position), $insert, array_slice($input, $position)); |
|
1890 | + { |
|
1891 | + $input = array_merge($insert, $input); |
|
1892 | + } |
|
1893 | + else { |
|
1894 | + $input = array_merge(array_slice($input, 0, $position), $insert, array_slice($input, $position)); |
|
1895 | + } |
|
1690 | 1896 | |
1691 | 1897 | return $input; |
1692 | 1898 | } |
@@ -1706,9 +1912,12 @@ discard block |
||
1706 | 1912 | global $modSettings; |
1707 | 1913 | |
1708 | 1914 | if (!isset($modSettings['scheduleTaskImmediate'])) |
1709 | - $scheduleTaskImmediate = array(); |
|
1710 | - else |
|
1711 | - $scheduleTaskImmediate = Util::unserialize($modSettings['scheduleTaskImmediate']); |
|
1915 | + { |
|
1916 | + $scheduleTaskImmediate = array(); |
|
1917 | + } |
|
1918 | + else { |
|
1919 | + $scheduleTaskImmediate = Util::unserialize($modSettings['scheduleTaskImmediate']); |
|
1920 | + } |
|
1712 | 1921 | |
1713 | 1922 | // If it has not been scheduled, the do so now |
1714 | 1923 | if (!isset($scheduleTaskImmediate[$task])) |
@@ -1739,9 +1948,12 @@ discard block |
||
1739 | 1948 | |
1740 | 1949 | // Not on, bail |
1741 | 1950 | if (!isset($modSettings['scheduleTaskImmediate'])) |
1742 | - return; |
|
1743 | - else |
|
1744 | - $scheduleTaskImmediate = Util::unserialize($modSettings['scheduleTaskImmediate']); |
|
1951 | + { |
|
1952 | + return; |
|
1953 | + } |
|
1954 | + else { |
|
1955 | + $scheduleTaskImmediate = Util::unserialize($modSettings['scheduleTaskImmediate']); |
|
1956 | + } |
|
1745 | 1957 | |
1746 | 1958 | // Clear / remove the task if it was set |
1747 | 1959 | if (isset($scheduleTaskImmediate[$task])) |
@@ -1845,10 +2057,13 @@ discard block |
||
1845 | 2057 | $time = trim(file_get_contents(BOARDDIR . '/db_last_error.txt')); |
1846 | 2058 | |
1847 | 2059 | if (preg_match('~^\d{10}$~', $time) === 1) |
1848 | - return $time; |
|
1849 | - else |
|
1850 | - return 0; |
|
1851 | -} |
|
2060 | + { |
|
2061 | + return $time; |
|
2062 | + } |
|
2063 | + else { |
|
2064 | + return 0; |
|
2065 | + } |
|
2066 | + } |
|
1852 | 2067 | |
1853 | 2068 | /** |
1854 | 2069 | * This function has the only task to retrieve the correct prefix to be used |
@@ -1867,7 +2082,9 @@ discard block |
||
1867 | 2082 | if ($response_prefix === null && (!$cache->getVar($response_prefix, 'response_prefix') || !$response_prefix)) |
1868 | 2083 | { |
1869 | 2084 | if ($language === $user_info['language']) |
1870 | - $response_prefix = $txt['response_prefix']; |
|
2085 | + { |
|
2086 | + $response_prefix = $txt['response_prefix']; |
|
2087 | + } |
|
1871 | 2088 | else |
1872 | 2089 | { |
1873 | 2090 | loadLanguage('index', $language, false); |
@@ -1895,10 +2112,13 @@ discard block |
||
1895 | 2112 | { |
1896 | 2113 | $value = trim($value); |
1897 | 2114 | if (filter_var($value, FILTER_VALIDATE_EMAIL) && Util::strlen($value) < 255) |
1898 | - return $value; |
|
1899 | - else |
|
1900 | - return false; |
|
1901 | -} |
|
2115 | + { |
|
2116 | + return $value; |
|
2117 | + } |
|
2118 | + else { |
|
2119 | + return false; |
|
2120 | + } |
|
2121 | + } |
|
1902 | 2122 | |
1903 | 2123 | /** |
1904 | 2124 | * Adds a protocol (http/s, ftp/mailto) to the beginning of an url if missing |
@@ -2042,7 +2262,9 @@ discard block |
||
2042 | 2262 | |
2043 | 2263 | // Don't know any browser! |
2044 | 2264 | if (empty($context['browser'])) |
2045 | - detectBrowser(); |
|
2265 | + { |
|
2266 | + detectBrowser(); |
|
2267 | + } |
|
2046 | 2268 | |
2047 | 2269 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
2048 | 2270 | } |
@@ -2114,7 +2336,9 @@ discard block |
||
2114 | 2336 | foreach ($button_strip as $key => $value) |
2115 | 2337 | { |
2116 | 2338 | if (!isset($value['test']) || !empty($context[$value['test']])) |
2117 | - return true; |
|
2339 | + { |
|
2340 | + return true; |
|
2341 | + } |
|
2118 | 2342 | } |
2119 | 2343 | |
2120 | 2344 | return false; |
@@ -1918,7 +1918,7 @@ |
||
1918 | 1918 | } |
1919 | 1919 | else |
1920 | 1920 | { |
1921 | - $pattern = '~^(' . implode('|', array_map(function ($val) {return preg_quote($val, '~');}, $protocols)) . ')~i'; |
|
1921 | + $pattern = '~^(' . implode('|', array_map(function($val) {return preg_quote($val, '~'); }, $protocols)) . ')~i'; |
|
1922 | 1922 | } |
1923 | 1923 | |
1924 | 1924 | $found = false; |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | # requirements (there can be none), but merely suggestions. |
26 | 26 | # |
27 | 27 | |
28 | -class PasswordHash { |
|
28 | +class PasswordHash |
|
29 | +{ |
|
29 | 30 | var $itoa64; |
30 | 31 | var $iteration_count_log2; |
31 | 32 | var $portable_hashes; |
@@ -36,7 +37,9 @@ discard block |
||
36 | 37 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
37 | 38 | |
38 | 39 | if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) |
39 | - $iteration_count_log2 = 8; |
|
40 | + { |
|
41 | + $iteration_count_log2 = 8; |
|
42 | + } |
|
40 | 43 | $this->iteration_count_log2 = $iteration_count_log2; |
41 | 44 | |
42 | 45 | $this->portable_hashes = $portable_hashes; |
@@ -49,25 +52,30 @@ discard block |
||
49 | 52 | $output = ''; |
50 | 53 | |
51 | 54 | // PHP >= 7 |
52 | - if (is_callable('random_bytes')) { |
|
55 | + if (is_callable('random_bytes')) |
|
56 | + { |
|
53 | 57 | $output = random_bytes($count); |
54 | 58 | } |
55 | 59 | // *nix |
56 | 60 | elseif (@is_readable('/dev/urandom') && |
57 | - ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
61 | + ($fh = @fopen('/dev/urandom', 'rb'))) |
|
62 | + { |
|
58 | 63 | $output = fread($fh, $count); |
59 | 64 | fclose($fh); |
60 | 65 | } |
61 | 66 | // This is much to slow on windows php < 5.3.4 |
62 | 67 | elseif (function_exists('openssl_random_pseudo_bytes') && |
63 | - (substr(PHP_OS, 0, 3) !== 'WIN' || version_compare(PHP_VERSION, '5.3.4', '>='))) { |
|
68 | + (substr(PHP_OS, 0, 3) !== 'WIN' || version_compare(PHP_VERSION, '5.3.4', '>='))) |
|
69 | + { |
|
64 | 70 | $output = openssl_random_pseudo_bytes($count); |
65 | 71 | } |
66 | 72 | |
67 | 73 | // Do it ourselves then |
68 | - if (strlen($output) < $count) { |
|
74 | + if (strlen($output) < $count) |
|
75 | + { |
|
69 | 76 | $output = ''; |
70 | - for ($i = 0; $i < $count; $i += 16) { |
|
77 | + for ($i = 0; $i < $count; $i += 16) |
|
78 | + { |
|
71 | 79 | $this->random_state = |
72 | 80 | md5(microtime() . $this->random_state); |
73 | 81 | $output .= |
@@ -83,19 +91,28 @@ discard block |
||
83 | 91 | { |
84 | 92 | $output = ''; |
85 | 93 | $i = 0; |
86 | - do { |
|
94 | + do |
|
95 | + { |
|
87 | 96 | $value = ord($input[$i++]); |
88 | 97 | $output .= $this->itoa64[$value & 0x3f]; |
89 | 98 | if ($i < $count) |
90 | - $value |= ord($input[$i]) << 8; |
|
99 | + { |
|
100 | + $value |= ord($input[$i]) << 8; |
|
101 | + } |
|
91 | 102 | $output .= $this->itoa64[($value >> 6) & 0x3f]; |
92 | 103 | if ($i++ >= $count) |
93 | - break; |
|
104 | + { |
|
105 | + break; |
|
106 | + } |
|
94 | 107 | if ($i < $count) |
95 | - $value |= ord($input[$i]) << 16; |
|
108 | + { |
|
109 | + $value |= ord($input[$i]) << 16; |
|
110 | + } |
|
96 | 111 | $output .= $this->itoa64[($value >> 12) & 0x3f]; |
97 | 112 | if ($i++ >= $count) |
98 | - break; |
|
113 | + { |
|
114 | + break; |
|
115 | + } |
|
99 | 116 | $output .= $this->itoa64[($value >> 18) & 0x3f]; |
100 | 117 | } while ($i < $count); |
101 | 118 | |
@@ -116,22 +133,30 @@ discard block |
||
116 | 133 | { |
117 | 134 | $output = '*0'; |
118 | 135 | if (substr($setting, 0, 2) == $output) |
119 | - $output = '*1'; |
|
136 | + { |
|
137 | + $output = '*1'; |
|
138 | + } |
|
120 | 139 | |
121 | 140 | $id = substr($setting, 0, 3); |
122 | 141 | # We use "$P$", phpBB3 uses "$H$" for the same thing |
123 | 142 | if ($id != '$P$' && $id != '$H$') |
124 | - return $output; |
|
143 | + { |
|
144 | + return $output; |
|
145 | + } |
|
125 | 146 | |
126 | 147 | $count_log2 = strpos($this->itoa64, $setting[3]); |
127 | 148 | if ($count_log2 < 7 || $count_log2 > 30) |
128 | - return $output; |
|
149 | + { |
|
150 | + return $output; |
|
151 | + } |
|
129 | 152 | |
130 | 153 | $count = 1 << $count_log2; |
131 | 154 | |
132 | 155 | $salt = substr($setting, 4, 8); |
133 | 156 | if (strlen($salt) != 8) |
134 | - return $output; |
|
157 | + { |
|
158 | + return $output; |
|
159 | + } |
|
135 | 160 | |
136 | 161 | # We're kind of forced to use MD5 here since it's the only |
137 | 162 | # cryptographic primitive available in all versions of PHP |
@@ -139,14 +164,19 @@ discard block |
||
139 | 164 | # in PHP would result in much worse performance and |
140 | 165 | # consequently in lower iteration counts and hashes that are |
141 | 166 | # quicker to crack (by non-PHP code). |
142 | - if (PHP_VERSION >= '5') { |
|
167 | + if (PHP_VERSION >= '5') |
|
168 | + { |
|
143 | 169 | $hash = md5($salt . $password, TRUE); |
144 | - do { |
|
170 | + do |
|
171 | + { |
|
145 | 172 | $hash = md5($hash . $password, TRUE); |
146 | 173 | } while (--$count); |
147 | - } else { |
|
174 | + } |
|
175 | + else |
|
176 | + { |
|
148 | 177 | $hash = pack('H*', md5($salt . $password)); |
149 | - do { |
|
178 | + do |
|
179 | + { |
|
150 | 180 | $hash = pack('H*', md5($hash . $password)); |
151 | 181 | } while (--$count); |
152 | 182 | } |
@@ -193,11 +223,13 @@ discard block |
||
193 | 223 | $output .= '$'; |
194 | 224 | |
195 | 225 | $i = 0; |
196 | - do { |
|
226 | + do |
|
227 | + { |
|
197 | 228 | $c1 = ord($input[$i++]); |
198 | 229 | $output .= $itoa64[$c1 >> 2]; |
199 | 230 | $c1 = ($c1 & 0x03) << 4; |
200 | - if ($i >= 16) { |
|
231 | + if ($i >= 16) |
|
232 | + { |
|
201 | 233 | $output .= $itoa64[$c1]; |
202 | 234 | break; |
203 | 235 | } |
@@ -219,34 +251,48 @@ discard block |
||
219 | 251 | public function HashPassword($password) |
220 | 252 | { |
221 | 253 | if ( strlen( $password ) > 4096 ) |
222 | - return '*'; |
|
254 | + { |
|
255 | + return '*'; |
|
256 | + } |
|
223 | 257 | |
224 | 258 | $random = ''; |
225 | 259 | |
226 | - if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
|
260 | + if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) |
|
261 | + { |
|
227 | 262 | $random = $this->get_random_bytes(16); |
228 | 263 | $hash = |
229 | 264 | crypt($password, $this->gensalt_blowfish($random)); |
230 | 265 | if (strlen($hash) == 60) |
231 | - return $hash; |
|
266 | + { |
|
267 | + return $hash; |
|
268 | + } |
|
232 | 269 | } |
233 | 270 | |
234 | - if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
|
271 | + if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) |
|
272 | + { |
|
235 | 273 | if (strlen($random) < 3) |
236 | - $random = $this->get_random_bytes(3); |
|
274 | + { |
|
275 | + $random = $this->get_random_bytes(3); |
|
276 | + } |
|
237 | 277 | $hash = |
238 | 278 | crypt($password, $this->gensalt_extended($random)); |
239 | 279 | if (strlen($hash) == 20) |
240 | - return $hash; |
|
280 | + { |
|
281 | + return $hash; |
|
282 | + } |
|
241 | 283 | } |
242 | 284 | |
243 | 285 | if (strlen($random) < 6) |
244 | - $random = $this->get_random_bytes(6); |
|
286 | + { |
|
287 | + $random = $this->get_random_bytes(6); |
|
288 | + } |
|
245 | 289 | $hash = |
246 | 290 | $this->crypt_private($password, |
247 | 291 | $this->gensalt_private($random)); |
248 | 292 | if (strlen($hash) == 34) |
249 | - return $hash; |
|
293 | + { |
|
294 | + return $hash; |
|
295 | + } |
|
250 | 296 | |
251 | 297 | # Returning '*' on error is safe here, but would _not_ be safe |
252 | 298 | # in a crypt(3)-like function used _both_ for generating new |
@@ -257,11 +303,15 @@ discard block |
||
257 | 303 | public function CheckPassword($password, $stored_hash) |
258 | 304 | { |
259 | 305 | if ( strlen( $password ) > 4096 ) |
260 | - return false; |
|
306 | + { |
|
307 | + return false; |
|
308 | + } |
|
261 | 309 | |
262 | 310 | $hash = $this->crypt_private($password, $stored_hash); |
263 | 311 | if ($hash[0] == '*') |
264 | - $hash = crypt($password, $stored_hash); |
|
312 | + { |
|
313 | + $hash = crypt($password, $stored_hash); |
|
314 | + } |
|
265 | 315 | |
266 | 316 | return $this->_hash_equals($hash, $stored_hash); |
267 | 317 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | $this->portable_hashes = $portable_hashes; |
43 | 43 | |
44 | - $this->random_state = microtime() . uniqid(rand(), TRUE); |
|
44 | + $this->random_state = microtime() . uniqid(rand(), true); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | private function get_random_bytes($count) |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | # consequently in lower iteration counts and hashes that are |
141 | 141 | # quicker to crack (by non-PHP code). |
142 | 142 | if (PHP_VERSION >= '5') { |
143 | - $hash = md5($salt . $password, TRUE); |
|
143 | + $hash = md5($salt . $password, true); |
|
144 | 144 | do { |
145 | - $hash = md5($hash . $password, TRUE); |
|
145 | + $hash = md5($hash . $password, true); |
|
146 | 146 | } while (--$count); |
147 | 147 | } else { |
148 | 148 | $hash = pack('H*', md5($salt . $password)); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | var $portable_hashes; |
32 | 32 | var $random_state; |
33 | 33 | |
34 | - public function __construct( $iteration_count_log2, $portable_hashes ) |
|
34 | + public function __construct($iteration_count_log2, $portable_hashes) |
|
35 | 35 | { |
36 | 36 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
37 | 37 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | public function HashPassword($password) |
220 | 220 | { |
221 | - if ( strlen( $password ) > 4096 ) |
|
221 | + if (strlen($password) > 4096) |
|
222 | 222 | return '*'; |
223 | 223 | |
224 | 224 | $random = ''; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | public function CheckPassword($password, $stored_hash) |
258 | 258 | { |
259 | - if ( strlen( $password ) > 4096 ) |
|
259 | + if (strlen($password) > 4096) |
|
260 | 260 | return false; |
261 | 261 | |
262 | 262 | $hash = $this->crypt_private($password, $stored_hash); |
@@ -1,4 +1,7 @@ discard block |
||
1 | -<?php if (!defined('BB2_CORE')) die("I said no cheating!"); |
|
1 | +<?php if (!defined('BB2_CORE')) |
|
2 | +{ |
|
3 | + die("I said no cheating!"); |
|
4 | +} |
|
2 | 5 | |
3 | 6 | # Round trip DNS verification |
4 | 7 | |
@@ -9,12 +12,21 @@ discard block |
||
9 | 12 | # between no records and error condition |
10 | 13 | function bb2_roundtripdns($ip,$domain) |
11 | 14 | { |
12 | - if (@is_ipv6($ip)) return $ip; |
|
15 | + if (@is_ipv6($ip)) |
|
16 | + { |
|
17 | + return $ip; |
|
18 | + } |
|
13 | 19 | |
14 | 20 | $host = gethostbyaddr($ip); |
15 | 21 | $host_result = strpos(strrev($host), strrev($domain)); |
16 | - if ($host_result === false || $host_result > 0) return false; |
|
22 | + if ($host_result === false || $host_result > 0) |
|
23 | + { |
|
24 | + return false; |
|
25 | + } |
|
17 | 26 | $addrs = gethostbynamel($host); |
18 | - if (in_array($ip, $addrs)) return true; |
|
27 | + if (in_array($ip, $addrs)) |
|
28 | + { |
|
29 | + return true; |
|
30 | + } |
|
19 | 31 | return false; |
20 | 32 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | # TODO: Not IPv6 safe |
8 | 8 | # FIXME: Returns false on DNS server failure; PHP provides no distinction |
9 | 9 | # between no records and error condition |
10 | -function bb2_roundtripdns($ip,$domain) |
|
10 | +function bb2_roundtripdns($ip, $domain) |
|
11 | 11 | { |
12 | 12 | if (@is_ipv6($ip)) return $ip; |
13 | 13 |
@@ -1,33 +1,57 @@ |
||
1 | -<?php if (!defined('BB2_CORE')) die('I said no cheating!'); |
|
1 | +<?php if (!defined('BB2_CORE')) |
|
2 | +{ |
|
3 | + die('I said no cheating!'); |
|
4 | +} |
|
2 | 5 | |
3 | 6 | function bb2_run_whitelist($package) |
4 | 7 | { |
5 | 8 | # FIXME: Transitional, until port maintainters implement bb2_read_whitelist |
6 | - if (function_exists('bb2_read_whitelist')) { |
|
9 | + if (function_exists('bb2_read_whitelist')) |
|
10 | + { |
|
7 | 11 | $whitelists = bb2_read_whitelist(); |
8 | - } else { |
|
12 | + } |
|
13 | + else |
|
14 | + { |
|
9 | 15 | $whitelists = @parse_ini_file(dirname(BB2_CORE) . "/whitelist.ini"); |
10 | 16 | } |
11 | 17 | |
12 | - if (@!empty($whitelists['ip'])) { |
|
13 | - foreach (array_filter($whitelists['ip']) as $range) { |
|
14 | - if (match_cidr($package['ip'], $range)) return true; |
|
18 | + if (@!empty($whitelists['ip'])) |
|
19 | + { |
|
20 | + foreach (array_filter($whitelists['ip']) as $range) |
|
21 | + { |
|
22 | + if (match_cidr($package['ip'], $range)) |
|
23 | + { |
|
24 | + return true; |
|
25 | + } |
|
15 | 26 | } |
16 | 27 | } |
17 | - if (@!empty($whitelists['useragent'])) { |
|
18 | - foreach (array_filter($whitelists['useragent']) as $user_agent) { |
|
19 | - if (!strcmp($package['headers_mixed']['User-Agent'], $user_agent)) return true; |
|
28 | + if (@!empty($whitelists['useragent'])) |
|
29 | + { |
|
30 | + foreach (array_filter($whitelists['useragent']) as $user_agent) |
|
31 | + { |
|
32 | + if (!strcmp($package['headers_mixed']['User-Agent'], $user_agent)) |
|
33 | + { |
|
34 | + return true; |
|
35 | + } |
|
20 | 36 | } |
21 | 37 | } |
22 | - if (@!empty($whitelists['url'])) { |
|
23 | - if (strpos($package['request_uri'], "?") === FALSE) { |
|
38 | + if (@!empty($whitelists['url'])) |
|
39 | + { |
|
40 | + if (strpos($package['request_uri'], "?") === FALSE) |
|
41 | + { |
|
24 | 42 | $request_uri = $package['request_uri']; |
25 | - } else { |
|
43 | + } |
|
44 | + else |
|
45 | + { |
|
26 | 46 | $request_uri = substr($package['request_uri'], 0, strpos($package['request_uri'], "?")); |
27 | 47 | } |
28 | - foreach (array_filter($whitelists['url']) as $url) { |
|
48 | + foreach (array_filter($whitelists['url']) as $url) |
|
49 | + { |
|
29 | 50 | $pos = strpos($request_uri, $url); |
30 | - if ($pos !== false && $pos == 0) return true; |
|
51 | + if ($pos !== false && $pos == 0) |
|
52 | + { |
|
53 | + return true; |
|
54 | + } |
|
31 | 55 | } |
32 | 56 | } |
33 | 57 | return false; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | } |
21 | 21 | } |
22 | 22 | if (@!empty($whitelists['url'])) { |
23 | - if (strpos($package['request_uri'], "?") === FALSE) { |
|
23 | + if (strpos($package['request_uri'], "?") === false) { |
|
24 | 24 | $request_uri = $package['request_uri']; |
25 | 25 | } else { |
26 | 26 | $request_uri = substr($package['request_uri'], 0, strpos($package['request_uri'], "?")); |
@@ -1,4 +1,7 @@ discard block |
||
1 | -<?php if (!defined('BB2_CWD')) die("I said no cheating!"); |
|
1 | +<?php if (!defined('BB2_CWD')) |
|
2 | +{ |
|
3 | + die("I said no cheating!"); |
|
4 | +} |
|
2 | 5 | define('BB2_VERSION', "2.2.22"); |
3 | 6 | |
4 | 7 | // Bad Behavior entry point is bb2_start() |
@@ -18,7 +21,8 @@ discard block |
||
18 | 21 | require_once(BB2_CORE . "/banned.inc.php"); |
19 | 22 | bb2_display_denial($settings, $package, $key, $previous_key); |
20 | 23 | bb2_log_denial($settings, $package, $key, $previous_key); |
21 | - if (is_callable('bb2_banned_callback')) { |
|
24 | + if (is_callable('bb2_banned_callback')) |
|
25 | + { |
|
22 | 26 | bb2_banned_callback($settings, $package, $key); |
23 | 27 | } |
24 | 28 | // Penalize the spammers some more |
@@ -29,12 +33,14 @@ discard block |
||
29 | 33 | function bb2_approved($settings, $package) |
30 | 34 | { |
31 | 35 | // Dirk wanted this |
32 | - if (is_callable('bb2_approved_callback')) { |
|
36 | + if (is_callable('bb2_approved_callback')) |
|
37 | + { |
|
33 | 38 | bb2_approved_callback($settings, $package); |
34 | 39 | } |
35 | 40 | |
36 | 41 | // Decide what to log on approved requests. |
37 | - if (($settings['verbose'] && $settings['logging']) || empty($package['user_agent'])) { |
|
42 | + if (($settings['verbose'] && $settings['logging']) || empty($package['user_agent'])) |
|
43 | + { |
|
38 | 44 | bb2_db_query(bb2_insert($settings, $package, "00000000")); |
39 | 45 | } |
40 | 46 | } |
@@ -44,21 +50,29 @@ discard block |
||
44 | 50 | { |
45 | 51 | # Detect if option is on when it should be off |
46 | 52 | $header = uc_all($settings['reverse_proxy_header']); |
47 | - if (!array_key_exists($header, $headers_mixed)) { |
|
53 | + if (!array_key_exists($header, $headers_mixed)) |
|
54 | + { |
|
48 | 55 | return false; |
49 | 56 | } |
50 | 57 | |
51 | 58 | $addrs = @array_reverse(preg_split("/[\s,]+/", $headers_mixed[$header])); |
52 | 59 | # Skip our known reverse proxies and private addresses |
53 | - if (!empty($settings['reverse_proxy_addresses'])) { |
|
54 | - foreach ($addrs as $addr) { |
|
55 | - if (!match_cidr($addr, $settings['reverse_proxy_addresses']) && !is_rfc1918($addr)) { |
|
60 | + if (!empty($settings['reverse_proxy_addresses'])) |
|
61 | + { |
|
62 | + foreach ($addrs as $addr) |
|
63 | + { |
|
64 | + if (!match_cidr($addr, $settings['reverse_proxy_addresses']) && !is_rfc1918($addr)) |
|
65 | + { |
|
56 | 66 | return $addr; |
57 | 67 | } |
58 | 68 | } |
59 | - } else { |
|
60 | - foreach ($addrs as $addr) { |
|
61 | - if (!is_rfc1918($addr)) { |
|
69 | + } |
|
70 | + else |
|
71 | + { |
|
72 | + foreach ($addrs as $addr) |
|
73 | + { |
|
74 | + if (!is_rfc1918($addr)) |
|
75 | + { |
|
62 | 76 | return $addr; |
63 | 77 | } |
64 | 78 | } |
@@ -71,10 +85,13 @@ discard block |
||
71 | 85 | function bb2_unpack_php_post_array($key, $value) |
72 | 86 | { |
73 | 87 | $unpacked = array(); |
74 | - foreach ($value as $k => $v) { |
|
88 | + foreach ($value as $k => $v) |
|
89 | + { |
|
75 | 90 | $i = $key. '[' . $k . ']'; |
76 | 91 | if (is_array($v)) |
77 | - $v = bb2_unpack_php_post_array($i, $v); |
|
92 | + { |
|
93 | + $v = bb2_unpack_php_post_array($i, $v); |
|
94 | + } |
|
78 | 95 | $unpacked[$i] = $v; |
79 | 96 | } |
80 | 97 | return $unpacked; |
@@ -88,7 +105,8 @@ discard block |
||
88 | 105 | // Postprocess the headers to mixed-case |
89 | 106 | // TODO: get the world to stop using PHP as CGI |
90 | 107 | $headers_mixed = array(); |
91 | - foreach ($headers as $h => $v) { |
|
108 | + foreach ($headers as $h => $v) |
|
109 | + { |
|
92 | 110 | $headers_mixed[uc_all($h)] = $v; |
93 | 111 | } |
94 | 112 | |
@@ -97,9 +115,12 @@ discard block |
||
97 | 115 | |
98 | 116 | // Reconstruct the HTTP entity, if present. |
99 | 117 | $request_entity = array(); |
100 | - if (isset($_SERVER['REQUEST_METHOD']) && (!strcasecmp($_SERVER['REQUEST_METHOD'], "POST") || !strcasecmp($_SERVER['REQUEST_METHOD'], "PUT"))) { |
|
101 | - foreach ($_POST as $h => $v) { |
|
102 | - if (is_array($v)) { |
|
118 | + if (isset($_SERVER['REQUEST_METHOD']) && (!strcasecmp($_SERVER['REQUEST_METHOD'], "POST") || !strcasecmp($_SERVER['REQUEST_METHOD'], "PUT"))) |
|
119 | + { |
|
120 | + foreach ($_POST as $h => $v) |
|
121 | + { |
|
122 | + if (is_array($v)) |
|
123 | + { |
|
103 | 124 | # Workaround, see Bug #12 |
104 | 125 | $v = "Array"; |
105 | 126 | } |
@@ -108,19 +129,29 @@ discard block |
||
108 | 129 | } |
109 | 130 | |
110 | 131 | $request_uri = $_SERVER["REQUEST_URI"]; |
111 | - if (!$request_uri) $request_uri = $_SERVER['SCRIPT_NAME']; # IIS |
|
132 | + if (!$request_uri) |
|
133 | + { |
|
134 | + $request_uri = $_SERVER['SCRIPT_NAME']; |
|
135 | + } |
|
136 | + # IIS |
|
112 | 137 | |
113 | - if ($settings['reverse_proxy'] && $ip = bb2_reverse_proxy($settings, $headers_mixed)) { |
|
138 | + if ($settings['reverse_proxy'] && $ip = bb2_reverse_proxy($settings, $headers_mixed)) |
|
139 | + { |
|
114 | 140 | $headers['X-Bad-Behavior-Remote-Address'] = $_SERVER['REMOTE_ADDR']; |
115 | 141 | $headers_mixed['X-Bad-Behavior-Remote-Address'] = $_SERVER['REMOTE_ADDR']; |
116 | - } else { |
|
142 | + } |
|
143 | + else |
|
144 | + { |
|
117 | 145 | $ip = $_SERVER['REMOTE_ADDR']; |
118 | 146 | } |
119 | 147 | |
120 | 148 | @$package = array('ip' => $ip, 'headers' => $headers, 'headers_mixed' => $headers_mixed, 'request_method' => $_SERVER['REQUEST_METHOD'], 'request_uri' => $request_uri, 'server_protocol' => $_SERVER['SERVER_PROTOCOL'], 'request_entity' => $request_entity, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'is_browser' => false,); |
121 | 149 | |
122 | 150 | $result = bb2_screen($settings, $package); |
123 | - if ($result && !defined('BB2_TEST')) bb2_banned($settings, $package, $result); |
|
151 | + if ($result && !defined('BB2_TEST')) |
|
152 | + { |
|
153 | + bb2_banned($settings, $package, $result); |
|
154 | + } |
|
124 | 155 | return $result; |
125 | 156 | } |
126 | 157 | |
@@ -131,102 +162,195 @@ discard block |
||
131 | 162 | |
132 | 163 | // CloudFlare-specific checks not handled by reverse proxy code |
133 | 164 | // Thanks to butchs at Simple Machines |
134 | - if (array_key_exists('Cf-Connecting-Ip', $package['headers_mixed'])) { |
|
165 | + if (array_key_exists('Cf-Connecting-Ip', $package['headers_mixed'])) |
|
166 | + { |
|
135 | 167 | require_once(BB2_CORE . "/cloudflare.inc.php"); |
136 | 168 | $r = bb2_cloudflare($package); |
137 | - if ($r !== false && $r != $package['ip']) return $r; |
|
169 | + if ($r !== false && $r != $package['ip']) |
|
170 | + { |
|
171 | + return $r; |
|
172 | + } |
|
138 | 173 | } |
139 | 174 | |
140 | 175 | // First check the whitelist |
141 | 176 | require_once(BB2_CORE . "/whitelist.inc.php"); |
142 | - if (!bb2_run_whitelist($package)) { |
|
177 | + if (!bb2_run_whitelist($package)) |
|
178 | + { |
|
143 | 179 | // Now check the blacklist |
144 | 180 | require_once(BB2_CORE . "/blacklist.inc.php"); |
145 | - if ($r = bb2_blacklist($package)) return $r; |
|
181 | + if ($r = bb2_blacklist($package)) |
|
182 | + { |
|
183 | + return $r; |
|
184 | + } |
|
146 | 185 | |
147 | 186 | // Check the http:BL |
148 | 187 | require_once(BB2_CORE . "/blackhole.inc.php"); |
149 | - if ($r = bb2_httpbl($settings, $package)) { |
|
150 | - if ($r == 1) return false; # whitelisted |
|
188 | + if ($r = bb2_httpbl($settings, $package)) |
|
189 | + { |
|
190 | + if ($r == 1) |
|
191 | + { |
|
192 | + return false; |
|
193 | + } |
|
194 | + # whitelisted |
|
151 | 195 | return $r; |
152 | 196 | } |
153 | 197 | |
154 | 198 | // Check for common stuff |
155 | 199 | require_once(BB2_CORE . "/common_tests.inc.php"); |
156 | - if ($r = bb2_protocol($settings, $package)) return $r; |
|
157 | - if ($r = bb2_cookies($settings, $package)) return $r; |
|
158 | - if ($r = bb2_misc_headers($settings, $package)) return $r; |
|
200 | + if ($r = bb2_protocol($settings, $package)) |
|
201 | + { |
|
202 | + return $r; |
|
203 | + } |
|
204 | + if ($r = bb2_cookies($settings, $package)) |
|
205 | + { |
|
206 | + return $r; |
|
207 | + } |
|
208 | + if ($r = bb2_misc_headers($settings, $package)) |
|
209 | + { |
|
210 | + return $r; |
|
211 | + } |
|
159 | 212 | |
160 | 213 | // Specific checks |
161 | 214 | @$ua = $package['user_agent']; |
162 | 215 | // Search engine checks come first |
163 | - if (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) { |
|
216 | + if (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) |
|
217 | + { |
|
164 | 218 | require_once(BB2_CORE . "/searchengine.inc.php"); |
165 | - if ($r = bb2_msnbot($package)) { |
|
166 | - if ($r == 1) return false; # whitelisted |
|
219 | + if ($r = bb2_msnbot($package)) |
|
220 | + { |
|
221 | + if ($r == 1) |
|
222 | + { |
|
223 | + return false; |
|
224 | + } |
|
225 | + # whitelisted |
|
167 | 226 | return $r; |
168 | 227 | } |
169 | 228 | return false; |
170 | - } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Web Preview") !== FALSE) { |
|
229 | + } |
|
230 | + elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Web Preview") !== FALSE) |
|
231 | + { |
|
171 | 232 | require_once(BB2_CORE . "/searchengine.inc.php"); |
172 | - if ($r = bb2_google($package)) { |
|
173 | - if ($r == 1) return false; # whitelisted |
|
233 | + if ($r = bb2_google($package)) |
|
234 | + { |
|
235 | + if ($r == 1) |
|
236 | + { |
|
237 | + return false; |
|
238 | + } |
|
239 | + # whitelisted |
|
174 | 240 | return $r; |
175 | 241 | } |
176 | 242 | return false; |
177 | - } elseif (stripos($ua, "Yahoo! Slurp") !== FALSE || stripos($ua, "Yahoo! SearchMonkey") !== FALSE) { |
|
243 | + } |
|
244 | + elseif (stripos($ua, "Yahoo! Slurp") !== FALSE || stripos($ua, "Yahoo! SearchMonkey") !== FALSE) |
|
245 | + { |
|
178 | 246 | require_once(BB2_CORE . "/searchengine.inc.php"); |
179 | - if ($r = bb2_yahoo($package)) { |
|
180 | - if ($r == 1) return false; # whitelisted |
|
247 | + if ($r = bb2_yahoo($package)) |
|
248 | + { |
|
249 | + if ($r == 1) |
|
250 | + { |
|
251 | + return false; |
|
252 | + } |
|
253 | + # whitelisted |
|
181 | 254 | return $r; |
182 | 255 | } |
183 | 256 | return false; |
184 | - } elseif (stripos($ua, "Baidu") !== FALSE) { |
|
257 | + } |
|
258 | + elseif (stripos($ua, "Baidu") !== FALSE) |
|
259 | + { |
|
185 | 260 | require_once(BB2_CORE . "/searchengine.inc.php"); |
186 | - if ($r = bb2_baidu($package)) { |
|
187 | - if ($r == 1) return false; # whitelisted |
|
261 | + if ($r = bb2_baidu($package)) |
|
262 | + { |
|
263 | + if ($r == 1) |
|
264 | + { |
|
265 | + return false; |
|
266 | + } |
|
267 | + # whitelisted |
|
188 | 268 | return $r; |
189 | 269 | } |
190 | 270 | return false; |
191 | 271 | } |
192 | 272 | // MSIE checks |
193 | - if (stripos($ua, "; MSIE") !== FALSE) { |
|
273 | + if (stripos($ua, "; MSIE") !== FALSE) |
|
274 | + { |
|
194 | 275 | $package['is_browser'] = true; |
195 | 276 | require_once(BB2_CORE . "/browser.inc.php"); |
196 | - if (stripos($ua, "Opera") !== FALSE) { |
|
197 | - if ($r = bb2_opera($package)) return $r; |
|
198 | - } else { |
|
199 | - if ($r = bb2_msie($package)) return $r; |
|
277 | + if (stripos($ua, "Opera") !== FALSE) |
|
278 | + { |
|
279 | + if ($r = bb2_opera($package)) |
|
280 | + { |
|
281 | + return $r; |
|
282 | + } |
|
200 | 283 | } |
201 | - } elseif (stripos($ua, "Konqueror") !== FALSE) { |
|
284 | + else |
|
285 | + { |
|
286 | + if ($r = bb2_msie($package)) |
|
287 | + { |
|
288 | + return $r; |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + elseif (stripos($ua, "Konqueror") !== FALSE) |
|
293 | + { |
|
202 | 294 | $package['is_browser'] = true; |
203 | 295 | require_once(BB2_CORE . "/browser.inc.php"); |
204 | - if ($r = bb2_konqueror($package)) return $r; |
|
205 | - } elseif (stripos($ua, "Opera") !== FALSE) { |
|
296 | + if ($r = bb2_konqueror($package)) |
|
297 | + { |
|
298 | + return $r; |
|
299 | + } |
|
300 | + } |
|
301 | + elseif (stripos($ua, "Opera") !== FALSE) |
|
302 | + { |
|
206 | 303 | $package['is_browser'] = true; |
207 | 304 | require_once(BB2_CORE . "/browser.inc.php"); |
208 | - if ($r = bb2_opera($package)) return $r; |
|
209 | - } elseif (stripos($ua, "Safari") !== FALSE) { |
|
305 | + if ($r = bb2_opera($package)) |
|
306 | + { |
|
307 | + return $r; |
|
308 | + } |
|
309 | + } |
|
310 | + elseif (stripos($ua, "Safari") !== FALSE) |
|
311 | + { |
|
210 | 312 | $package['is_browser'] = true; |
211 | 313 | require_once(BB2_CORE . "/browser.inc.php"); |
212 | - if ($r = bb2_safari($package)) return $r; |
|
213 | - } elseif (stripos($ua, "Lynx") !== FALSE) { |
|
314 | + if ($r = bb2_safari($package)) |
|
315 | + { |
|
316 | + return $r; |
|
317 | + } |
|
318 | + } |
|
319 | + elseif (stripos($ua, "Lynx") !== FALSE) |
|
320 | + { |
|
214 | 321 | $package['is_browser'] = true; |
215 | 322 | require_once(BB2_CORE . "/browser.inc.php"); |
216 | - if ($r = bb2_lynx($package)) return $r; |
|
217 | - } elseif (stripos($ua, "MovableType") !== FALSE) { |
|
323 | + if ($r = bb2_lynx($package)) |
|
324 | + { |
|
325 | + return $r; |
|
326 | + } |
|
327 | + } |
|
328 | + elseif (stripos($ua, "MovableType") !== FALSE) |
|
329 | + { |
|
218 | 330 | require_once(BB2_CORE . "/movabletype.inc.php"); |
219 | - if ($r = bb2_movabletype($package)) return $r; |
|
220 | - } elseif (stripos($ua, "Mozilla") !== FALSE && stripos($ua, "Mozilla") == 0) { |
|
331 | + if ($r = bb2_movabletype($package)) |
|
332 | + { |
|
333 | + return $r; |
|
334 | + } |
|
335 | + } |
|
336 | + elseif (stripos($ua, "Mozilla") !== FALSE && stripos($ua, "Mozilla") == 0) |
|
337 | + { |
|
221 | 338 | $package['is_browser'] = true; |
222 | 339 | require_once(BB2_CORE . "/browser.inc.php"); |
223 | - if ($r = bb2_mozilla($package)) return $r; |
|
340 | + if ($r = bb2_mozilla($package)) |
|
341 | + { |
|
342 | + return $r; |
|
343 | + } |
|
224 | 344 | } |
225 | 345 | |
226 | 346 | // More intensive screening applies to POST requests |
227 | - if (!strcasecmp('POST', $package['request_method'])) { |
|
347 | + if (!strcasecmp('POST', $package['request_method'])) |
|
348 | + { |
|
228 | 349 | require_once(BB2_CORE . "/post.inc.php"); |
229 | - if ($r = bb2_post($settings, $package)) return $r; |
|
350 | + if ($r = bb2_post($settings, $package)) |
|
351 | + { |
|
352 | + return $r; |
|
353 | + } |
|
230 | 354 | } |
231 | 355 | } |
232 | 356 |
@@ -160,28 +160,28 @@ discard block |
||
160 | 160 | // Specific checks |
161 | 161 | @$ua = $package['user_agent']; |
162 | 162 | // Search engine checks come first |
163 | - if (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) { |
|
163 | + if (stripos($ua, "bingbot") !== false || stripos($ua, "msnbot") !== false || stripos($ua, "MS Search") !== false) { |
|
164 | 164 | require_once(BB2_CORE . "/searchengine.inc.php"); |
165 | 165 | if ($r = bb2_msnbot($package)) { |
166 | 166 | if ($r == 1) return false; # whitelisted |
167 | 167 | return $r; |
168 | 168 | } |
169 | 169 | return false; |
170 | - } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Web Preview") !== FALSE) { |
|
170 | + } elseif (stripos($ua, "Googlebot") !== false || stripos($ua, "Mediapartners-Google") !== false || stripos($ua, "Google Web Preview") !== false) { |
|
171 | 171 | require_once(BB2_CORE . "/searchengine.inc.php"); |
172 | 172 | if ($r = bb2_google($package)) { |
173 | 173 | if ($r == 1) return false; # whitelisted |
174 | 174 | return $r; |
175 | 175 | } |
176 | 176 | return false; |
177 | - } elseif (stripos($ua, "Yahoo! Slurp") !== FALSE || stripos($ua, "Yahoo! SearchMonkey") !== FALSE) { |
|
177 | + } elseif (stripos($ua, "Yahoo! Slurp") !== false || stripos($ua, "Yahoo! SearchMonkey") !== false) { |
|
178 | 178 | require_once(BB2_CORE . "/searchengine.inc.php"); |
179 | 179 | if ($r = bb2_yahoo($package)) { |
180 | 180 | if ($r == 1) return false; # whitelisted |
181 | 181 | return $r; |
182 | 182 | } |
183 | 183 | return false; |
184 | - } elseif (stripos($ua, "Baidu") !== FALSE) { |
|
184 | + } elseif (stripos($ua, "Baidu") !== false) { |
|
185 | 185 | require_once(BB2_CORE . "/searchengine.inc.php"); |
186 | 186 | if ($r = bb2_baidu($package)) { |
187 | 187 | if ($r == 1) return false; # whitelisted |
@@ -190,34 +190,34 @@ discard block |
||
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | // MSIE checks |
193 | - if (stripos($ua, "; MSIE") !== FALSE) { |
|
193 | + if (stripos($ua, "; MSIE") !== false) { |
|
194 | 194 | $package['is_browser'] = true; |
195 | 195 | require_once(BB2_CORE . "/browser.inc.php"); |
196 | - if (stripos($ua, "Opera") !== FALSE) { |
|
196 | + if (stripos($ua, "Opera") !== false) { |
|
197 | 197 | if ($r = bb2_opera($package)) return $r; |
198 | 198 | } else { |
199 | 199 | if ($r = bb2_msie($package)) return $r; |
200 | 200 | } |
201 | - } elseif (stripos($ua, "Konqueror") !== FALSE) { |
|
201 | + } elseif (stripos($ua, "Konqueror") !== false) { |
|
202 | 202 | $package['is_browser'] = true; |
203 | 203 | require_once(BB2_CORE . "/browser.inc.php"); |
204 | 204 | if ($r = bb2_konqueror($package)) return $r; |
205 | - } elseif (stripos($ua, "Opera") !== FALSE) { |
|
205 | + } elseif (stripos($ua, "Opera") !== false) { |
|
206 | 206 | $package['is_browser'] = true; |
207 | 207 | require_once(BB2_CORE . "/browser.inc.php"); |
208 | 208 | if ($r = bb2_opera($package)) return $r; |
209 | - } elseif (stripos($ua, "Safari") !== FALSE) { |
|
209 | + } elseif (stripos($ua, "Safari") !== false) { |
|
210 | 210 | $package['is_browser'] = true; |
211 | 211 | require_once(BB2_CORE . "/browser.inc.php"); |
212 | 212 | if ($r = bb2_safari($package)) return $r; |
213 | - } elseif (stripos($ua, "Lynx") !== FALSE) { |
|
213 | + } elseif (stripos($ua, "Lynx") !== false) { |
|
214 | 214 | $package['is_browser'] = true; |
215 | 215 | require_once(BB2_CORE . "/browser.inc.php"); |
216 | 216 | if ($r = bb2_lynx($package)) return $r; |
217 | - } elseif (stripos($ua, "MovableType") !== FALSE) { |
|
217 | + } elseif (stripos($ua, "MovableType") !== false) { |
|
218 | 218 | require_once(BB2_CORE . "/movabletype.inc.php"); |
219 | 219 | if ($r = bb2_movabletype($package)) return $r; |
220 | - } elseif (stripos($ua, "Mozilla") !== FALSE && stripos($ua, "Mozilla") == 0) { |
|
220 | + } elseif (stripos($ua, "Mozilla") !== false && stripos($ua, "Mozilla") == 0) { |
|
221 | 221 | $package['is_browser'] = true; |
222 | 222 | require_once(BB2_CORE . "/browser.inc.php"); |
223 | 223 | if ($r = bb2_mozilla($package)) return $r; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | require_once(BB2_CORE . "/functions.inc.php"); |
11 | 11 | |
12 | 12 | // Kill 'em all! |
13 | -function bb2_banned($settings, $package, $key, $previous_key=false) |
|
13 | +function bb2_banned($settings, $package, $key, $previous_key = false) |
|
14 | 14 | { |
15 | 15 | // Some spambots hit too hard. Slow them down a bit. |
16 | 16 | sleep(2); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | { |
73 | 73 | $unpacked = array(); |
74 | 74 | foreach ($value as $k => $v) { |
75 | - $i = $key. '[' . $k . ']'; |
|
75 | + $i = $key . '[' . $k . ']'; |
|
76 | 76 | if (is_array($v)) |
77 | 77 | $v = bb2_unpack_php_post_array($i, $v); |
78 | 78 | $unpacked[$i] = $v; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | $request_uri = $_SERVER["REQUEST_URI"]; |
111 | - if (!$request_uri) $request_uri = $_SERVER['SCRIPT_NAME']; # IIS |
|
111 | + if (!$request_uri) $request_uri = $_SERVER['SCRIPT_NAME']; # IIS |
|
112 | 112 | |
113 | 113 | if ($settings['reverse_proxy'] && $ip = bb2_reverse_proxy($settings, $headers_mixed)) { |
114 | 114 | $headers['X-Bad-Behavior-Remote-Address'] = $_SERVER['REMOTE_ADDR']; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | // Check the http:BL |
148 | 148 | require_once(BB2_CORE . "/blackhole.inc.php"); |
149 | 149 | if ($r = bb2_httpbl($settings, $package)) { |
150 | - if ($r == 1) return false; # whitelisted |
|
150 | + if ($r == 1) return false; # whitelisted |
|
151 | 151 | return $r; |
152 | 152 | } |
153 | 153 | |
@@ -163,28 +163,28 @@ discard block |
||
163 | 163 | if (stripos($ua, "bingbot") !== FALSE || stripos($ua, "msnbot") !== FALSE || stripos($ua, "MS Search") !== FALSE) { |
164 | 164 | require_once(BB2_CORE . "/searchengine.inc.php"); |
165 | 165 | if ($r = bb2_msnbot($package)) { |
166 | - if ($r == 1) return false; # whitelisted |
|
166 | + if ($r == 1) return false; # whitelisted |
|
167 | 167 | return $r; |
168 | 168 | } |
169 | 169 | return false; |
170 | 170 | } elseif (stripos($ua, "Googlebot") !== FALSE || stripos($ua, "Mediapartners-Google") !== FALSE || stripos($ua, "Google Web Preview") !== FALSE) { |
171 | 171 | require_once(BB2_CORE . "/searchengine.inc.php"); |
172 | 172 | if ($r = bb2_google($package)) { |
173 | - if ($r == 1) return false; # whitelisted |
|
173 | + if ($r == 1) return false; # whitelisted |
|
174 | 174 | return $r; |
175 | 175 | } |
176 | 176 | return false; |
177 | 177 | } elseif (stripos($ua, "Yahoo! Slurp") !== FALSE || stripos($ua, "Yahoo! SearchMonkey") !== FALSE) { |
178 | 178 | require_once(BB2_CORE . "/searchengine.inc.php"); |
179 | 179 | if ($r = bb2_yahoo($package)) { |
180 | - if ($r == 1) return false; # whitelisted |
|
180 | + if ($r == 1) return false; # whitelisted |
|
181 | 181 | return $r; |
182 | 182 | } |
183 | 183 | return false; |
184 | 184 | } elseif (stripos($ua, "Baidu") !== FALSE) { |
185 | 185 | require_once(BB2_CORE . "/searchengine.inc.php"); |
186 | 186 | if ($r = bb2_baidu($package)) { |
187 | - if ($r == 1) return false; # whitelisted |
|
187 | + if ($r == 1) return false; # whitelisted |
|
188 | 188 | return $r; |
189 | 189 | } |
190 | 190 | return false; |
@@ -1,4 +1,7 @@ discard block |
||
1 | -<?php if (!defined('BB2_CORE')) die('I said no cheating!'); |
|
1 | +<?php if (!defined('BB2_CORE')) |
|
2 | +{ |
|
3 | + die('I said no cheating!'); |
|
4 | +} |
|
2 | 5 | |
3 | 6 | require_once(BB2_CORE . "/roundtripdns.inc.php"); |
4 | 7 | |
@@ -6,8 +9,13 @@ discard block |
||
6 | 9 | |
7 | 10 | function bb2_google($package) |
8 | 11 | { |
9 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
10 | - if (match_cidr($package['ip'], array("66.249.64.0/19", "64.233.160.0/19", "72.14.192.0/18", "203.208.32.0/19", "74.125.0.0/16", "216.239.32.0/19", "209.85.128.0/17")) === FALSE) { |
|
12 | + if (@is_ipv6($package['ip'])) |
|
13 | + { |
|
14 | + return false; |
|
15 | + } |
|
16 | + # TODO |
|
17 | + if (match_cidr($package['ip'], array("66.249.64.0/19", "64.233.160.0/19", "72.14.192.0/18", "203.208.32.0/19", "74.125.0.0/16", "216.239.32.0/19", "209.85.128.0/17")) === FALSE) |
|
18 | + { |
|
11 | 19 | return false; # Soft fail, must pass other screening |
12 | 20 | #return "f1182195"; # Hard fail |
13 | 21 | } |
@@ -22,8 +30,13 @@ discard block |
||
22 | 30 | |
23 | 31 | function bb2_msnbot($package) |
24 | 32 | { |
25 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
26 | - if (match_cidr($package['ip'], array("207.46.0.0/16", "65.52.0.0/14", "207.68.128.0/18", "207.68.192.0/20", "64.4.0.0/18", "157.54.0.0/15", "157.60.0.0/16", "157.56.0.0/14", "131.253.21.0/24", "131.253.22.0/23", "131.253.24.0/21", "131.253.32.0/20", "40.76.0.0/14")) === FALSE) { |
|
33 | + if (@is_ipv6($package['ip'])) |
|
34 | + { |
|
35 | + return false; |
|
36 | + } |
|
37 | + # TODO |
|
38 | + if (match_cidr($package['ip'], array("207.46.0.0/16", "65.52.0.0/14", "207.68.128.0/18", "207.68.192.0/20", "64.4.0.0/18", "157.54.0.0/15", "157.60.0.0/16", "157.56.0.0/14", "131.253.21.0/24", "131.253.22.0/23", "131.253.24.0/21", "131.253.32.0/20", "40.76.0.0/14")) === FALSE) |
|
39 | + { |
|
27 | 40 | return false; # Soft fail, must pass other screening |
28 | 41 | #return "e4de0453"; # Hard fail |
29 | 42 | } |
@@ -38,8 +51,13 @@ discard block |
||
38 | 51 | |
39 | 52 | function bb2_yahoo($package) |
40 | 53 | { |
41 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
42 | - if (match_cidr($package['ip'], array("202.160.176.0/20", "67.195.0.0/16", "203.209.252.0/24", "72.30.0.0/16", "98.136.0.0/14", "74.6.0.0/16")) === FALSE) { |
|
54 | + if (@is_ipv6($package['ip'])) |
|
55 | + { |
|
56 | + return false; |
|
57 | + } |
|
58 | + # TODO |
|
59 | + if (match_cidr($package['ip'], array("202.160.176.0/20", "67.195.0.0/16", "203.209.252.0/24", "72.30.0.0/16", "98.136.0.0/14", "74.6.0.0/16")) === FALSE) |
|
60 | + { |
|
43 | 61 | return false; # Soft fail, must pass other screening |
44 | 62 | #return '71436a15'; # Hard fail |
45 | 63 | } |
@@ -54,8 +72,13 @@ discard block |
||
54 | 72 | |
55 | 73 | function bb2_baidu($package) |
56 | 74 | { |
57 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
58 | - if (match_cidr($package['ip'], array("119.63.192.0/21", "123.125.71.0/24", "180.76.0.0/16", "220.181.0.0/16")) === FALSE) { |
|
75 | + if (@is_ipv6($package['ip'])) |
|
76 | + { |
|
77 | + return false; |
|
78 | + } |
|
79 | + # TODO |
|
80 | + if (match_cidr($package['ip'], array("119.63.192.0/21", "123.125.71.0/24", "180.76.0.0/16", "220.181.0.0/16")) === FALSE) |
|
81 | + { |
|
59 | 82 | return false; # Soft fail, must pass other screening |
60 | 83 | } |
61 | 84 | return 1; # Real Baidu bot; bypass all other checks |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | function bb2_google($package) |
8 | 8 | { |
9 | 9 | if (@is_ipv6($package['ip'])) return false; # TODO |
10 | - if (match_cidr($package['ip'], array("66.249.64.0/19", "64.233.160.0/19", "72.14.192.0/18", "203.208.32.0/19", "74.125.0.0/16", "216.239.32.0/19", "209.85.128.0/17")) === FALSE) { |
|
10 | + if (match_cidr($package['ip'], array("66.249.64.0/19", "64.233.160.0/19", "72.14.192.0/18", "203.208.32.0/19", "74.125.0.0/16", "216.239.32.0/19", "209.85.128.0/17")) === false) { |
|
11 | 11 | return false; # Soft fail, must pass other screening |
12 | 12 | #return "f1182195"; # Hard fail |
13 | 13 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | function bb2_msnbot($package) |
24 | 24 | { |
25 | 25 | if (@is_ipv6($package['ip'])) return false; # TODO |
26 | - if (match_cidr($package['ip'], array("207.46.0.0/16", "65.52.0.0/14", "207.68.128.0/18", "207.68.192.0/20", "64.4.0.0/18", "157.54.0.0/15", "157.60.0.0/16", "157.56.0.0/14", "131.253.21.0/24", "131.253.22.0/23", "131.253.24.0/21", "131.253.32.0/20", "40.76.0.0/14")) === FALSE) { |
|
26 | + if (match_cidr($package['ip'], array("207.46.0.0/16", "65.52.0.0/14", "207.68.128.0/18", "207.68.192.0/20", "64.4.0.0/18", "157.54.0.0/15", "157.60.0.0/16", "157.56.0.0/14", "131.253.21.0/24", "131.253.22.0/23", "131.253.24.0/21", "131.253.32.0/20", "40.76.0.0/14")) === false) { |
|
27 | 27 | return false; # Soft fail, must pass other screening |
28 | 28 | #return "e4de0453"; # Hard fail |
29 | 29 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | function bb2_yahoo($package) |
40 | 40 | { |
41 | 41 | if (@is_ipv6($package['ip'])) return false; # TODO |
42 | - if (match_cidr($package['ip'], array("202.160.176.0/20", "67.195.0.0/16", "203.209.252.0/24", "72.30.0.0/16", "98.136.0.0/14", "74.6.0.0/16")) === FALSE) { |
|
42 | + if (match_cidr($package['ip'], array("202.160.176.0/20", "67.195.0.0/16", "203.209.252.0/24", "72.30.0.0/16", "98.136.0.0/14", "74.6.0.0/16")) === false) { |
|
43 | 43 | return false; # Soft fail, must pass other screening |
44 | 44 | #return '71436a15'; # Hard fail |
45 | 45 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | function bb2_baidu($package) |
56 | 56 | { |
57 | 57 | if (@is_ipv6($package['ip'])) return false; # TODO |
58 | - if (match_cidr($package['ip'], array("119.63.192.0/21", "123.125.71.0/24", "180.76.0.0/16", "220.181.0.0/16")) === FALSE) { |
|
58 | + if (match_cidr($package['ip'], array("119.63.192.0/21", "123.125.71.0/24", "180.76.0.0/16", "220.181.0.0/16")) === false) { |
|
59 | 59 | return false; # Soft fail, must pass other screening |
60 | 60 | } |
61 | 61 | return 1; # Real Baidu bot; bypass all other checks |
@@ -6,57 +6,57 @@ |
||
6 | 6 | |
7 | 7 | function bb2_google($package) |
8 | 8 | { |
9 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
9 | + if (@is_ipv6($package['ip'])) return false; # TODO |
|
10 | 10 | if (match_cidr($package['ip'], array("66.249.64.0/19", "64.233.160.0/19", "72.14.192.0/18", "203.208.32.0/19", "74.125.0.0/16", "216.239.32.0/19", "209.85.128.0/17")) === FALSE) { |
11 | - return false; # Soft fail, must pass other screening |
|
11 | + return false; # Soft fail, must pass other screening |
|
12 | 12 | #return "f1182195"; # Hard fail |
13 | 13 | } |
14 | 14 | # Disabled due to http://bugs.php.net/bug.php?id=53092 |
15 | 15 | # if (!bb2_roundtripdns($package['ip'], "googlebot.com")) { |
16 | 16 | # return "f1182195"; |
17 | 17 | # } |
18 | - return 1; # Real Googlebot; bypass all other checks |
|
18 | + return 1; # Real Googlebot; bypass all other checks |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // Analyze user agents claiming to be msnbot |
22 | 22 | |
23 | 23 | function bb2_msnbot($package) |
24 | 24 | { |
25 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
25 | + if (@is_ipv6($package['ip'])) return false; # TODO |
|
26 | 26 | if (match_cidr($package['ip'], array("207.46.0.0/16", "65.52.0.0/14", "207.68.128.0/18", "207.68.192.0/20", "64.4.0.0/18", "157.54.0.0/15", "157.60.0.0/16", "157.56.0.0/14", "131.253.21.0/24", "131.253.22.0/23", "131.253.24.0/21", "131.253.32.0/20", "40.76.0.0/14")) === FALSE) { |
27 | - return false; # Soft fail, must pass other screening |
|
27 | + return false; # Soft fail, must pass other screening |
|
28 | 28 | #return "e4de0453"; # Hard fail |
29 | 29 | } |
30 | 30 | # Disabled due to http://bugs.php.net/bug.php?id=53092 |
31 | 31 | # if (!bb2_roundtripdns($package['ip'], "msn.com")) { |
32 | 32 | # return "e4de0453"; |
33 | 33 | # } |
34 | - return 1; # Real msnbot; bypass all other checks |
|
34 | + return 1; # Real msnbot; bypass all other checks |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // Analyze user agents claiming to be Yahoo! |
38 | 38 | |
39 | 39 | function bb2_yahoo($package) |
40 | 40 | { |
41 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
41 | + if (@is_ipv6($package['ip'])) return false; # TODO |
|
42 | 42 | if (match_cidr($package['ip'], array("202.160.176.0/20", "67.195.0.0/16", "203.209.252.0/24", "72.30.0.0/16", "98.136.0.0/14", "74.6.0.0/16")) === FALSE) { |
43 | - return false; # Soft fail, must pass other screening |
|
43 | + return false; # Soft fail, must pass other screening |
|
44 | 44 | #return '71436a15'; # Hard fail |
45 | 45 | } |
46 | 46 | # Disabled due to http://bugs.php.net/bug.php?id=53092 |
47 | 47 | # if (!bb2_roundtripdns($package['ip'], "crawl.yahoo.net")) { |
48 | 48 | # return "71436a15"; |
49 | 49 | # } |
50 | - return 1; # Real Yahoo bot; bypass all other checks |
|
50 | + return 1; # Real Yahoo bot; bypass all other checks |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Analyze user agents claiming to be Baidu |
54 | 54 | |
55 | 55 | function bb2_baidu($package) |
56 | 56 | { |
57 | - if (@is_ipv6($package['ip'])) return false; # TODO |
|
57 | + if (@is_ipv6($package['ip'])) return false; # TODO |
|
58 | 58 | if (match_cidr($package['ip'], array("119.63.192.0/21", "123.125.71.0/24", "180.76.0.0/16", "220.181.0.0/16")) === FALSE) { |
59 | - return false; # Soft fail, must pass other screening |
|
59 | + return false; # Soft fail, must pass other screening |
|
60 | 60 | } |
61 | - return 1; # Real Baidu bot; bypass all other checks |
|
61 | + return 1; # Real Baidu bot; bypass all other checks |
|
62 | 62 | } |
@@ -1,8 +1,12 @@ discard block |
||
1 | -<?php if (!defined('BB2_CORE')) die('I said no cheating!'); |
|
1 | +<?php if (!defined('BB2_CORE')) |
|
2 | +{ |
|
3 | + die('I said no cheating!'); |
|
4 | +} |
|
2 | 5 | |
3 | 6 | // Defines the responses which Bad Behavior might return. |
4 | 7 | |
5 | -function bb2_get_response($key) { |
|
8 | +function bb2_get_response($key) |
|
9 | +{ |
|
6 | 10 | $bb2_responses = array( |
7 | 11 | '00000000' => array('response' => 200, 'explanation' => '', 'log' => 'Permitted'), |
8 | 12 | '136673cd' => array('response' => 403, 'explanation' => 'Your Internet Protocol address is listed on a blacklist of addresses involved in malicious or illegal activity. See the listing below for more details on specific blacklists and removal procedures.', 'log' => 'IP address found on external blacklist'), |
@@ -47,6 +51,9 @@ discard block |
||
47 | 51 | 'f9f2b8b9' => array('response' => 403, 'explanation' => 'You do not have permission to access this server. This may be caused by a malfunctioning proxy server or browser privacy software.', 'log' => 'A User-Agent is required but none was provided.'), |
48 | 52 | ); |
49 | 53 | |
50 | - if (array_key_exists($key, $bb2_responses)) return $bb2_responses[$key]; |
|
54 | + if (array_key_exists($key, $bb2_responses)) |
|
55 | + { |
|
56 | + return $bb2_responses[$key]; |
|
57 | + } |
|
51 | 58 | return array('00000000'); |
52 | 59 | } |
@@ -1,15 +1,20 @@ discard block |
||
1 | -<?php if (!defined('BB2_CORE')) die('I said no cheating!'); |
|
1 | +<?php if (!defined('BB2_CORE')) |
|
2 | +{ |
|
3 | + die('I said no cheating!'); |
|
4 | +} |
|
2 | 5 | |
3 | 6 | // Specialized screening for trackbacks |
4 | 7 | function bb2_trackback($package) |
5 | 8 | { |
6 | 9 | // Web browsers don't send trackbacks |
7 | - if ($package['is_browser']) { |
|
10 | + if ($package['is_browser']) |
|
11 | + { |
|
8 | 12 | return 'f0dcb3fd'; |
9 | 13 | } |
10 | 14 | |
11 | 15 | // Proxy servers don't send trackbacks either |
12 | - if (array_key_exists('Via', $package['headers_mixed']) || array_key_exists('Max-Forwards', $package['headers_mixed']) || array_key_exists('X-Forwarded-For', $package['headers_mixed']) || array_key_exists('Client-Ip', $package['headers_mixed'])) { |
|
16 | + if (array_key_exists('Via', $package['headers_mixed']) || array_key_exists('Max-Forwards', $package['headers_mixed']) || array_key_exists('X-Forwarded-For', $package['headers_mixed']) || array_key_exists('Client-Ip', $package['headers_mixed'])) |
|
17 | + { |
|
13 | 18 | return 'd60b87c7'; |
14 | 19 | } |
15 | 20 | |
@@ -17,8 +22,10 @@ discard block |
||
17 | 22 | // Real ones do not contain Accept:, and have a charset defined |
18 | 23 | // Real WP trackbacks may contain Accept: depending on the HTTP |
19 | 24 | // transport being used by the sending host |
20 | - if (strpos($package['headers_mixed']['User-Agent'], "WordPress/") !== FALSE) { |
|
21 | - if (strpos($package['headers_mixed']['Content-Type'], "charset=") === FALSE) { |
|
25 | + if (strpos($package['headers_mixed']['User-Agent'], "WordPress/") !== FALSE) |
|
26 | + { |
|
27 | + if (strpos($package['headers_mixed']['Content-Type'], "charset=") === FALSE) |
|
28 | + { |
|
22 | 29 | return 'e3990b47'; |
23 | 30 | } |
24 | 31 | } |
@@ -33,34 +40,41 @@ discard block |
||
33 | 40 | // if ($r = bb2_blackhole($package)) return $r; |
34 | 41 | |
35 | 42 | // MovableType needs specialized screening |
36 | - if (stripos($package['headers_mixed']['User-Agent'], "MovableType") !== FALSE) { |
|
37 | - if (strcmp($package['headers_mixed']['Range'], "bytes=0-99999")) { |
|
43 | + if (stripos($package['headers_mixed']['User-Agent'], "MovableType") !== FALSE) |
|
44 | + { |
|
45 | + if (strcmp($package['headers_mixed']['Range'], "bytes=0-99999")) |
|
46 | + { |
|
38 | 47 | return "7d12528e"; |
39 | 48 | } |
40 | 49 | } |
41 | 50 | |
42 | 51 | // Trackbacks need special screening |
43 | 52 | $request_entity = $package['request_entity']; |
44 | - if (isset($request_entity['title']) && isset($request_entity['url']) && isset($request_entity['blog_name'])) { |
|
53 | + if (isset($request_entity['title']) && isset($request_entity['url']) && isset($request_entity['blog_name'])) |
|
54 | + { |
|
45 | 55 | return bb2_trackback($package); |
46 | 56 | } |
47 | 57 | |
48 | 58 | // Catch a few completely broken spambots |
49 | - foreach ($request_entity as $key => $value) { |
|
59 | + foreach ($request_entity as $key => $value) |
|
60 | + { |
|
50 | 61 | $pos = strpos($key, " document.write"); |
51 | - if ($pos !== FALSE) { |
|
62 | + if ($pos !== FALSE) |
|
63 | + { |
|
52 | 64 | return "dfd9b1ad"; |
53 | 65 | } |
54 | 66 | } |
55 | 67 | |
56 | 68 | // If Referer exists, it should refer to a page on our site |
57 | - if (!$settings['offsite_forms'] && array_key_exists('Referer', $package['headers_mixed'])) { |
|
69 | + if (!$settings['offsite_forms'] && array_key_exists('Referer', $package['headers_mixed'])) |
|
70 | + { |
|
58 | 71 | $url = parse_url($package['headers_mixed']['Referer']); |
59 | 72 | $url['host'] = preg_replace('|^www\.|', '', $url['host']); |
60 | 73 | $host = preg_replace('|^www\.|', '', $package['headers_mixed']['Host']); |
61 | 74 | # Strip port |
62 | 75 | $host = preg_replace('|:\d+$|', '', $host); |
63 | - if (strcasecmp($host, $url['host'])) { |
|
76 | + if (strcasecmp($host, $url['host'])) |
|
77 | + { |
|
64 | 78 | return "cd361abb"; |
65 | 79 | } |
66 | 80 | } |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | // Real ones do not contain Accept:, and have a charset defined |
18 | 18 | // Real WP trackbacks may contain Accept: depending on the HTTP |
19 | 19 | // transport being used by the sending host |
20 | - if (strpos($package['headers_mixed']['User-Agent'], "WordPress/") !== FALSE) { |
|
21 | - if (strpos($package['headers_mixed']['Content-Type'], "charset=") === FALSE) { |
|
20 | + if (strpos($package['headers_mixed']['User-Agent'], "WordPress/") !== false) { |
|
21 | + if (strpos($package['headers_mixed']['Content-Type'], "charset=") === false) { |
|
22 | 22 | return 'e3990b47'; |
23 | 23 | } |
24 | 24 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | // if ($r = bb2_blackhole($package)) return $r; |
34 | 34 | |
35 | 35 | // MovableType needs specialized screening |
36 | - if (stripos($package['headers_mixed']['User-Agent'], "MovableType") !== FALSE) { |
|
36 | + if (stripos($package['headers_mixed']['User-Agent'], "MovableType") !== false) { |
|
37 | 37 | if (strcmp($package['headers_mixed']['Range'], "bytes=0-99999")) { |
38 | 38 | return "7d12528e"; |
39 | 39 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | // Catch a few completely broken spambots |
49 | 49 | foreach ($request_entity as $key => $value) { |
50 | 50 | $pos = strpos($key, " document.write"); |
51 | - if ($pos !== FALSE) { |
|
51 | + if ($pos !== false) { |
|
52 | 52 | return "dfd9b1ad"; |
53 | 53 | } |
54 | 54 | } |