forked from Glennmen/PMSF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw_data.php
1554 lines (1422 loc) · 57.6 KB
/
raw_data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include('config/config.php');
include('adapter.php');
$now = new DateTime();
$d = array();
$d["timestamp"] = $now->getTimestamp();
$swLat = !empty($_POST['swLat']) ? $_POST['swLat'] : 0;
$neLng = !empty($_POST['neLng']) ? $_POST['neLng'] : 0;
$swLng = !empty($_POST['swLng']) ? $_POST['swLng'] : 0;
$neLat = !empty($_POST['neLat']) ? $_POST['neLat'] : 0;
$oSwLat = !empty($_POST['oSwLat']) ? $_POST['oSwLat'] : 0;
$oSwLng = !empty($_POST['oSwLng']) ? $_POST['oSwLng'] : 0;
$oNeLat = !empty($_POST['oNeLat']) ? $_POST['oNeLat'] : 0;
$oNeLng = !empty($_POST['oNeLng']) ? $_POST['oNeLng'] : 0;
$luredonly = !empty($_POST['luredonly']) ? $_POST['luredonly'] : false;
$lastpokemon = !empty($_POST['lastpokemon']) ? $_POST['lastpokemon'] : false;
$lastgyms = !empty($_POST['lastgyms']) ? $_POST['lastgyms'] : false;
$lastpokestops = !empty($_POST['lastpokestops']) ? $_POST['lastpokestops'] : false;
$lastlocs = !empty($_POST['lastslocs']) ? $_POST['lastslocs'] : false;
$lastspawns = !empty($_POST['lastspawns']) ? $_POST['lastspawns'] : false;
$d["lastpokestops"] = !empty($_POST['pokestops']) ? $_POST['pokestops'] : false;
$d["lastgyms"] = !empty($_POST['gyms']) ? $_POST['gyms'] : false;
$d["lastslocs"] = !empty($_POST['scanned']) ? $_POST['scanned'] : false;
$d["lastspawns"] = !empty($_POST['spawnpoints']) ? $_POST['spawnpoints'] : false;
$d["lastpokemon"] = !empty($_POST['pokemon']) ? $_POST['pokemon'] : false;
$timestamp = !empty($_POST['timestamp']) ? $_POST['timestamp'] : 0;
$useragent = $_SERVER['HTTP_USER_AGENT'];
if (empty($swLat) || empty($swLng) || empty($neLat) || empty($neLng) || preg_match("/curl|libcurl/", $useragent)) {
http_response_code(400);
die();
}
if ($maxLatLng > 0 && ((($neLat - $swLat) > $maxLatLng) || (($neLng - $swLng) > $maxLatLng))) {
http_response_code(400);
die();
}
if (!validateToken($_POST['token'])) {
http_response_code(400);
die();
}
$newarea = false;
if (($oSwLng < $swLng) && ($oSwLat < $swLat) && ($oNeLat > $neLat) && ($oNeLng > $neLng)) {
$newarea = false;
} elseif (($oSwLat != $swLat) && ($oSwLng != $swLng) && ($oNeLat != $neLat) && ($oNeLng != $neLng)) {
$newarea = true;
} else {
$newarea = false;
}
$d["oSwLat"] = $swLat;
$d["oSwLng"] = $swLng;
$d["oNeLat"] = $neLat;
$d["oNeLng"] = $neLng;
$ids = array();
$eids = array();
$reids = array();
global $noPokemon;
if (!$noPokemon) {
if ($d["lastpokemon"] == "true") {
if ($lastpokemon != 'true') {
$d["pokemons"] = get_active($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["pokemons"] = get_active($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["pokemons"] = get_active($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
if (!empty($_POST['eids'])) {
$eids = explode(",", $_POST['eids']);
foreach ($d['pokemons'] as $elementKey => $element) {
foreach ($element as $valueKey => $value) {
if ($valueKey == 'pokemon_id') {
if (in_array($value, $eids)) {
//delete this particular object from the $array
unset($d['pokemons'][$elementKey]);
}
}
}
}
}
if (!empty($_POST['reids'])) {
$reids = explode(",", $_POST['reids']);
$d["pokemons"] = $d["pokemons"] + (get_active_by_id($reids, $swLat, $swLng, $neLat, $neLng));
$d["reids"] = !empty($_POST['reids']) ? $reids : null;
}
}
}
global $noPokestops;
if (!$noPokestops) {
if ($d["lastpokestops"] == "true") {
if ($lastpokestops != "true") {
$d["pokestops"] = get_stops($swLat, $swLng, $neLat, $neLng, 0, 0, 0, 0, 0, $luredonly);
} else {
if ($newarea) {
$d["pokestops"] = get_stops($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng, $luredonly);
} else {
$d["pokestops"] = get_stops($swLat, $swLng, $neLat, $neLng, $timestamp, 0, 0, 0, 0, $luredonly);
}
}
}
}
global $noGyms, $noRaids;
if (!$noGyms || !$noRaids) {
if ($d["lastgyms"] == "true") {
if ($lastgyms != "true") {
$d["gyms"] = get_gyms($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["gyms"] = get_gyms($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["gyms"] = get_gyms($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
global $noSpawnPoints;
if (!$noSpawnPoints) {
if ($d["lastspawns"] == "true") {
if ($lastspawns != "true") {
$d["spawnpoints"] = get_spawnpoints($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["spawnpoints"] = get_spawnpoints($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["spawnpoints"] = get_spawnpoints($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
global $noScannedLocations;
if (!$noScannedLocations) {
if ($d["lastslocs"] == "true") {
if ($lastlocs != "true") {
$d["scanned"] = get_recent($swLat, $swLng, $neLat, $neLng);
} else {
if ($newarea) {
$d["scanned"] = get_recent($swLat, $swLng, $neLat, $neLng, 0, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
} else {
$d["scanned"] = get_recent($swLat, $swLng, $neLat, $neLng, $timestamp);
}
}
}
}
$d['token'] = refreshCsrfToken();
$jaysson = json_encode($d);
echo $jaysson;
function get_active($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0)
{
global $db;
$datas = array();
global $map;
if ($map == "monocle") {
if ($swLat == 0) {
$datas = $db->query("SELECT * FROM sightings WHERE expire_timestamp > :time", [':time'=> time()])->fetchAll();
} elseif ($tstamp > 0) {
$datas = $db->query("SELECT *
FROM sightings
WHERE expire_timestamp > :time
AND lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng", [':time' => time(), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT *
FROM sightings
WHERE expire_timestamp > :time
AND lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng
AND NOT( lat > :oSwLat
AND lon > :oSwLng
AND lat < :oNeLat
AND lon < :oNeLng ) " , [':time' => time(), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} else {
$datas = $db->query("SELECT *
FROM sightings
WHERE expire_timestamp > :time
AND lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng", [':time' => time(), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
} else {
$time = new DateTime();
$time->setTimeZone(new DateTimeZone('UTC'));
$time->setTimestamp(time());
if ($swLat == 0) {
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime", [':disappearTime' => date_format($time, 'Y-m-d H:i:s')])->fetchAll();
} elseif ($tstamp > 0) {
$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($tstamp);
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime
AND last_modified > :lastModified
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':disappearTime' => date_format($time, 'Y-m-d H:i:s'), ':lastModified'=>date_format($date, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng
AND NOT(
latitude > :oSwLat
AND longitude > :oSwLng
AND latitude < :oNeLat
AND longitude < :oNeLng)", [':disappearTime' => date_format($time, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} else {
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':disappearTime' => date_format($time, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
}
$pokemons = array();
$json_poke = "static/data/pokemon.json";
$json_contents = file_get_contents($json_poke);
$data = json_decode($json_contents, TRUE);
$i = 0;
/* fetch associative array */
foreach ($datas as $row) {
$p = array();
$dissapear = $row["expire_timestamp"] * 1000;
$lat = floatval($row["lat"]);
$lon = floatval($row["lon"]);
$pokeid = intval($row["pokemon_id"]);
$atk = isset($row["atk_iv"]) ? intval($row["atk_iv"]) : null;
$def = isset($row["def_iv"]) ? intval($row["def_iv"]) : null;
$sta = isset($row["sta_iv"]) ? intval($row["sta_iv"]) : null;
$mv1 = !empty($row["move_1"]) ? intval($row["move_1"]) : null;
$mv2 = !empty($row["move_2"]) ? intval($row["move_2"]) : null;
$weight = !empty($row["weight"]) ? floatval($row["weight"]) : null;
$height = !empty($row["height"]) ? floatval($row["height"]) : null;
$gender = isset($row["gender"]) ? intval($row["gender"]) : null;
$form = isset($row["form"]) ? intval($row["form"]) : null;
$cp = !empty($row["cp"]) ? intval($row["cp"]) : null;
$cpm = !empty($row["cp_multiplier"]) ? floatval($row["cp_multiplier"]) : null;
$level = !empty($row["level"]) ? intval($row["level"]) : null;
$p["disappear_time"] = $dissapear; //done
$p["encounter_id"] = $row["encounter_id"]; //done
global $noHighLevelData;
if (!$noHighLevelData) {
$p["individual_attack"] = $atk; //done
$p["individual_defense"] = $def; //done
$p["individual_stamina"] = $sta; //done
$p["move_1"] = $mv1; //done
$p["move_2"] = $mv2;
$p["weight"] = $weight;
$p["height"] = $height;
$p["cp"] = $cp;
$p["cp_multiplier"] = $cpm;
$p["level"] = $level;
}
$p["latitude"] = $lat; //done
$p["longitude"] = $lon; //done
$p["gender"] = $gender;
$p["form"] = $form;
$p["pokemon_id"] = $pokeid;
$p["pokemon_name"] = i8ln($data[$pokeid]['name']);
$p["pokemon_rarity"] = i8ln($data[$pokeid]['rarity']);
$types = $data[$pokeid]["types"];
foreach ($types as $k => $v) {
$types[$k]['type'] = i8ln($v['type']);
}
$p["pokemon_types"] = $types;
$p["spawnpoint_id"] = $row["spawn_id"];
$pokemons[] = $p;
unset($datas[$i]);
$i++;
}
return $pokemons;
}
function get_active_by_id($ids, $swLat, $swLng, $neLat, $neLng)
{
global $db;
$datas = array();
global $map;
$pkmn_in = '';
if (count($ids)) {
$i=1;
foreach ($ids as $id) {
$pkmn_ids[':qry_'.$i] = $id;
$pkmn_in .= ':'.'qry_'.$i.",";
$i++;
}
$pkmn_in = substr($pkmn_in, 0, -1);
} else {
$pkmn_ids = [];
}
if ($map == "monocle") {
if ($swLat == 0) {
$datas = $db->query("SELECT *
FROM sightings
WHERE `expire_timestamp` > :time
AND pokemon_id IN ( $pkmn_in ) ", array_merge($pkmn_ids, [':time'=>time()]))->fetchAll();
} else {
$datas = $db->query("SELECT *
FROM sightings
WHERE expire_timestamp > :timeStamp
AND pokemon_id IN ( $pkmn_in )
AND lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng", array_merge($pkmn_ids, [':timeStamp'=> time(), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng]))->fetchAll();
}
} else {
$time = new DateTime();
$time->setTimeZone(new DateTimeZone('UTC'));
$time->setTimestamp(time());
if ($swLat == 0) {
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime
AND pokemon_id IN ( $pkmn_in )", array_merge($pkmn_ids, [':disappearTime' => date_format($time, 'Y-m-d H:i:s')]))->fetchAll();
} else {
$datas = $db->query("SELECT *,
Unix_timestamp(Convert_tz(disappear_time, '+00:00', @@global.time_zone)) AS expire_timestamp,
latitude AS lat,
longitude AS lon,
individual_attack AS atk_iv,
individual_defense AS def_iv,
individual_stamina AS sta_iv,
spawnpoint_id AS spawn_id
FROM pokemon
WHERE disappear_time > :disappearTime
AND pokemon_id IN ( $pkmn_in )
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", array_merge($pkmn_ids, [':disappearTime' => date_format($time, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng]))->fetchAll();
}
}
$pokemons = array();
$json_poke = "static/data/pokemon.json";
$json_contents = file_get_contents($json_poke);
$data = json_decode($json_contents, TRUE);
$i = 0;
/* fetch associative array */
foreach ($datas as $row) {
$p = array();
$dissapear = $row["expire_timestamp"] * 1000;
$lat = floatval($row["lat"]);
$lon = floatval($row["lon"]);
$pokeid = intval($row["pokemon_id"]);
$atk = isset($row["atk_iv"]) ? intval($row["atk_iv"]) : null;
$def = isset($row["def_iv"]) ? intval($row["def_iv"]) : null;
$sta = isset($row["sta_iv"]) ? intval($row["sta_iv"]) : null;
$mv1 = !empty($row["move_1"]) ? intval($row["move_1"]) : null;
$mv2 = !empty($row["move_2"]) ? intval($row["move_2"]) : null;
$weight = !empty($row["weight"]) ? floatval($row["weight"]) : null;
$height = !empty($row["height"]) ? floatval($row["height"]) : null;
$gender = isset($row["gender"]) ? intval($row["gender"]) : null;
$form = isset($row["form"]) ? intval($row["form"]) : null;
$cp = !empty($row["cp"]) ? intval($row["cp"]) : null;
$cpm = !empty($row["cp_multiplier"]) ? floatval($row["cp_multiplier"]) : null;
$level = !empty($row["level"]) ? intval($row["level"]) : null;
$p["disappear_time"] = $dissapear; //done
$p["encounter_id"] = $row["encounter_id"]; //done
global $noHighLevelData;
if (!$noHighLevelData) {
$p["individual_attack"] = $atk; //done
$p["individual_defense"] = $def; //done
$p["individual_stamina"] = $sta; //done
$p["move_1"] = $mv1; //done
$p["move_2"] = $mv2;
$p["weight"] = $weight;
$p["height"] = $height;
$p["cp"] = $cp;
$p["cp_multiplier"] = $cpm;
$p["level"] = $level;
}
$p["latitude"] = $lat; //done
$p["longitude"] = $lon; //done
$p["gender"] = $gender;
$p["form"] = $form;
$p["pokemon_id"] = $pokeid;
$p["pokemon_name"] = i8ln($data[$pokeid]['name']);
$p["pokemon_rarity"] = i8ln($data[$pokeid]['rarity']);
$p["pokemon_types"] = $data[$pokeid]["types"];
$p["spawnpoint_id"] = $row["spawn_id"];
$pokemons[] = $p;
unset($datas[$i]);
$i++;
}
return $pokemons;
}
function get_stops($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0, $lured = false)
{
global $db;
$datas = array();
global $map;
if ($map == "monocle") {
if ($swLat == 0) {
$datas = $db->query("SELECT external_id, lat, lon FROM pokestops")->fetchAll();
} elseif ($tstamp > 0) {
$datas = $db->query("SELECT external_id,
lat,
lon
FROM pokestops
WHERE lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT external_id,
lat,
lon
FROM pokestops
WHERE lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng
AND NOT( lat > :oSwLat
AND lon > :oSwLng
AND lat < :oNeLat
AND lon < :oNeLng ) ", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} else {
$datas = $db->query("SELECT external_id,
lat,
lon
FROM pokestops
WHERE lat > :swLat
AND lon > :swLng
AND lat < :neLat
AND lon < :neLng", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
} else {
if ($swLat == 0) {
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone))
AS
lure_expiration,
pokestop_id
AS external_id,
latitude
AS lat,
longitude
AS lon
FROM pokestop ")->fetchAll();
} elseif ($tstamp > 0 && $lured == "true") {
$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($tstamp);
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone)) AS lure_expiration,
pokestop_id AS external_id,
latitude AS lat,
longitude AS lon
FROM pokestop
WHERE last_updated > :lastUpdated
AND active_fort_modifier IS NOT NULL
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':lastUpdated' => date_format($date, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($tstamp > 0) {
$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($tstamp);
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone)) AS lure_expiration,
pokestop_id AS external_id,
latitude AS lat,
longitude AS lon
FROM pokestop
WHERE last_updated > :lastUpdated
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':lastUpdated' => date_format($date, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0 && $lured == "true") {
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone))
AS
lure_expiration,
pokestop_id
AS external_id,
latitude
AS lat,
longitude
AS lon
FROM pokestop
WHERE active_fort_modifier IS NOT NULL
AND ( latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng )
AND NOT( latitude > :oSwLat
AND longitude > :oSwLng
AND latitude < :oNeLat
AND longitude < :oNeLng )
AND active_fort_modifier IS NOT NULL", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone))
AS
lure_expiration,
pokestop_id
AS external_id,
latitude
AS lat,
longitude
AS lon
FROM pokestop
WHERE latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng
AND NOT( latitude > :oSwLat
AND longitude > :oSwLng
AND latitude < :oNeLat
AND longitude < :oNeLng ) ", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} elseif ($lured == "true") {
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone)) AS lure_expiration,
pokestop_id AS external_id,
latitude AS lat,
longitude AS lon
FROM pokestop
WHERE active_fort_modifier IS NOT NULL
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} else {
$datas = $db->query("SELECT active_fort_modifier,
enabled,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(lure_expiration, '+00:00', @@global.time_zone)) AS lure_expiration,
pokestop_id AS external_id,
latitude AS lat,
longitude AS lon
FROM pokestop
WHERE latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
}
$i = 0;
$pokestops = array();
/* fetch associative array */
foreach ($datas as $row) {
$p = array();
$lat = floatval($row["lat"]);
$lon = floatval($row["lon"]);
$p["active_fort_modifier"] = !empty($row["active_fort_modifier"]) ? $row["active_fort_modifier"] : null;
$p["enabled"] = isset($row["enabled"]) ? boolval($row["enabled"]) : true;
$p["last_modified"] = !empty($row["last_modified"]) ? $row["last_modified"] * 1000 : 0;
$p["latitude"] = $lat;
$p["longitude"] = $lon;
$p["lure_expiration"] = !empty($row["lure_expiration"]) ? $row["lure_expiration"] * 1000 : null;
$p["pokestop_id"] = $row["external_id"];
$pokestops[] = $p;
unset($datas[$i]);
$i++;
}
return $pokestops;
}
function get_gyms($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0)
{
global $adapter;
if (!is_null($adapter)) {
return $adapter->get_gyms($swLat, $swLng, $neLat, $neLng, $tstamp, $oSwLat, $oSwLng, $oNeLat, $oNeLng);
}
global $db;
$datas = array();
global $map;
if ($map == "monocle") {
if ($swLat == 0) {
$datas = $db->query("SELECT t3.external_id,
t3.lat,
t3.lon,
t1.last_modified,
t1.team,
t1.slots_available,
t1.guard_pokemon_id
FROM (SELECT fort_id,
Max(last_modified) AS MaxLastModified
FROM fort_sightings
GROUP BY fort_id) t2
LEFT JOIN fort_sightings t1
ON t2.fort_id = t1.fort_id
AND t2.maxlastmodified = t1.last_modified
LEFT JOIN forts t3
ON t1.fort_id = t3.id")->fetchAll();
} elseif ($tstamp > 0) {
$datas = $db->query("SELECT t3.external_id,
t3.lat,
t3.lon,
t1.last_modified,
t1.team,
t1.slots_available,
t1.guard_pokemon_id
FROM (SELECT fort_id,
Max(last_modified) AS MaxLastModified
FROM fort_sightings
GROUP BY fort_id) t2
LEFT JOIN fort_sightings t1
ON t2.fort_id = t1.fort_id
AND t2.maxlastmodified = t1.last_modified
LEFT JOIN forts t3
ON t1.fort_id = t3.id
WHERE t3.lat > :swLat
AND t3.lon > :swLng
AND t3.lat < :neLat
AND t3.lon < :neLng",[':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT t3.external_id,
t3.lat,
t3.lon,
t1.last_modified,
t1.team,
t1.slots_available,
t1.guard_pokemon_id
FROM (SELECT fort_id,
Max(last_modified) AS MaxLastModified
FROM fort_sightings
GROUP BY fort_id) t2
LEFT JOIN fort_sightings t1
ON t2.fort_id = t1.fort_id
AND t2.maxlastmodified = t1.last_modified
LEFT JOIN forts t3
ON t1.fort_id = t3.id
WHERE t3.lat > :swLat
AND t3.lon > :swLng
AND t3.lat < :neLat
AND t3.lon < :neLng
AND NOT( t3.lat > :oSwLat
AND t3.lon > :oSwLng
AND t3.lat < :oNeLat
AND t3.lon < :oNeLng)", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} else {
$datas = $db->query("SELECT t3.external_id,
t3.lat,
t3.lon,
t1.last_modified,
t1.team,
t1.slots_available,
t1.guard_pokemon_id
FROM (
SELECT fort_id,
Max(last_modified) AS maxlastmodified
FROM fort_sightings
GROUP BY fort_id) t2
LEFT JOIN fort_sightings t1
ON t2.fort_id = t1.fort_id
AND t2.maxlastmodified = t1.last_modified
LEFT JOIN forts t3
ON t1.fort_id = t3.id
WHERE t3.lat > :swLat
AND t3.lon > :swLng
AND t3.lat < :neLat
AND t3.lon < :neLng",[':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
} else {
global $fork;
if ($fork != "sloppy") {
if ($swLat == 0) {
$datas = $db->query("SELECT gym.gym_id
AS
external_id,
latitude
AS lat,
longitude
AS lon,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00',
@@global.time_zone)) AS
last_scanned,
team_id
AS team,
enabled,
name,
level,
pokemon_id,
cp,
move_1,
move_2,
Unix_timestamp(Convert_tz(start, '+00:00', @@global.time_zone))
AS raid_start,
Unix_timestamp(Convert_tz(end, '+00:00', @@global.time_zone))
AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
LEFT JOIN raid
ON gym.gym_id = raid.gym_id ")->fetchAll();
} elseif ($tstamp > 0) {
$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($tstamp);
$datas = $db->query("SELECT gym.gym_id AS external_id,
latitude AS lat,
longitude AS lon,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00', @@global.time_zone)) AS last_scanned,
team_id AS team,
enabled,
name,
level,
pokemon_id,
cp,
move_1,
move_2,
Unix_timestamp(Convert_tz(start, '+00:00', @@global.time_zone)) AS raid_start,
Unix_timestamp(Convert_tz(end, '+00:00', @@global.time_zone)) AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
LEFT JOIN raid
ON gym.gym_id = raid.gym_id
WHERE gym.last_scanned > :lastScanned
AND latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng", [':lastScanned' => date_format($date, 'Y-m-d H:i:s'), ':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
} elseif ($oSwLat != 0) {
$datas = $db->query("SELECT gym.gym_id
AS
external_id,
latitude
AS lat,
longitude
AS lon,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00',
@@global.time_zone)) AS
last_scanned,
team_id
AS team,
enabled,
name,
level,
pokemon_id,
cp,
move_1,
move_2,
Unix_timestamp(Convert_tz(start, '+00:00', @@global.time_zone))
AS raid_start,
Unix_timestamp(Convert_tz(end, '+00:00', @@global.time_zone))
AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
LEFT JOIN raid
ON gym.gym_id = raid.gym_id
WHERE latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng
AND NOT( latitude > :oSwLat
AND longitude > :oSwLng
AND latitude < :oNeLat
AND longitude < :oNeLng )", [':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng, ':oSwLat' => $oSwLat, ':oSwLng' => $oSwLng, ':oNeLat' => $oNeLat, ':oNeLng' => $oNeLng])->fetchAll();
} else {
$datas = $db->query("SELECT gym.gym_id AS external_id,
latitude AS lat,
longitude AS lon,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00', @@global.time_zone)) AS last_scanned,
team_id AS team,
enabled,
name,
level,
pokemon_id,
cp,
move_1,
move_2,
Unix_timestamp(Convert_tz(start, '+00:00', @@global.time_zone)) AS raid_start,
Unix_timestamp(Convert_tz(
end, '+00:00', @@global.time_zone)) AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id
LEFT JOIN raid
ON gym.gym_id = raid.gym_id
WHERE latitude > :swLat
AND longitude > :swLng
AND latitude < :neLat
AND longitude < :neLng",[':swLat' => $swLat, ':swLng' => $swLng, ':neLat' => $neLat, ':neLng' => $neLng])->fetchAll();
}
} else {
if ($swLat == 0) {
$datas = $db->query("SELECT gym.gym_id
AS
external_id,
latitude
AS lat,
longitude
AS lon,
guard_pokemon_id,
slots_available,
total_gym_cp
AS total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone))
AS
last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00',
@@global.time_zone)) AS
last_scanned,
team_id
AS team,
enabled,
name,
raid_level
AS level,
raid_pokemon_id
AS pokemon_id,
raid_pokemon_cp
AS cp,
raid_pokemon_move_1
AS move_1,
raid_pokemon_move_2
AS move_2,
Unix_timestamp(Convert_tz(raid_battle, '+00:00', @@global.time_zone))
AS
raid_start,
Unix_timestamp(Convert_tz(raid_end, '+00:00', @@global.time_zone))
AS raid_end
FROM gym
LEFT JOIN gymdetails
ON gym.gym_id = gymdetails.gym_id")->fetchAll();
} elseif ($tstamp > 0) {
$date = new DateTime();
$date->setTimezone(new DateTimeZone('UTC'));
$date->setTimestamp($tstamp);
$datas = $db->query("SELECT gym.gym_id AS external_id,
latitude AS lat,
longitude AS lon,
guard_pokemon_id,
slots_available,
total_gym_cp AS total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00', @@global.time_zone)) AS last_scanned,
team_id AS team,
enabled,
name,
raid_level AS level,
raid_pokemon_id AS pokemon_id,
raid_pokemon_cp AS cp,
raid_pokemon_move_1 AS move_1,
raid_pokemon_move_2 AS move_2,
Unix_timestamp(Convert_tz(raid_battle, '+00:00', @@global.time_zone)) AS raid_start,
Unix_timestamp(Convert_tz(raid_end, '+00:00', @@global.time_zone)) AS raid_end
FROM gym