@@ -894,8 +894,9 @@ |
||
894 | 894 | } |
895 | 895 | |
896 | 896 | if ($db['dblink_slave'] !== false) { |
897 | - if (mysql_select_db($opt['db']['placeholder']['db'], $db['dblink_slave']) == false) |
|
898 | - sql_error(); |
|
897 | + if (mysql_select_db($opt['db']['placeholder']['db'], $db['dblink_slave']) == false) { |
|
898 | + sql_error(); |
|
899 | + } |
|
899 | 900 | |
900 | 901 | mysql_query("SET NAMES '" . mysql_real_escape_string($opt['charset']['mysql'], $db['dblink_slave']) . "'", $db['dblink_slave']); |
901 | 902 |
@@ -29,13 +29,18 @@ |
||
29 | 29 | require_once('replicate_common.inc.php'); |
30 | 30 | |
31 | 31 | $since = $request->get_parameter('since'); |
32 | - if ($since === null) throw new ParamMissing('since'); |
|
33 | - if ((int)$since != $since) throw new InvalidParam('since'); |
|
32 | + if ($since === null) { |
|
33 | + throw new ParamMissing('since'); |
|
34 | + } |
|
35 | + if ((int)$since != $since) { |
|
36 | + throw new InvalidParam('since'); |
|
37 | + } |
|
34 | 38 | |
35 | 39 | # Let's check the $since parameter. |
36 | 40 | |
37 | - if (!ReplicateCommon::check_since_param($since)) |
|
38 | - throw new BadRequest("The 'since' parameter is too old. You must update your database more frequently."); |
|
41 | + if (!ReplicateCommon::check_since_param($since)) { |
|
42 | + throw new BadRequest("The 'since' parameter is too old. You must update your database more frequently."); |
|
43 | + } |
|
39 | 44 | |
40 | 45 | # Select a best chunk for the given $since, get the chunk from the database (or cache). |
41 | 46 |
@@ -40,8 +40,9 @@ discard block |
||
40 | 40 | if ($cache == null) |
41 | 41 | { |
42 | 42 | $cache = Db::select_value("select min(id) from okapi_clog"); |
43 | - if ($cache === null) |
|
44 | - $cache = 1; |
|
43 | + if ($cache === null) { |
|
44 | + $cache = 1; |
|
45 | + } |
|
45 | 46 | $cache -= 1; |
46 | 47 | } |
47 | 48 | return $cache; |
@@ -54,19 +55,22 @@ discard block |
||
54 | 55 | */ |
55 | 56 | private static function get_diff($old, $new) |
56 | 57 | { |
57 | - if (!$old) |
|
58 | - return $new; |
|
58 | + if (!$old) { |
|
59 | + return $new; |
|
60 | + } |
|
59 | 61 | $changed_keys = array(); |
60 | 62 | foreach ($new as $key => $value) |
61 | 63 | { |
62 | - if (!array_key_exists($key, $old)) |
|
63 | - $changed_keys[] = $key; |
|
64 | - elseif ($old[$key] != $new[$key]) |
|
65 | - $changed_keys[] = $key; |
|
64 | + if (!array_key_exists($key, $old)) { |
|
65 | + $changed_keys[] = $key; |
|
66 | + } elseif ($old[$key] != $new[$key]) { |
|
67 | + $changed_keys[] = $key; |
|
68 | + } |
|
66 | 69 | } |
67 | 70 | $changed = array(); |
68 | - foreach ($changed_keys as $key) |
|
69 | - $changed[$key] = $new[$key]; |
|
71 | + foreach ($changed_keys as $key) { |
|
72 | + $changed[$key] = $new[$key]; |
|
73 | + } |
|
70 | 74 | return $changed; |
71 | 75 | } |
72 | 76 | |
@@ -75,8 +79,9 @@ discard block |
||
75 | 79 | { |
76 | 80 | $now = Db::select_value("select date_add(now(), interval -1 minute)"); # See issue 157. |
77 | 81 | $last_update = Okapi::get_var('last_clog_update'); |
78 | - if ($last_update === null) |
|
79 | - $last_update = Db::select_value("select date_add(now(), interval -1 day)"); |
|
82 | + if ($last_update === null) { |
|
83 | + $last_update = Db::select_value("select date_add(now(), interval -1 day)"); |
|
84 | + } |
|
80 | 85 | |
81 | 86 | # Usually this will be fast. But, for example, if admin changes ALL the |
82 | 87 | # caches, this will take forever. But we still want it to finish properly |
@@ -117,8 +122,9 @@ discard block |
||
117 | 122 | where okapi_syncbase > '".Db::escape_string($last_update)."' |
118 | 123 | limit $offset, 10000; |
119 | 124 | "); |
120 | - if (count($log_uuids) == 0) |
|
121 | - break; |
|
125 | + if (count($log_uuids) == 0) { |
|
126 | + break; |
|
127 | + } |
|
122 | 128 | $offset += 10000; |
123 | 129 | $log_uuid_groups = Okapi::make_groups($log_uuids, 100); |
124 | 130 | unset($log_uuids); |
@@ -202,8 +208,9 @@ discard block |
||
202 | 208 | ); |
203 | 209 | foreach ($entries as $entry) |
204 | 210 | { |
205 | - if ($entry['object_type'] != 'geocache') |
|
206 | - continue; |
|
211 | + if ($entry['object_type'] != 'geocache') { |
|
212 | + continue; |
|
213 | + } |
|
207 | 214 | $cache_code = $entry['object_key']['code']; |
208 | 215 | |
209 | 216 | if (($entry['change_type'] == 'replace') && ($geocache_ignored_fields != null)) { |
@@ -227,8 +234,10 @@ discard block |
||
227 | 234 | # We will story the first and the last entry in the $two_examples |
228 | 235 | # vars which is to be emailed to OKAPI developers. |
229 | 236 | |
230 | - if (count($two_examples) == 0) |
|
231 | - $two_examples[0] = $entry; /* The first entry */ |
|
237 | + if (count($two_examples) == 0) { |
|
238 | + $two_examples[0] = $entry; |
|
239 | + } |
|
240 | + /* The first entry */ |
|
232 | 241 | $two_examples[1] = $entry; /* The last entry */ |
233 | 242 | |
234 | 243 | Db::execute(" |
@@ -279,10 +288,12 @@ discard block |
||
279 | 288 | { |
280 | 289 | $cache_keys1 = array(); |
281 | 290 | $cache_keys2 = array(); |
282 | - foreach ($key_values as $key) |
|
283 | - $cache_keys1[] = 'clog#'.$object_type.'#'.$key; |
|
284 | - foreach ($key_values as $key) |
|
285 | - $cache_keys2[] = 'clogmd5#'.$object_type.'#'.$key; |
|
291 | + foreach ($key_values as $key) { |
|
292 | + $cache_keys1[] = 'clog#'.$object_type.'#'.$key; |
|
293 | + } |
|
294 | + foreach ($key_values as $key) { |
|
295 | + $cache_keys2[] = 'clogmd5#'.$object_type.'#'.$key; |
|
296 | + } |
|
286 | 297 | $cached_values1 = Cache::get_many($cache_keys1); |
287 | 298 | $cached_values2 = Cache::get_many($cache_keys2); |
288 | 299 | if (!$fulldump_mode) |
@@ -342,8 +353,7 @@ discard block |
||
342 | 353 | $cached_values2['clogmd5#'.$object_type.'#'.$key] = $current_md5; |
343 | 354 | $cached_values1['clog#'.$object_type.'#'.$key] = $object; |
344 | 355 | } |
345 | - } |
|
346 | - else |
|
356 | + } else |
|
347 | 357 | { |
348 | 358 | # Currently, the object does not exist. |
349 | 359 | if ($use_cache && ($cached_values1['clog#'.$object_type.'#'.$key] === false)) |
@@ -368,16 +378,16 @@ discard block |
||
368 | 378 | if ($fulldump_mode) |
369 | 379 | { |
370 | 380 | return $entries; |
371 | - } |
|
372 | - else |
|
381 | + } else |
|
373 | 382 | { |
374 | 383 | # Save the entries to the clog table. |
375 | 384 | |
376 | 385 | if (count($entries) > 0) |
377 | 386 | { |
378 | 387 | $data_values = array(); |
379 | - foreach ($entries as $entry) |
|
380 | - $data_values[] = gzdeflate(serialize($entry)); |
|
388 | + foreach ($entries as $entry) { |
|
389 | + $data_values[] = gzdeflate(serialize($entry)); |
|
390 | + } |
|
381 | 391 | Db::execute(" |
382 | 392 | insert into okapi_clog (data) |
383 | 393 | values ('".implode("'),('", array_map('\okapi\Db::escape_string', $data_values))."'); |
@@ -403,10 +413,14 @@ discard block |
||
403 | 413 | $first_id = Db::select_value(" |
404 | 414 | select id from okapi_clog where id > '".Db::escape_string($since)."' limit 1 |
405 | 415 | "); |
406 | - if ($first_id === null) |
|
407 | - return true; # okay, since points to the newest revision |
|
408 | - if ($first_id == $since + 1) |
|
409 | - return true; # okay, revision $since + 1 is present |
|
416 | + if ($first_id === null) { |
|
417 | + return true; |
|
418 | + } |
|
419 | + # okay, since points to the newest revision |
|
420 | + if ($first_id == $since + 1) { |
|
421 | + return true; |
|
422 | + } |
|
423 | + # okay, revision $since + 1 is present |
|
410 | 424 | |
411 | 425 | # If we're here, then this means that $first_id > $since + 1. |
412 | 426 | # Revision $since + 1 is already deleted, $since must be too old! |
@@ -432,10 +446,11 @@ discard block |
||
432 | 446 | # user wants), then we'll give him 80. If user wants less than half of what we |
433 | 447 | # have (ex. 30), then we'll give him only his 30. |
434 | 448 | |
435 | - if ($current_revision - $since > $since - $last_chunk_cut) |
|
436 | - return array($last_chunk_cut + 1, $current_revision); |
|
437 | - else |
|
438 | - return array($since + 1, $current_revision); |
|
449 | + if ($current_revision - $since > $since - $last_chunk_cut) { |
|
450 | + return array($last_chunk_cut + 1, $current_revision); |
|
451 | + } else { |
|
452 | + return array($since + 1, $current_revision); |
|
453 | + } |
|
439 | 454 | } |
440 | 455 | $prev_chunk_cut = $since - ($since % self::$chunk_size); |
441 | 456 | return array($prev_chunk_cut + 1, $prev_chunk_cut + self::$chunk_size); |
@@ -446,10 +461,12 @@ discard block |
||
446 | 461 | */ |
447 | 462 | public static function get_chunk($from, $to) |
448 | 463 | { |
449 | - if ($to < $from) |
|
450 | - return array(); |
|
451 | - if ($to - $from > self::$chunk_size) |
|
452 | - throw new Exception("You should not get chunksize bigger than ".self::$chunk_size." entries at one time."); |
|
464 | + if ($to < $from) { |
|
465 | + return array(); |
|
466 | + } |
|
467 | + if ($to - $from > self::$chunk_size) { |
|
468 | + throw new Exception("You should not get chunksize bigger than ".self::$chunk_size." entries at one time."); |
|
469 | + } |
|
453 | 470 | |
454 | 471 | # Check if we already have this chunk in cache. |
455 | 472 | |
@@ -475,10 +492,11 @@ discard block |
||
475 | 492 | # be ever accessed after the next revision appears, so there is not point |
476 | 493 | # in storing them that long. |
477 | 494 | |
478 | - if (($from % self::$chunk_size === 0) && ($to % self::$chunk_size === 0)) |
|
479 | - $timeout = 10 * 86400; |
|
480 | - else |
|
481 | - $timeout = 86400; |
|
495 | + if (($from % self::$chunk_size === 0) && ($to % self::$chunk_size === 0)) { |
|
496 | + $timeout = 10 * 86400; |
|
497 | + } else { |
|
498 | + $timeout = 86400; |
|
499 | + } |
|
482 | 500 | Cache::set($cache_key, $chunk, $timeout); |
483 | 501 | } |
484 | 502 | |
@@ -518,9 +536,10 @@ discard block |
||
518 | 536 | $entries = self::generate_changelog_entries('services/caches/geocaches', 'geocache', 'cache_codes', |
519 | 537 | 'code', $cache_codes, self::$logged_cache_fields, true, false); |
520 | 538 | $filtered = array(); |
521 | - foreach ($entries as $entry) |
|
522 | - if ($entry['change_type'] == 'replace') |
|
539 | + foreach ($entries as $entry) { |
|
540 | + if ($entry['change_type'] == 'replace') |
|
523 | 541 | $filtered[] = $entry; |
542 | + } |
|
524 | 543 | unset($entries); |
525 | 544 | file_put_contents("$dir/$basename.json", json_encode($filtered)); |
526 | 545 | unset($filtered); |
@@ -541,8 +560,9 @@ discard block |
||
541 | 560 | order by uuid |
542 | 561 | limit $offset, 10000 |
543 | 562 | "); |
544 | - if (count($log_uuids) == 0) |
|
545 | - break; |
|
563 | + if (count($log_uuids) == 0) { |
|
564 | + break; |
|
565 | + } |
|
546 | 566 | $offset += 10000; |
547 | 567 | $log_uuid_groups = Okapi::make_groups($log_uuids, 500); |
548 | 568 | unset($log_uuids); |
@@ -553,9 +573,10 @@ discard block |
||
553 | 573 | $entries = self::generate_changelog_entries('services/logs/entries', 'log', 'log_uuids', |
554 | 574 | 'uuid', $log_uuids, self::$logged_log_entry_fields, true, false); |
555 | 575 | $filtered = array(); |
556 | - foreach ($entries as $entry) |
|
557 | - if ($entry['change_type'] == 'replace') |
|
576 | + foreach ($entries as $entry) { |
|
577 | + if ($entry['change_type'] == 'replace') |
|
558 | 578 | $filtered[] = $entry; |
579 | + } |
|
559 | 580 | unset($entries); |
560 | 581 | file_put_contents("$dir/$basename.json", json_encode($filtered)); |
561 | 582 | unset($filtered); |
@@ -581,8 +602,9 @@ discard block |
||
581 | 602 | # Compute uncompressed size. |
582 | 603 | |
583 | 604 | $size = filesize("$dir/index.json"); |
584 | - foreach ($json_files as $filename) |
|
585 | - $size += filesize("$dir/$filename"); |
|
605 | + foreach ($json_files as $filename) { |
|
606 | + $size += filesize("$dir/$filename"); |
|
607 | + } |
|
586 | 608 | |
587 | 609 | # Create JSON archive. We use tar options: -j for bzip2, -z for gzip |
588 | 610 | # (bzip2 is MUCH slower). |
@@ -49,9 +49,10 @@ discard block |
||
49 | 49 | require_once('replicate_common.inc.php'); |
50 | 50 | |
51 | 51 | $data = Cache::get("last_fulldump"); |
52 | - if ($data == null) |
|
53 | - throw new BadRequest("No fulldump found. Try again later. If this doesn't help ". |
|
52 | + if ($data == null) { |
|
53 | + throw new BadRequest("No fulldump found. Try again later. If this doesn't help ". |
|
54 | 54 | "contact site administrator and/or OKAPI developers."); |
55 | + } |
|
55 | 56 | |
56 | 57 | # Check consumer's quota |
57 | 58 | |
@@ -59,14 +60,15 @@ discard block |
||
59 | 60 | if ($please != 'true') |
60 | 61 | { |
61 | 62 | $not_good = 3 < self::count_calls($request->consumer->key, 30); |
62 | - if ($not_good) |
|
63 | - throw new BadRequest("Consumer's monthly quota exceeded. Try later or call with '&pleeaase=true'."); |
|
64 | - } |
|
65 | - else |
|
63 | + if ($not_good) { |
|
64 | + throw new BadRequest("Consumer's monthly quota exceeded. Try later or call with '&pleeaase=true'."); |
|
65 | + } |
|
66 | + } else |
|
66 | 67 | { |
67 | 68 | $not_good = 5 < self::count_calls($request->consumer->key, 1); |
68 | - if ($not_good) |
|
69 | - throw new BadRequest("No more please. Seriously, dude..."); |
|
69 | + if ($not_good) { |
|
70 | + throw new BadRequest("No more please. Seriously, dude..."); |
|
71 | + } |
|
70 | 72 | } |
71 | 73 | |
72 | 74 | $response = new OkapiHttpResponse(); |
@@ -64,19 +64,23 @@ discard block |
||
64 | 64 | # (and if it was, was it empty). |
65 | 65 | |
66 | 66 | $status = self::get_tile_status($zoom, $x, $y); |
67 | - if ($status === null) # Not yet computed. |
|
67 | + if ($status === null) { |
|
68 | + # Not yet computed. |
|
68 | 69 | { |
69 | 70 | # Note, that computing the tile does not involve taking any |
70 | 71 | # search parameters. |
71 | 72 | |
72 | 73 | $status = self::compute_tile($zoom, $x, $y); |
73 | 74 | } |
75 | + } |
|
74 | 76 | |
75 | - if ($status === 1) # Computed and empty. |
|
77 | + if ($status === 1) { |
|
78 | + # Computed and empty. |
|
76 | 79 | { |
77 | 80 | # This tile was already computed and it is empty. |
78 | 81 | return null; |
79 | 82 | } |
83 | + } |
|
80 | 84 | |
81 | 85 | # If we got here, then the tile is computed and not empty (status 2). |
82 | 86 | |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | # For low-level tiles, this can be expensive. |
122 | 126 | |
123 | 127 | $status = self::get_tile_status($zoom, $x, $y); |
124 | - if ($status !== null) |
|
125 | - return $status; |
|
128 | + if ($status !== null) { |
|
129 | + return $status; |
|
130 | + } |
|
126 | 131 | |
127 | 132 | if ($zoom === 0) |
128 | 133 | { |
@@ -174,8 +179,7 @@ discard block |
||
174 | 179 | "); |
175 | 180 | } |
176 | 181 | $status = 2; |
177 | - } |
|
178 | - else |
|
182 | + } else |
|
179 | 183 | { |
180 | 184 | # We will use the parent tile to compute the contents of this tile. |
181 | 185 | |
@@ -184,19 +188,23 @@ discard block |
||
184 | 188 | $parent_y = $y >> 1; |
185 | 189 | |
186 | 190 | $status = self::get_tile_status($parent_zoom, $parent_x, $parent_y); |
187 | - if ($status === null) # Not computed. |
|
191 | + if ($status === null) { |
|
192 | + # Not computed. |
|
188 | 193 | { |
189 | 194 | $time_started = microtime(true); |
195 | + } |
|
190 | 196 | $status = self::compute_tile($parent_zoom, $parent_x, $parent_y); |
191 | 197 | } |
192 | 198 | |
193 | - if ($status === 1) # Computed and empty. |
|
199 | + if ($status === 1) { |
|
200 | + # Computed and empty. |
|
194 | 201 | { |
195 | 202 | # No need to check. |
196 | 203 | } |
197 | 204 | else # Computed, not empty. |
198 | 205 | { |
199 | 206 | $scale = 8 + 21 - $zoom; |
207 | + } |
|
200 | 208 | $parentcenter_z21x = (($parent_x << 1) | 1) << $scale; |
201 | 209 | $parentcenter_z21y = (($parent_y << 1) | 1) << $scale; |
202 | 210 | $margin = 1 << ($scale - 2); |
@@ -209,14 +217,20 @@ discard block |
||
209 | 217 | # |1 2| |
210 | 218 | # |3 4| |
211 | 219 | |
212 | - if ($x & 1) # 2 or 4 |
|
220 | + if ($x & 1) { |
|
221 | + # 2 or 4 |
|
213 | 222 | $left_z21x = $parentcenter_z21x - $margin; |
214 | - else # 1 or 3 |
|
223 | + } else { |
|
224 | + # 1 or 3 |
|
215 | 225 | $right_z21x = $parentcenter_z21x + $margin; |
216 | - if ($y & 1) # 3 or 4 |
|
226 | + } |
|
227 | + if ($y & 1) { |
|
228 | + # 3 or 4 |
|
217 | 229 | $top_z21y = $parentcenter_z21y - $margin; |
218 | - else # 1 or 2 |
|
230 | + } else { |
|
231 | + # 1 or 2 |
|
219 | 232 | $bottom_z21y = $parentcenter_z21y + $margin; |
233 | + } |
|
220 | 234 | |
221 | 235 | # Cache the result. |
222 | 236 | |
@@ -256,10 +270,11 @@ discard block |
||
256 | 270 | and y = '".Db::escape_string($y)."' |
257 | 271 | limit 1; |
258 | 272 | "); |
259 | - if ($test) |
|
260 | - $status = 2; |
|
261 | - else |
|
262 | - $status = 1; |
|
273 | + if ($test) { |
|
274 | + $status = 2; |
|
275 | + } else { |
|
276 | + $status = 1; |
|
277 | + } |
|
263 | 278 | } |
264 | 279 | } |
265 | 280 | |
@@ -294,12 +309,15 @@ discard block |
||
294 | 309 | return false; |
295 | 310 | } |
296 | 311 | $flags = 0; |
297 | - if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3)) |
|
298 | - $flags |= self::$FLAG_STAR; |
|
299 | - if ($cache['trackables_count'] > 0) |
|
300 | - $flags |= self::$FLAG_HAS_TRACKABLES; |
|
301 | - if ($cache['founds'] == 0) |
|
302 | - $flags |= self::$FLAG_NOT_YET_FOUND; |
|
312 | + if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3)) { |
|
313 | + $flags |= self::$FLAG_STAR; |
|
314 | + } |
|
315 | + if ($cache['trackables_count'] > 0) { |
|
316 | + $flags |= self::$FLAG_HAS_TRACKABLES; |
|
317 | + } |
|
318 | + if ($cache['founds'] == 0) { |
|
319 | + $flags |= self::$FLAG_NOT_YET_FOUND; |
|
320 | + } |
|
303 | 321 | return array($cache['internal_id'], $z21x, $z21y, Okapi::cache_status_name2id($cache['status']), |
304 | 322 | Okapi::cache_type_name2id($cache['type']), $cache['rating'], $flags, |
305 | 323 | self::compute_name_crc($cache['name'])); |
@@ -58,11 +58,13 @@ discard block |
||
58 | 58 | private static function require_uint($request, $name, $min_value = 0) |
59 | 59 | { |
60 | 60 | $val = $request->get_parameter($name); |
61 | - if ($val === null) |
|
62 | - throw new ParamMissing($name); |
|
61 | + if ($val === null) { |
|
62 | + throw new ParamMissing($name); |
|
63 | + } |
|
63 | 64 | $ret = intval($val); |
64 | - if ($ret < 0 || ("$ret" !== $val)) |
|
65 | - throw new InvalidParam($name, "Expecting non-negative integer."); |
|
65 | + if ($ret < 0 || ("$ret" !== $val)) { |
|
66 | + throw new InvalidParam($name, "Expecting non-negative integer."); |
|
67 | + } |
|
66 | 68 | return $ret; |
67 | 69 | } |
68 | 70 | |
@@ -84,14 +86,17 @@ discard block |
||
84 | 86 | # zoom, x, y - required tile-specific parameters. |
85 | 87 | |
86 | 88 | $zoom = self::require_uint($request, 'z'); |
87 | - if ($zoom > 21) |
|
88 | - throw new InvalidParam('z', "Maximum value for this parameter is 21."); |
|
89 | + if ($zoom > 21) { |
|
90 | + throw new InvalidParam('z', "Maximum value for this parameter is 21."); |
|
91 | + } |
|
89 | 92 | $x = self::require_uint($request, 'x'); |
90 | 93 | $y = self::require_uint($request, 'y'); |
91 | - if ($x >= 1<<$zoom) |
|
92 | - throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
93 | - if ($y >= 1<<$zoom) |
|
94 | - throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
94 | + if ($x >= 1<<$zoom) { |
|
95 | + throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
96 | + } |
|
97 | + if ($y >= 1<<$zoom) { |
|
98 | + throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
99 | + } |
|
95 | 100 | |
96 | 101 | # Now, we will create a search set (or use one previously created). |
97 | 102 | # Instead of creating a new OkapiInternalRequest object, we will pass |
@@ -114,8 +119,9 @@ discard block |
||
114 | 119 | $rows = array(); |
115 | 120 | if ($rs !== null) |
116 | 121 | { |
117 | - while ($row = Db::fetch_row($rs)) |
|
118 | - $rows[] = $row; |
|
122 | + while ($row = Db::fetch_row($rs)) { |
|
123 | + $rows[] = $row; |
|
124 | + } |
|
119 | 125 | unset($row); |
120 | 126 | } |
121 | 127 | OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointA", null, |
@@ -142,8 +148,9 @@ discard block |
||
142 | 148 | where user_id = '".Db::escape_string($request->token->user_id)."' |
143 | 149 | "); |
144 | 150 | $user['ignored'] = array(); |
145 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
146 | - $user['ignored'][$cache_id] = true; |
|
151 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
152 | + $user['ignored'][$cache_id] = true; |
|
153 | + } |
|
147 | 154 | |
148 | 155 | # Found caches. |
149 | 156 | |
@@ -156,8 +163,9 @@ discard block |
||
156 | 163 | and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
157 | 164 | "); |
158 | 165 | $user['found'] = array(); |
159 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
160 | - $user['found'][$cache_id] = true; |
|
166 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
167 | + $user['found'][$cache_id] = true; |
|
168 | + } |
|
161 | 169 | |
162 | 170 | # Own caches. |
163 | 171 | |
@@ -167,8 +175,9 @@ discard block |
||
167 | 175 | where user_id = '".Db::escape_string($request->token->user_id)."' |
168 | 176 | "); |
169 | 177 | $user['own'] = array(); |
170 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
171 | - $user['own'][$cache_id] = true; |
|
178 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
179 | + $user['own'][$cache_id] = true; |
|
180 | + } |
|
172 | 181 | |
173 | 182 | Cache::set($cache_key, $user, 30); |
174 | 183 | } |
@@ -181,10 +190,14 @@ discard block |
||
181 | 190 | # to be drawn as found) and the "own" flag (to indicate that |
182 | 191 | # the current user is the owner). |
183 | 192 | |
184 | - if (isset($user['found'][$row_ref[0]])) |
|
185 | - $row_ref[6] |= TileTree::$FLAG_FOUND; # $row[6] is "flags" |
|
186 | - if (isset($user['own'][$row_ref[0]])) |
|
187 | - $row_ref[6] |= TileTree::$FLAG_OWN; # $row[6] is "flags" |
|
193 | + if (isset($user['found'][$row_ref[0]])) { |
|
194 | + $row_ref[6] |= TileTree::$FLAG_FOUND; |
|
195 | + } |
|
196 | + # $row[6] is "flags" |
|
197 | + if (isset($user['own'][$row_ref[0]])) { |
|
198 | + $row_ref[6] |= TileTree::$FLAG_OWN; |
|
199 | + } |
|
200 | + # $row[6] is "flags" |
|
188 | 201 | } |
189 | 202 | } |
190 | 203 |
@@ -74,23 +74,28 @@ discard block |
||
74 | 74 | { |
75 | 75 | # Preprocess the rows. |
76 | 76 | |
77 | - if ($this->zoom >= 5) |
|
78 | - $this->decide_which_get_captions(); |
|
77 | + if ($this->zoom >= 5) { |
|
78 | + $this->decide_which_get_captions(); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | # Make a background. |
81 | 82 | |
82 | 83 | $this->im = imagecreatetruecolor(256, 256); |
83 | 84 | imagealphablending($this->im, false); |
84 | - if ($this->zoom >= 13) $opacity = 15; |
|
85 | - elseif ($this->zoom <= 12) $opacity = max(0, $this->zoom * 2 - 14); |
|
85 | + if ($this->zoom >= 13) { |
|
86 | + $opacity = 15; |
|
87 | + } elseif ($this->zoom <= 12) { |
|
88 | + $opacity = max(0, $this->zoom * 2 - 14); |
|
89 | + } |
|
86 | 90 | $transparent = imagecolorallocatealpha($this->im, 0, 0, 0, 127 - $opacity); |
87 | 91 | imagefilledrectangle($this->im, 0, 0, 256, 256, $transparent); |
88 | 92 | imagealphablending($this->im, true); |
89 | 93 | |
90 | 94 | # Draw the caches. |
91 | 95 | |
92 | - foreach ($this->rows_ref as &$row_ref) |
|
93 | - $this->draw_cache($row_ref); |
|
96 | + foreach ($this->rows_ref as &$row_ref) { |
|
97 | + $this->draw_cache($row_ref); |
|
98 | + } |
|
94 | 99 | |
95 | 100 | # Return the result. |
96 | 101 | |
@@ -118,13 +123,13 @@ discard block |
||
118 | 123 | $cache_key = "tilesrc/".Okapi::$git_revision."/".self::$VERSION."/".$key; |
119 | 124 | $gd2_path = self::$USE_STATIC_IMAGE_CACHE |
120 | 125 | ? FileCache::get_file_path($cache_key) : null; |
121 | - if ($gd2_path === null) |
|
122 | - throw new Exception("Not in cache"); |
|
126 | + if ($gd2_path === null) { |
|
127 | + throw new Exception("Not in cache"); |
|
128 | + } |
|
123 | 129 | # File cache hit. GD2 files are much faster to read than PNGs. |
124 | 130 | # This can throw an Exception (see bug#160). |
125 | 131 | $locmem_cache[$key] = imagecreatefromgd2($gd2_path); |
126 | - } |
|
127 | - catch (Exception $e) |
|
132 | + } catch (Exception $e) |
|
128 | 133 | { |
129 | 134 | # Miss again (or error decoding). Read the image from PNG. |
130 | 135 | |
@@ -132,12 +137,15 @@ discard block |
||
132 | 137 | |
133 | 138 | # Apply all wanted effects. |
134 | 139 | |
135 | - if ($opacity != 1) |
|
136 | - self::change_opacity($locmem_cache[$key], $opacity); |
|
137 | - if ($contrast != 0) |
|
138 | - imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast); |
|
139 | - if ($brightness != 0) |
|
140 | - imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness); |
|
140 | + if ($opacity != 1) { |
|
141 | + self::change_opacity($locmem_cache[$key], $opacity); |
|
142 | + } |
|
143 | + if ($contrast != 0) { |
|
144 | + imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast); |
|
145 | + } |
|
146 | + if ($brightness != 0) { |
|
147 | + imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness); |
|
148 | + } |
|
141 | 149 | if (($r != 0) || ($g != 0) || ($b != 0)) |
142 | 150 | { |
143 | 151 | imagefilter($locmem_cache[$key], IMG_FILTER_GRAYSCALE); |
@@ -182,12 +190,13 @@ discard block |
||
182 | 190 | { |
183 | 191 | $capt = ($cache_struct[6] & TileTree::$FLAG_DRAW_CAPTION); |
184 | 192 | |
185 | - if (($this->zoom <= 8) && (!$capt)) |
|
186 | - $this->draw_cache_tiny($cache_struct); |
|
187 | - elseif (($this->zoom <= 13) && (!$capt)) |
|
188 | - $this->draw_cache_medium($cache_struct); |
|
189 | - else |
|
190 | - $this->draw_cache_large($cache_struct); |
|
193 | + if (($this->zoom <= 8) && (!$capt)) { |
|
194 | + $this->draw_cache_tiny($cache_struct); |
|
195 | + } elseif (($this->zoom <= 13) && (!$capt)) { |
|
196 | + $this->draw_cache_medium($cache_struct); |
|
197 | + } else { |
|
198 | + $this->draw_cache_large($cache_struct); |
|
199 | + } |
|
191 | 200 | |
192 | 201 | # Put caption (this flag is set only when there is plenty of space around). |
193 | 202 | |
@@ -241,8 +250,9 @@ discard block |
||
241 | 250 | $markercenter_x = 12; |
242 | 251 | $markercenter_y = 12; |
243 | 252 | |
244 | - if ($count > 1) |
|
245 | - imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
|
253 | + if ($count > 1) { |
|
254 | + imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
|
255 | + } |
|
246 | 256 | imagecopy($this->im, $outer_marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
247 | 257 | |
248 | 258 | # Put the inner marker (indicates the type). |
@@ -304,8 +314,9 @@ discard block |
||
304 | 314 | $nextBonus = ""; |
305 | 315 | for ($i=0; ($i<count($words)) || (mb_strlen($nextBonus)>0); $i++) { |
306 | 316 | $word = isset($words[$i])?$words[$i]:""; |
307 | - if (mb_strlen($nextBonus) > 0) |
|
308 | - $word = $nextBonus." ".$word; |
|
317 | + if (mb_strlen($nextBonus) > 0) { |
|
318 | + $word = $nextBonus." ".$word; |
|
319 | + } |
|
309 | 320 | $nextBonus = ""; |
310 | 321 | while (true) { |
311 | 322 | $bbox = imagettfbbox($size, 0, $font, $line.$word); |
@@ -324,8 +335,9 @@ discard block |
||
324 | 335 | continue; |
325 | 336 | } |
326 | 337 | } |
327 | - if (mb_strlen($line) > 0) |
|
328 | - $lines[] = trim($line); |
|
338 | + if (mb_strlen($line) > 0) { |
|
339 | + $lines[] = trim($line); |
|
340 | + } |
|
329 | 341 | return implode("\n", $lines); |
330 | 342 | } |
331 | 343 | |
@@ -389,9 +401,12 @@ discard block |
||
389 | 401 | # Draw an outline. |
390 | 402 | |
391 | 403 | $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80); |
392 | - for ($x=0; $x<=12; $x+=3) |
|
393 | - for ($y=$size-3; $y<=$size+9; $y+=3) |
|
394 | - $drawer($x, $y, $outline_color); |
|
404 | + for ($x=0; $x<=12; $x+=3) { |
|
405 | + for ($y=$size-3; |
|
406 | + } |
|
407 | + $y<=$size+9; $y+=3) { |
|
408 | + $drawer($x, $y, $outline_color); |
|
409 | + } |
|
395 | 410 | |
396 | 411 | # Add a slight shadow effect (on top of the outline). |
397 | 412 | |
@@ -426,10 +441,11 @@ discard block |
||
426 | 441 | $found = $flags & TileTree::$FLAG_FOUND; |
427 | 442 | $own = $flags & TileTree::$FLAG_OWN; |
428 | 443 | $new = $flags & TileTree::$FLAG_NEW; |
429 | - if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION))) |
|
430 | - $a = .35; |
|
431 | - else |
|
432 | - $a = 1; |
|
444 | + if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION))) { |
|
445 | + $a = .35; |
|
446 | + } else { |
|
447 | + $a = 1; |
|
448 | + } |
|
433 | 449 | |
434 | 450 | # Put the marker (indicates the type). |
435 | 451 | |
@@ -445,11 +461,12 @@ discard block |
||
445 | 461 | { |
446 | 462 | imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
447 | 463 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
448 | - } |
|
449 | - elseif ($status == 1) # don't put the marker for unavailable caches (X only) |
|
464 | + } elseif ($status == 1) { |
|
465 | + # don't put the marker for unavailable caches (X only) |
|
450 | 466 | { |
451 | 467 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
452 | 468 | } |
469 | + } |
|
453 | 470 | |
454 | 471 | # If the cache is unavailable, mark it with X. |
455 | 472 | |
@@ -485,16 +502,14 @@ discard block |
||
485 | 502 | |
486 | 503 | $overlay = self::get_image("medium_overlay_own"); |
487 | 504 | imagecopy($this->im, $overlay, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
488 | - } |
|
489 | - elseif ($found) |
|
505 | + } elseif ($found) |
|
490 | 506 | { |
491 | 507 | # Mark found caches with V. |
492 | 508 | |
493 | 509 | $icon = self::get_image("found", 0.7*$a); |
494 | 510 | imagecopy($this->im, $icon, $px - ($center_x - $markercenter_x) - 7, |
495 | 511 | $py - ($center_y - $markercenter_y) - 9, 0, 0, 16, 16); |
496 | - } |
|
497 | - elseif ($new) |
|
512 | + } elseif ($new) |
|
498 | 513 | { |
499 | 514 | # Mark new caches with additional overlay. |
500 | 515 | |
@@ -546,8 +561,7 @@ discard block |
||
546 | 561 | { |
547 | 562 | imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
548 | 563 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
549 | - } |
|
550 | - elseif ($status == 1) |
|
564 | + } elseif ($status == 1) |
|
551 | 565 | { |
552 | 566 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
553 | 567 | } |
@@ -577,25 +591,33 @@ discard block |
||
577 | 591 | # This is efficient and yields acceptable results. |
578 | 592 | |
579 | 593 | $matrix = array(); |
580 | - for ($i=0; $i<12; $i++) |
|
581 | - $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
|
594 | + for ($i=0; $i<12; $i++) { |
|
595 | + $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
|
596 | + } |
|
582 | 597 | |
583 | 598 | foreach ($this->rows_ref as &$row_ref) |
584 | 599 | { |
585 | 600 | $mx = ($row_ref[1] + 64) >> 5; |
586 | 601 | $my = ($row_ref[2] + 64) >> 5; |
587 | - if (($mx >= 12) || ($my >= 12)) continue; |
|
588 | - if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) # 8 is count |
|
589 | - $matrix[$mx][$my] = $row_ref[0]; # 0 is cache_id |
|
590 | - else |
|
591 | - $matrix[$mx][$my] = -1; |
|
602 | + if (($mx >= 12) || ($my >= 12)) { |
|
603 | + continue; |
|
604 | + } |
|
605 | + if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) { |
|
606 | + # 8 is count |
|
607 | + $matrix[$mx][$my] = $row_ref[0]; |
|
608 | + } |
|
609 | + # 0 is cache_id |
|
610 | + else { |
|
611 | + $matrix[$mx][$my] = -1; |
|
612 | + } |
|
592 | 613 | } |
593 | 614 | $selected_cache_ids = array(); |
594 | 615 | for ($mx=1; $mx<11; $mx++) |
595 | 616 | { |
596 | 617 | for ($my=1; $my<11; $my++) |
597 | 618 | { |
598 | - if ($matrix[$mx][$my] > 0) # cache_id |
|
619 | + if ($matrix[$mx][$my] > 0) { |
|
620 | + # cache_id |
|
599 | 621 | { |
600 | 622 | # Check all adjacent squares. |
601 | 623 | |
@@ -610,12 +632,14 @@ discard block |
||
610 | 632 | ) |
611 | 633 | $selected_cache_ids[] = $matrix[$mx][$my]; |
612 | 634 | } |
635 | + } |
|
613 | 636 | } |
614 | 637 | } |
615 | 638 | |
616 | - foreach ($this->rows_ref as &$row_ref) |
|
617 | - if (in_array($row_ref[0], $selected_cache_ids)) |
|
639 | + foreach ($this->rows_ref as &$row_ref) { |
|
640 | + if (in_array($row_ref[0], $selected_cache_ids)) |
|
618 | 641 | $row_ref[6] |= TileTree::$FLAG_DRAW_CAPTION; |
642 | + } |
|
619 | 643 | } |
620 | 644 | |
621 | 645 | } |
622 | 646 | \ No newline at end of file |
@@ -33,10 +33,11 @@ discard block |
||
33 | 33 | { |
34 | 34 | if ($c['object_type'] == 'geocache') |
35 | 35 | { |
36 | - if ($c['change_type'] == 'replace') |
|
37 | - self::handle_geocache_replace($c); |
|
38 | - else |
|
39 | - self::handle_geocache_delete($c); |
|
36 | + if ($c['change_type'] == 'replace') { |
|
37 | + self::handle_geocache_replace($c); |
|
38 | + } else { |
|
39 | + self::handle_geocache_delete($c); |
|
40 | + } |
|
40 | 41 | } |
41 | 42 | } |
42 | 43 | } |
@@ -95,19 +96,18 @@ discard block |
||
95 | 96 | # Aaah, a new geocache! How nice... ;) |
96 | 97 | |
97 | 98 | self::add_geocache_to_cached_tiles($theirs); |
98 | - } |
|
99 | - elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) # z21x & z21y fields |
|
99 | + } elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) { |
|
100 | + # z21x & z21y fields |
|
100 | 101 | { |
101 | 102 | # Location changed. |
102 | 103 | |
103 | 104 | self::remove_geocache_from_cached_tiles($ours[0]); |
104 | - self::add_geocache_to_cached_tiles($theirs); |
|
105 | 105 | } |
106 | - elseif ($ours != $theirs) |
|
106 | + self::add_geocache_to_cached_tiles($theirs); |
|
107 | + } elseif ($ours != $theirs) |
|
107 | 108 | { |
108 | 109 | self::update_geocache_attributes_in_cached_tiles($theirs); |
109 | - } |
|
110 | - else |
|
110 | + } else |
|
111 | 111 | { |
112 | 112 | # No need to update anything. This is very common (i.e. when the |
113 | 113 | # cache was simply found, not actually changed). Replicate module generates |
@@ -154,10 +154,13 @@ discard block |
||
154 | 154 | # go with the simple approach and check all 1+8 bordering tiles. |
155 | 155 | |
156 | 156 | $tiles_in_this_region = array(); |
157 | - for ($x=$ex-1; $x<=$ex+1; $x++) |
|
158 | - for ($y=$ey-1; $y<=$ey+1; $y++) |
|
159 | - if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
157 | + for ($x=$ex-1; $x<=$ex+1; $x++) { |
|
158 | + for ($y=$ey-1; |
|
159 | + } |
|
160 | + $y<=$ey+1; $y++) { |
|
161 | + if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
160 | 162 | $tiles_in_this_region[] = array($x, $y); |
163 | + } |
|
161 | 164 | |
162 | 165 | foreach ($tiles_in_this_region as $coords) |
163 | 166 | { |
@@ -171,14 +174,18 @@ discard block |
||
171 | 174 | $top_z21y = ($y << $scale) - $margin; |
172 | 175 | $bottom_z21y = (($y + 1) << $scale) + $margin; |
173 | 176 | |
174 | - if ($z21x < $left_z21x) |
|
175 | - continue; |
|
176 | - if ($z21x > $right_z21x) |
|
177 | - continue; |
|
178 | - if ($z21y < $top_z21y) |
|
179 | - continue; |
|
180 | - if ($z21y > $bottom_z21y) |
|
181 | - continue; |
|
177 | + if ($z21x < $left_z21x) { |
|
178 | + continue; |
|
179 | + } |
|
180 | + if ($z21x > $right_z21x) { |
|
181 | + continue; |
|
182 | + } |
|
183 | + if ($z21y < $top_z21y) { |
|
184 | + continue; |
|
185 | + } |
|
186 | + if ($z21y > $bottom_z21y) { |
|
187 | + continue; |
|
188 | + } |
|
182 | 189 | |
183 | 190 | # We found a match. Store it for later. |
184 | 191 |
@@ -40,33 +40,42 @@ discard block |
||
40 | 40 | public static function call(OkapiRequest $request) |
41 | 41 | { |
42 | 42 | $cache_codes = $request->get_parameter('cache_codes'); |
43 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
43 | + if ($cache_codes === null) { |
|
44 | + throw new ParamMissing('cache_codes'); |
|
45 | + } |
|
44 | 46 | if ($cache_codes === "") |
45 | 47 | { |
46 | 48 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
47 | 49 | # All of the queries below have to be ready for $cache_codes to be empty! |
48 | 50 | $cache_codes = array(); |
51 | + } else { |
|
52 | + $cache_codes = explode("|", $cache_codes); |
|
49 | 53 | } |
50 | - else |
|
51 | - $cache_codes = explode("|", $cache_codes); |
|
52 | 54 | |
53 | - if ((count($cache_codes) > 500) && (!$request->skip_limits)) |
|
54 | - throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
55 | + if ((count($cache_codes) > 500) && (!$request->skip_limits)) { |
|
56 | + throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
55 | 57 | "caches is 500. You provided ".count($cache_codes)." cache codes."); |
56 | - if (count($cache_codes) != count(array_unique($cache_codes))) |
|
57 | - throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
58 | + } |
|
59 | + if (count($cache_codes) != count(array_unique($cache_codes))) { |
|
60 | + throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
61 | + } |
|
58 | 62 | |
59 | 63 | $langpref = $request->get_parameter('langpref'); |
60 | - if (!$langpref) $langpref = "en"; |
|
64 | + if (!$langpref) { |
|
65 | + $langpref = "en"; |
|
66 | + } |
|
61 | 67 | $langpref .= "|".Settings::get('SITELANG'); |
62 | 68 | $langpref = explode("|", $langpref); |
63 | 69 | |
64 | 70 | $fields = $request->get_parameter('fields'); |
65 | - if (!$fields) $fields = "code|name|location|type|status"; |
|
71 | + if (!$fields) { |
|
72 | + $fields = "code|name|location|type|status"; |
|
73 | + } |
|
66 | 74 | $fields = explode("|", $fields); |
67 | - foreach ($fields as $field) |
|
68 | - if (!in_array($field, self::$valid_field_names)) |
|
75 | + foreach ($fields as $field) { |
|
76 | + if (!in_array($field, self::$valid_field_names)) |
|
69 | 77 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
78 | + } |
|
70 | 79 | |
71 | 80 | # Some fields need to be temporarily included whenever the "description" |
72 | 81 | # or "attribution_note" field are included. That's a little ugly, but |
@@ -94,60 +103,77 @@ discard block |
||
94 | 103 | } |
95 | 104 | |
96 | 105 | $attribution_append = $request->get_parameter('attribution_append'); |
97 | - if (!$attribution_append) $attribution_append = 'full'; |
|
98 | - if (!in_array($attribution_append, array('none', 'static', 'full'))) |
|
99 | - throw new InvalidParam('attribution_append'); |
|
106 | + if (!$attribution_append) { |
|
107 | + $attribution_append = 'full'; |
|
108 | + } |
|
109 | + if (!in_array($attribution_append, array('none', 'static', 'full'))) { |
|
110 | + throw new InvalidParam('attribution_append'); |
|
111 | + } |
|
100 | 112 | |
101 | 113 | $log_fields = $request->get_parameter('log_fields'); |
102 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call |
|
114 | + if (!$log_fields) { |
|
115 | + $log_fields = "uuid|date|user|type|comment"; |
|
116 | + } |
|
117 | + // validation is done on call |
|
103 | 118 | |
104 | 119 | $user_uuid = $request->get_parameter('user_uuid'); |
105 | 120 | if ($user_uuid != null) |
106 | 121 | { |
107 | 122 | $user_id = Db::select_value("select user_id from user where uuid='".Db::escape_string($user_uuid)."'"); |
108 | - if ($user_id == null) |
|
109 | - throw new InvalidParam('user_uuid', "User not found."); |
|
110 | - if (($request->token != null) && ($request->token->user_id != $user_id)) |
|
111 | - throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
123 | + if ($user_id == null) { |
|
124 | + throw new InvalidParam('user_uuid', "User not found."); |
|
125 | + } |
|
126 | + if (($request->token != null) && ($request->token->user_id != $user_id)) { |
|
127 | + throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
128 | + } |
|
129 | + } elseif (($user_uuid == null) && ($request->token != null)) { |
|
130 | + $user_id = $request->token->user_id; |
|
131 | + } else { |
|
132 | + $user_id = null; |
|
112 | 133 | } |
113 | - elseif (($user_uuid == null) && ($request->token != null)) |
|
114 | - $user_id = $request->token->user_id; |
|
115 | - else |
|
116 | - $user_id = null; |
|
117 | 134 | |
118 | 135 | $lpc = $request->get_parameter('lpc'); |
119 | - if ($lpc === null) $lpc = 10; |
|
120 | - if ($lpc == 'all') |
|
121 | - $lpc = null; |
|
122 | - else |
|
136 | + if ($lpc === null) { |
|
137 | + $lpc = 10; |
|
138 | + } |
|
139 | + if ($lpc == 'all') { |
|
140 | + $lpc = null; |
|
141 | + } else |
|
123 | 142 | { |
124 | - if (!is_numeric($lpc)) |
|
125 | - throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
143 | + if (!is_numeric($lpc)) { |
|
144 | + throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
145 | + } |
|
126 | 146 | $lpc = intval($lpc); |
127 | - if ($lpc < 0) |
|
128 | - throw new InvalidParam('lpc', "Must be a positive value."); |
|
147 | + if ($lpc < 0) { |
|
148 | + throw new InvalidParam('lpc', "Must be a positive value."); |
|
149 | + } |
|
129 | 150 | } |
130 | 151 | |
131 | 152 | if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields) |
132 | 153 | || in_array('bearing3', $fields)) |
133 | 154 | { |
134 | 155 | $tmp = $request->get_parameter('my_location'); |
135 | - if (!$tmp) |
|
136 | - throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
156 | + if (!$tmp) { |
|
157 | + throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
158 | + } |
|
137 | 159 | $parts = explode('|', $tmp); |
138 | - if (count($parts) != 2) |
|
139 | - throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
160 | + if (count($parts) != 2) { |
|
161 | + throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
162 | + } |
|
140 | 163 | foreach ($parts as &$part_ref) |
141 | 164 | { |
142 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
143 | - throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
165 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
166 | + throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
167 | + } |
|
144 | 168 | $part_ref = floatval($part_ref); |
145 | 169 | } |
146 | 170 | list($center_lat, $center_lon) = $parts; |
147 | - if ($center_lat > 90 || $center_lat < -90) |
|
148 | - throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
149 | - if ($center_lon > 180 || $center_lon < -180) |
|
150 | - throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
171 | + if ($center_lat > 90 || $center_lat < -90) { |
|
172 | + throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
173 | + } |
|
174 | + if ($center_lon > 180 || $center_lon < -180) { |
|
175 | + throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
176 | + } |
|
151 | 177 | } |
152 | 178 | |
153 | 179 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -181,8 +207,7 @@ discard block |
||
181 | 207 | wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
182 | 208 | and status in (1,2,3) |
183 | 209 | "); |
184 | - } |
|
185 | - elseif (Settings::get('OC_BRANCH') == 'oc.pl') |
|
210 | + } elseif (Settings::get('OC_BRANCH') == 'oc.pl') |
|
186 | 211 | { |
187 | 212 | # PL branch: |
188 | 213 | # - Caches have ratings. |
@@ -231,10 +256,11 @@ discard block |
||
231 | 256 | $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc']; |
232 | 257 | // OC software allows entering anything here, and that's what users do. |
233 | 258 | // We do a formal verification so that only a valid GC code is returned: |
234 | - if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) |
|
235 | - $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
236 | - else |
|
237 | - $entry['gc_code'] = null; |
|
259 | + if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) { |
|
260 | + $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
261 | + } else { |
|
262 | + $entry['gc_code'] = null; |
|
263 | + } |
|
238 | 264 | unset($wp_gc); |
239 | 265 | break; |
240 | 266 | case 'name': $entry['name'] = $row['name']; break; |
@@ -312,12 +338,19 @@ discard block |
||
312 | 338 | $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break; |
313 | 339 | break; |
314 | 340 | case 'rating': |
315 | - if ($row['votes'] < 3) $entry['rating'] = null; |
|
316 | - elseif ($row['score'] >= 2.2) $entry['rating'] = 5.0; |
|
317 | - elseif ($row['score'] >= 1.4) $entry['rating'] = 4.0; |
|
318 | - elseif ($row['score'] >= 0.1) $entry['rating'] = 3.0; |
|
319 | - elseif ($row['score'] >= -1.0) $entry['rating'] = 2.0; |
|
320 | - else $entry['rating'] = 1.0; |
|
341 | + if ($row['votes'] < 3) { |
|
342 | + $entry['rating'] = null; |
|
343 | + } elseif ($row['score'] >= 2.2) { |
|
344 | + $entry['rating'] = 5.0; |
|
345 | + } elseif ($row['score'] >= 1.4) { |
|
346 | + $entry['rating'] = 4.0; |
|
347 | + } elseif ($row['score'] >= 0.1) { |
|
348 | + $entry['rating'] = 3.0; |
|
349 | + } elseif ($row['score'] >= -1.0) { |
|
350 | + $entry['rating'] = 2.0; |
|
351 | + } else { |
|
352 | + $entry['rating'] = 1.0; |
|
353 | + } |
|
321 | 354 | break; |
322 | 355 | case 'rating_votes': $entry['rating_votes'] = $row['votes'] + 0; break; |
323 | 356 | case 'recommendations': $entry['recommendations'] = $row['topratings'] + 0; break; |
@@ -352,8 +385,9 @@ discard block |
||
352 | 385 | } |
353 | 386 | } |
354 | 387 | $results[$row['wp_oc']] = $entry; |
355 | - if ($row['listing_outdated'] > 0) |
|
356 | - $outdated_listings[] = $row['wp_oc']; |
|
388 | + if ($row['listing_outdated'] > 0) { |
|
389 | + $outdated_listings[] = $row['wp_oc']; |
|
390 | + } |
|
357 | 391 | } |
358 | 392 | Db::free_result($rs); |
359 | 393 | |
@@ -367,8 +401,9 @@ discard block |
||
367 | 401 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."') |
368 | 402 | "); |
369 | 403 | $tmp = array(); |
370 | - while ($row = Db::fetch_assoc($rs)) |
|
371 | - $tmp[$row['user_id']] = $row; |
|
404 | + while ($row = Db::fetch_assoc($rs)) { |
|
405 | + $tmp[$row['user_id']] = $row; |
|
406 | + } |
|
372 | 407 | foreach ($results as $cache_code => &$result_ref) |
373 | 408 | { |
374 | 409 | $row = $tmp[$owner_ids[$cache_code]]; |
@@ -384,8 +419,9 @@ discard block |
||
384 | 419 | |
385 | 420 | if (in_array('is_found', $fields)) |
386 | 421 | { |
387 | - if ($user_id == null) |
|
388 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
422 | + if ($user_id == null) { |
|
423 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
424 | + } |
|
389 | 425 | $tmp = Db::select_column(" |
390 | 426 | select c.wp_oc |
391 | 427 | from |
@@ -401,18 +437,21 @@ discard block |
||
401 | 437 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
402 | 438 | "); |
403 | 439 | $tmp2 = array(); |
404 | - foreach ($tmp as $cache_code) |
|
405 | - $tmp2[$cache_code] = true; |
|
406 | - foreach ($results as $cache_code => &$result_ref) |
|
407 | - $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
440 | + foreach ($tmp as $cache_code) { |
|
441 | + $tmp2[$cache_code] = true; |
|
442 | + } |
|
443 | + foreach ($results as $cache_code => &$result_ref) { |
|
444 | + $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
445 | + } |
|
408 | 446 | } |
409 | 447 | |
410 | 448 | # is_not_found |
411 | 449 | |
412 | 450 | if (in_array('is_not_found', $fields)) |
413 | 451 | { |
414 | - if ($user_id == null) |
|
415 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
452 | + if ($user_id == null) { |
|
453 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
454 | + } |
|
416 | 455 | $tmp = Db::select_column(" |
417 | 456 | select c.wp_oc |
418 | 457 | from |
@@ -425,18 +464,21 @@ discard block |
||
425 | 464 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
426 | 465 | "); |
427 | 466 | $tmp2 = array(); |
428 | - foreach ($tmp as $cache_code) |
|
429 | - $tmp2[$cache_code] = true; |
|
430 | - foreach ($results as $cache_code => &$result_ref) |
|
431 | - $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
467 | + foreach ($tmp as $cache_code) { |
|
468 | + $tmp2[$cache_code] = true; |
|
469 | + } |
|
470 | + foreach ($results as $cache_code => &$result_ref) { |
|
471 | + $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
472 | + } |
|
432 | 473 | } |
433 | 474 | |
434 | 475 | # is_watched |
435 | 476 | |
436 | 477 | if (in_array('is_watched', $fields)) |
437 | 478 | { |
438 | - if ($request->token == null) |
|
439 | - throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
479 | + if ($request->token == null) { |
|
480 | + throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
481 | + } |
|
440 | 482 | $tmp = Db::select_column(" |
441 | 483 | select c.wp_oc |
442 | 484 | from |
@@ -447,8 +489,9 @@ discard block |
||
447 | 489 | and cw.user_id = '".Db::escape_string($request->token->user_id)."' |
448 | 490 | "); |
449 | 491 | $tmp2 = array(); |
450 | - foreach ($tmp as $cache_code) |
|
451 | - $tmp2[$cache_code] = true; |
|
492 | + foreach ($tmp as $cache_code) { |
|
493 | + $tmp2[$cache_code] = true; |
|
494 | + } |
|
452 | 495 | |
453 | 496 | # OCDE caches can also be indirectly watched by watching cache lists: |
454 | 497 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -464,20 +507,23 @@ discard block |
||
464 | 507 | and clw.cache_list_id = cli.cache_list_id |
465 | 508 | and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
466 | 509 | "); |
467 | - foreach ($tmp as $cache_code) |
|
468 | - $tmp2[$cache_code] = true; |
|
510 | + foreach ($tmp as $cache_code) { |
|
511 | + $tmp2[$cache_code] = true; |
|
512 | + } |
|
469 | 513 | } |
470 | 514 | |
471 | - foreach ($results as $cache_code => &$result_ref) |
|
472 | - $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
515 | + foreach ($results as $cache_code => &$result_ref) { |
|
516 | + $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
517 | + } |
|
473 | 518 | } |
474 | 519 | |
475 | 520 | # is_ignored |
476 | 521 | |
477 | 522 | if (in_array('is_ignored', $fields)) |
478 | 523 | { |
479 | - if ($request->token == null) |
|
480 | - throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
524 | + if ($request->token == null) { |
|
525 | + throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
526 | + } |
|
481 | 527 | $tmp = Db::select_column(" |
482 | 528 | select c.wp_oc |
483 | 529 | from |
@@ -488,10 +534,12 @@ discard block |
||
488 | 534 | and ci.user_id = '".Db::escape_string($request->token->user_id)."' |
489 | 535 | "); |
490 | 536 | $tmp2 = array(); |
491 | - foreach ($tmp as $cache_code) |
|
492 | - $tmp2[$cache_code] = true; |
|
493 | - foreach ($results as $cache_code => &$result_ref) |
|
494 | - $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
537 | + foreach ($tmp as $cache_code) { |
|
538 | + $tmp2[$cache_code] = true; |
|
539 | + } |
|
540 | + foreach ($results as $cache_code => &$result_ref) { |
|
541 | + $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
542 | + } |
|
495 | 543 | } |
496 | 544 | |
497 | 545 | # Descriptions and hints. |
@@ -579,27 +627,31 @@ discard block |
||
579 | 627 | foreach (array( |
580 | 628 | 'short_description', 'short_descriptions', 'description', 'descriptions', |
581 | 629 | 'hint', 'hints', 'hint2', 'hints2' |
582 | - ) as $field) |
|
583 | - if (!in_array($field, $fields)) |
|
630 | + ) as $field) { |
|
631 | + if (!in_array($field, $fields)) |
|
584 | 632 | foreach ($results as &$result_ref) |
585 | 633 | unset($result_ref[$field]); |
634 | + } |
|
586 | 635 | } |
587 | 636 | |
588 | 637 | # Images. |
589 | 638 | |
590 | 639 | if (in_array('images', $fields) || in_array('preview_image', $fields)) |
591 | 640 | { |
592 | - if (in_array('images', $fields)) |
|
593 | - foreach ($results as &$result_ref) |
|
641 | + if (in_array('images', $fields)) { |
|
642 | + foreach ($results as &$result_ref) |
|
594 | 643 | $result_ref['images'] = array(); |
595 | - if (in_array('preview_image', $fields)) |
|
596 | - foreach ($results as &$result_ref) |
|
644 | + } |
|
645 | + if (in_array('preview_image', $fields)) { |
|
646 | + foreach ($results as &$result_ref) |
|
597 | 647 | $result_ref['preview_image'] = null; |
648 | + } |
|
598 | 649 | |
599 | - if (Db::field_exists('pictures', 'mappreview')) |
|
600 | - $preview_field = "mappreview"; |
|
601 | - else |
|
602 | - $preview_field = "0"; |
|
650 | + if (Db::field_exists('pictures', 'mappreview')) { |
|
651 | + $preview_field = "mappreview"; |
|
652 | + } else { |
|
653 | + $preview_field = "0"; |
|
654 | + } |
|
603 | 655 | $rs = Db::query(" |
604 | 656 | select object_id, uuid, url, title, spoiler, ".$preview_field." as preview |
605 | 657 | from pictures |
@@ -635,10 +687,12 @@ discard block |
||
635 | 687 | 'unique_caption' => self::get_unique_caption($row['title']), |
636 | 688 | 'is_spoiler' => ($row['spoiler'] ? true : false), |
637 | 689 | ); |
638 | - if (in_array('images', $fields)) |
|
639 | - $results[$cache_code]['images'][] = $image; |
|
640 | - if ($row['preview'] != 0 && in_array('preview_image', $fields)) |
|
641 | - $results[$cache_code]['preview_image'] = $image; |
|
690 | + if (in_array('images', $fields)) { |
|
691 | + $results[$cache_code]['images'][] = $image; |
|
692 | + } |
|
693 | + if ($row['preview'] != 0 && in_array('preview_image', $fields)) { |
|
694 | + $results[$cache_code]['preview_image'] = $image; |
|
695 | + } |
|
642 | 696 | } |
643 | 697 | } |
644 | 698 | |
@@ -653,8 +707,9 @@ discard block |
||
653 | 707 | { |
654 | 708 | $fields_to_remove_later[] = 'attr_acodes'; |
655 | 709 | } |
656 | - foreach ($results as &$result_ref) |
|
657 | - $result_ref['attr_acodes'] = array(); |
|
710 | + foreach ($results as &$result_ref) { |
|
711 | + $result_ref['attr_acodes'] = array(); |
|
712 | + } |
|
658 | 713 | |
659 | 714 | # Load internal_attr_id => acode mapping. |
660 | 715 | |
@@ -687,8 +742,9 @@ discard block |
||
687 | 742 | foreach ($results as &$result_ref) |
688 | 743 | { |
689 | 744 | $result_ref['attrnames'] = array(); |
690 | - foreach ($result_ref['attr_acodes'] as $acode) |
|
691 | - $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
745 | + foreach ($result_ref['attr_acodes'] as $acode) { |
|
746 | + $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
747 | + } |
|
692 | 748 | } |
693 | 749 | } |
694 | 750 | } |
@@ -697,8 +753,9 @@ discard block |
||
697 | 753 | |
698 | 754 | if (in_array('latest_logs', $fields)) |
699 | 755 | { |
700 | - foreach ($results as &$result_ref) |
|
701 | - $result_ref['latest_logs'] = array(); |
|
756 | + foreach ($results as &$result_ref) { |
|
757 | + $result_ref['latest_logs'] = array(); |
|
758 | + } |
|
702 | 759 | |
703 | 760 | # Get all log IDs in proper order, then filter out the latest |
704 | 761 | # ones. This should be the fastest technique ... |
@@ -732,8 +789,9 @@ discard block |
||
732 | 789 | { |
733 | 790 | # User wants some of the latest logs. |
734 | 791 | $tmp = array(); |
735 | - while ($row = Db::fetch_assoc($rs)) |
|
736 | - $tmp[$row['cache_id']][] = $row; |
|
792 | + while ($row = Db::fetch_assoc($rs)) { |
|
793 | + $tmp[$row['cache_id']][] = $row; |
|
794 | + } |
|
737 | 795 | foreach ($tmp as $cache_key => &$rowslist_ref) |
738 | 796 | { |
739 | 797 | for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++) |
@@ -742,8 +800,7 @@ discard block |
||
742 | 800 | $log2cache_map[$rowslist_ref[$i]['uuid']] = $cacheid2wptcode[$rowslist_ref[$i]['cache_id']]; |
743 | 801 | } |
744 | 802 | } |
745 | - } |
|
746 | - else |
|
803 | + } else |
|
747 | 804 | { |
748 | 805 | # User wants ALL logs. |
749 | 806 | while ($row = Db::fetch_assoc($rs)) |
@@ -773,18 +830,17 @@ discard block |
||
773 | 830 | ); |
774 | 831 | foreach ($subset as $log_uuid) |
775 | 832 | { |
776 | - if ($entries[$log_uuid]) |
|
777 | - $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
833 | + if ($entries[$log_uuid]) { |
|
834 | + $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
835 | + } |
|
778 | 836 | } |
779 | 837 | } |
780 | - } |
|
781 | - catch (Exception $e) |
|
838 | + } catch (Exception $e) |
|
782 | 839 | { |
783 | 840 | if (($e instanceof InvalidParam) && ($e->paramName == 'fields')) |
784 | 841 | { |
785 | 842 | throw new InvalidParam('log_fields', $e->whats_wrong_about_it); |
786 | - } |
|
787 | - else |
|
843 | + } else |
|
788 | 844 | { |
789 | 845 | /* Something is wrong with OUR code. */ |
790 | 846 | throw new Exception($e); |
@@ -796,10 +852,12 @@ discard block |
||
796 | 852 | |
797 | 853 | if (in_array('my_notes', $fields)) |
798 | 854 | { |
799 | - if ($request->token == null) |
|
800 | - throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
801 | - foreach ($results as &$result_ref) |
|
802 | - $result_ref['my_notes'] = null; |
|
855 | + if ($request->token == null) { |
|
856 | + throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
857 | + } |
|
858 | + foreach ($results as &$result_ref) { |
|
859 | + $result_ref['my_notes'] = null; |
|
860 | + } |
|
803 | 861 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
804 | 862 | { |
805 | 863 | # OCPL uses cache_notes table to store notes. |
@@ -812,8 +870,7 @@ discard block |
||
812 | 870 | and user_id = '".Db::escape_string($request->token->user_id)."' |
813 | 871 | group by cache_id |
814 | 872 | "); |
815 | - } |
|
816 | - else |
|
873 | + } else |
|
817 | 874 | { |
818 | 875 | # OCDE uses coordinates table (with type == 2) to store notes (this is somewhat weird). |
819 | 876 | |
@@ -852,13 +909,15 @@ discard block |
||
852 | 909 | and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
853 | 910 | "); |
854 | 911 | $trs = array(); |
855 | - while ($row = Db::fetch_assoc($rs)) |
|
856 | - $trs[$row['cache_code']][] = $row; |
|
912 | + while ($row = Db::fetch_assoc($rs)) { |
|
913 | + $trs[$row['cache_code']][] = $row; |
|
914 | + } |
|
857 | 915 | foreach ($results as $cache_code => &$result_ref) |
858 | 916 | { |
859 | 917 | $result_ref['trackables'] = array(); |
860 | - if (!isset($trs[$cache_code])) |
|
861 | - continue; |
|
918 | + if (!isset($trs[$cache_code])) { |
|
919 | + continue; |
|
920 | + } |
|
862 | 921 | foreach ($trs[$cache_code] as $t) |
863 | 922 | { |
864 | 923 | $result_ref['trackables'][] = array( |
@@ -875,10 +934,10 @@ discard block |
||
875 | 934 | if (in_array('trackables', $fields)) |
876 | 935 | { |
877 | 936 | # We already got all trackables data, no need to query database again. |
878 | - foreach ($results as $cache_code => &$result_ref) |
|
879 | - $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
880 | - } |
|
881 | - else |
|
937 | + foreach ($results as $cache_code => &$result_ref) { |
|
938 | + $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
939 | + } |
|
940 | + } else |
|
882 | 941 | { |
883 | 942 | $rs = Db::query(" |
884 | 943 | select wp as cache_code, count(*) as count |
@@ -887,14 +946,16 @@ discard block |
||
887 | 946 | group by wp |
888 | 947 | "); |
889 | 948 | $tr_counts = new ArrayObject(); |
890 | - while ($row = Db::fetch_assoc($rs)) |
|
891 | - $tr_counts[$row['cache_code']] = $row['count']; |
|
949 | + while ($row = Db::fetch_assoc($rs)) { |
|
950 | + $tr_counts[$row['cache_code']] = $row['count']; |
|
951 | + } |
|
892 | 952 | foreach ($results as $cache_code => &$result_ref) |
893 | 953 | { |
894 | - if (isset($tr_counts[$cache_code])) |
|
895 | - $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
896 | - else |
|
897 | - $result_ref['trackables_count'] = 0; |
|
954 | + if (isset($tr_counts[$cache_code])) { |
|
955 | + $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
956 | + } else { |
|
957 | + $result_ref['trackables_count'] = 0; |
|
958 | + } |
|
898 | 959 | } |
899 | 960 | unset($tr_counts); |
900 | 961 | } |
@@ -916,11 +977,11 @@ discard block |
||
916 | 977 | coordinates_type ct |
917 | 978 | left join sys_trans_text stt on stt.trans_id = ct.trans_id |
918 | 979 | "); |
919 | - while ($row = Db::fetch_assoc($rs)) |
|
920 | - $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
980 | + while ($row = Db::fetch_assoc($rs)) { |
|
981 | + $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
982 | + } |
|
921 | 983 | Db::free_result($rs); |
922 | - } |
|
923 | - else |
|
984 | + } else |
|
924 | 985 | { |
925 | 986 | $rs = Db::query(" |
926 | 987 | select id, pl, en |
@@ -934,8 +995,9 @@ discard block |
||
934 | 995 | } |
935 | 996 | } |
936 | 997 | |
937 | - foreach ($results as &$result_ref) |
|
938 | - $result_ref['alt_wpts'] = array(); |
|
998 | + foreach ($results as &$result_ref) { |
|
999 | + $result_ref['alt_wpts'] = array(); |
|
1000 | + } |
|
939 | 1001 | $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
940 | 1002 | |
941 | 1003 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
@@ -970,8 +1032,7 @@ discard block |
||
970 | 1032 | and status = 1 |
971 | 1033 | order by cache_id, stage, `desc` |
972 | 1034 | "); |
973 | - } |
|
974 | - else |
|
1035 | + } else |
|
975 | 1036 | { |
976 | 1037 | # OCDE uses 'coordinates' table (with type=1) to store additional waypoints |
977 | 1038 | # and defines waypoint types in 'coordinates_type' table. |
@@ -1117,8 +1178,9 @@ discard block |
||
1117 | 1178 | c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
1118 | 1179 | "); |
1119 | 1180 | $country_codes2names = array(); |
1120 | - while ($row = Db::fetch_assoc($rs)) |
|
1121 | - $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
1181 | + while ($row = Db::fetch_assoc($rs)) { |
|
1182 | + $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
1183 | + } |
|
1122 | 1184 | Db::free_result($rs); |
1123 | 1185 | |
1124 | 1186 | # get geocache countries and states |
@@ -1135,15 +1197,15 @@ discard block |
||
1135 | 1197 | "); |
1136 | 1198 | while ($row = Db::fetch_assoc($rs)) |
1137 | 1199 | { |
1138 | - if (!isset($country_codes2names[$row['country_code']])) |
|
1139 | - $countries[$row['cache_code']] = ''; |
|
1140 | - else |
|
1141 | - $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
1200 | + if (!isset($country_codes2names[$row['country_code']])) { |
|
1201 | + $countries[$row['cache_code']] = ''; |
|
1202 | + } else { |
|
1203 | + $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
1204 | + } |
|
1142 | 1205 | $states[$row['cache_code']] = $row['state']; |
1143 | 1206 | } |
1144 | 1207 | Db::free_result($rs); |
1145 | - } |
|
1146 | - else |
|
1208 | + } else |
|
1147 | 1209 | { |
1148 | 1210 | # OCPL: |
1149 | 1211 | # - cache_location data is entered by the user. |
@@ -1172,13 +1234,15 @@ discard block |
||
1172 | 1234 | |
1173 | 1235 | if (in_array('country', $fields)) |
1174 | 1236 | { |
1175 | - foreach ($results as $cache_code => &$row_ref) |
|
1176 | - $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
1237 | + foreach ($results as $cache_code => &$row_ref) { |
|
1238 | + $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
1239 | + } |
|
1177 | 1240 | } |
1178 | 1241 | if (in_array('state', $fields)) |
1179 | 1242 | { |
1180 | - foreach ($results as $cache_code => &$row_ref) |
|
1181 | - $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
1243 | + foreach ($results as $cache_code => &$row_ref) { |
|
1244 | + $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
1245 | + } |
|
1182 | 1246 | } |
1183 | 1247 | unset($countries); |
1184 | 1248 | unset($states); |
@@ -1191,12 +1255,13 @@ discard block |
||
1191 | 1255 | /* Note, that the "owner" and "internal_id" fields are automatically included, |
1192 | 1256 | * whenever the attribution_note is included. */ |
1193 | 1257 | |
1194 | - foreach ($results as $cache_code => &$result_ref) |
|
1195 | - $result_ref['attribution_note'] = |
|
1258 | + foreach ($results as $cache_code => &$result_ref) { |
|
1259 | + $result_ref['attribution_note'] = |
|
1196 | 1260 | self::get_cache_attribution_note( |
1197 | 1261 | $result_ref['internal_id'], $langpref[0], $langpref, |
1198 | 1262 | $results[$cache_code]['owner'], 'full' |
1199 | 1263 | ); |
1264 | + } |
|
1200 | 1265 | } |
1201 | 1266 | |
1202 | 1267 | # Protection areas |
@@ -1222,8 +1287,7 @@ discard block |
||
1222 | 1287 | group by npa_areas.type_id, npa_areas.name |
1223 | 1288 | order by npa_types.ordinal |
1224 | 1289 | "); |
1225 | - } |
|
1226 | - else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) |
|
1290 | + } else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) |
|
1227 | 1291 | { |
1228 | 1292 | # Current OCPL table definitions use collation 'latin1' for parkipl |
1229 | 1293 | # and 'utf8' for np_areas. Union needs identical collations. |
@@ -1255,8 +1319,7 @@ discard block |
||
1255 | 1319 | c.cache_id in (".$cache_ids_escaped_and_imploded.") |
1256 | 1320 | and cache_npa_areas.npa_id != 0 |
1257 | 1321 | "); |
1258 | - } |
|
1259 | - else |
|
1322 | + } else |
|
1260 | 1323 | { |
1261 | 1324 | # OC.US and .UK do not have a 'parkipl' table. |
1262 | 1325 | # OC.US has a 'us_parks' table instead. |
@@ -1264,8 +1327,9 @@ discard block |
||
1264 | 1327 | $rs = null; |
1265 | 1328 | } |
1266 | 1329 | |
1267 | - foreach ($results as &$result_ref) |
|
1268 | - $result_ref['protection_areas'] = array(); |
|
1330 | + foreach ($results as &$result_ref) { |
|
1331 | + $result_ref['protection_areas'] = array(); |
|
1332 | + } |
|
1269 | 1333 | if ($rs) |
1270 | 1334 | { |
1271 | 1335 | while ($row = Db::fetch_assoc($rs)) |
@@ -1280,18 +1344,20 @@ discard block |
||
1280 | 1344 | } |
1281 | 1345 | |
1282 | 1346 | # Check which cache codes were not found and mark them with null. |
1283 | - foreach ($cache_codes as $cache_code) |
|
1284 | - if (!isset($results[$cache_code])) |
|
1347 | + foreach ($cache_codes as $cache_code) { |
|
1348 | + if (!isset($results[$cache_code])) |
|
1285 | 1349 | $results[$cache_code] = null; |
1350 | + } |
|
1286 | 1351 | |
1287 | 1352 | if (count($fields_to_remove_later) > 0) |
1288 | 1353 | { |
1289 | 1354 | # Some of the fields in $results were added only temporarily |
1290 | 1355 | # (the Consumer did not ask for them). We will remove these fields now. |
1291 | 1356 | |
1292 | - foreach ($results as &$result_ref) |
|
1293 | - foreach ($fields_to_remove_later as $field) |
|
1357 | + foreach ($results as &$result_ref) { |
|
1358 | + foreach ($fields_to_remove_later as $field) |
|
1294 | 1359 | unset($result_ref[$field]); |
1360 | + } |
|
1295 | 1361 | } |
1296 | 1362 | |
1297 | 1363 | # Order the results in the same order as the input codes were given. |
@@ -1301,8 +1367,9 @@ discard block |
||
1301 | 1367 | # so we just have to rewrite it (sequentially). |
1302 | 1368 | |
1303 | 1369 | $ordered_results = new ArrayObject(); |
1304 | - foreach ($cache_codes as $cache_code) |
|
1305 | - $ordered_results[$cache_code] = $results[$cache_code]; |
|
1370 | + foreach ($cache_codes as $cache_code) { |
|
1371 | + $ordered_results[$cache_code] = $results[$cache_code]; |
|
1372 | + } |
|
1306 | 1373 | |
1307 | 1374 | /* Handle OCPL's "access logs" feature. */ |
1308 | 1375 | |
@@ -1415,8 +1482,7 @@ discard block |
||
1415 | 1482 | _("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."), |
1416 | 1483 | $cache_url, $site_url, $site_name |
1417 | 1484 | ); |
1418 | - } |
|
1419 | - else |
|
1485 | + } else |
|
1420 | 1486 | { |
1421 | 1487 | # OC.de wants the tld in lowercase here |
1422 | 1488 | $site_name = ucfirst(strtolower($site_name)); |
@@ -1430,8 +1496,7 @@ discard block |
||
1430 | 1496 | ), |
1431 | 1497 | $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x') |
1432 | 1498 | ); |
1433 | - } |
|
1434 | - elseif ($type == 'static') |
|
1499 | + } elseif ($type == 'static') |
|
1435 | 1500 | { |
1436 | 1501 | $note = sprintf( |
1437 | 1502 | _( |