Failed Conditions
Pull Request — master (#371)
by
unknown
02:05
created
functions.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -216,6 +216,9 @@
 block discarded – undo
216 216
 //#######################################################################
217 217
 // used in get_tree_at_depth
218 218
 //#######################################################################
219
+/**
220
+ * @param boolean $correct_arrow
221
+ */
219 222
 function tree_check_array($array_check, $array_add, $correct_arrow)
220 223
 {
221 224
     $count = count($array_check);
Please login to merge, or discard this patch.
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@  discard block
 block discarded – undo
10 10
 
11 11
 function time_ago($timestamp, $locales)
12 12
 {
13
-    // Set up our variables.
14
-    $minute_in_seconds = 60;
15
-    $hour_in_seconds = $minute_in_seconds * 60;
16
-    $day_in_seconds = $hour_in_seconds * 24;
17
-    $week_in_seconds = $day_in_seconds * 7;
18
-    $month_in_seconds = $day_in_seconds * 30;
19
-    $year_in_seconds = $day_in_seconds * 365;
20
-
21
-    // current time
22
-    $now = time();
23
-
24
-    // Calculate the time difference between the current time reference point and the timestamp we're comparing.
25
-    // The difference is defined negative, when in the future.
26
-    $time_difference = $now - $timestamp;
27
-
28
-    // Calculate the time ago using the smallest applicable unit.
29
-    if ($time_difference < $hour_in_seconds) {
30
-        $difference_value = abs(round($time_difference / $minute_in_seconds));
31
-        $difference_label = 'MINUTE';
32
-    } elseif ($time_difference < $day_in_seconds) {
33
-        $difference_value = abs(round($time_difference / $hour_in_seconds));
34
-        $difference_label = 'HOUR';
35
-    } elseif ($time_difference < $week_in_seconds) {
36
-        $difference_value = abs(round($time_difference / $day_in_seconds));
37
-        $difference_label = 'DAY';
38
-    } elseif ($time_difference < $month_in_seconds) {
39
-        $difference_value = abs(round($time_difference / $week_in_seconds));
40
-        $difference_label = 'WEEK';
41
-    } elseif ($time_difference < $year_in_seconds) {
42
-        $difference_value = abs(round($time_difference / $month_in_seconds));
43
-        $difference_label = 'MONTH';
44
-    } else {
45
-        $difference_value = abs(round($time_difference / $year_in_seconds));
46
-        $difference_label = 'YEAR';
47
-    }
48
-
49
-    // plural
50
-    if (1 != $difference_value) {
51
-        $difference_label = $difference_label.'S';
52
-    }
53
-
54
-    if ($time_difference <= 0) {
55
-        // Present
56
-        return sprintf($locales->TIME_LEFT, $difference_value.' '.$locales->$difference_label);
57
-    } else {
58
-        // Past
59
-        return sprintf($locales->TIME_AGO, $difference_value.' '.$locales->$difference_label);
60
-    }
13
+	// Set up our variables.
14
+	$minute_in_seconds = 60;
15
+	$hour_in_seconds = $minute_in_seconds * 60;
16
+	$day_in_seconds = $hour_in_seconds * 24;
17
+	$week_in_seconds = $day_in_seconds * 7;
18
+	$month_in_seconds = $day_in_seconds * 30;
19
+	$year_in_seconds = $day_in_seconds * 365;
20
+
21
+	// current time
22
+	$now = time();
23
+
24
+	// Calculate the time difference between the current time reference point and the timestamp we're comparing.
25
+	// The difference is defined negative, when in the future.
26
+	$time_difference = $now - $timestamp;
27
+
28
+	// Calculate the time ago using the smallest applicable unit.
29
+	if ($time_difference < $hour_in_seconds) {
30
+		$difference_value = abs(round($time_difference / $minute_in_seconds));
31
+		$difference_label = 'MINUTE';
32
+	} elseif ($time_difference < $day_in_seconds) {
33
+		$difference_value = abs(round($time_difference / $hour_in_seconds));
34
+		$difference_label = 'HOUR';
35
+	} elseif ($time_difference < $week_in_seconds) {
36
+		$difference_value = abs(round($time_difference / $day_in_seconds));
37
+		$difference_label = 'DAY';
38
+	} elseif ($time_difference < $month_in_seconds) {
39
+		$difference_value = abs(round($time_difference / $week_in_seconds));
40
+		$difference_label = 'WEEK';
41
+	} elseif ($time_difference < $year_in_seconds) {
42
+		$difference_value = abs(round($time_difference / $month_in_seconds));
43
+		$difference_label = 'MONTH';
44
+	} else {
45
+		$difference_value = abs(round($time_difference / $year_in_seconds));
46
+		$difference_label = 'YEAR';
47
+	}
48
+
49
+	// plural
50
+	if (1 != $difference_value) {
51
+		$difference_label = $difference_label.'S';
52
+	}
53
+
54
+	if ($time_difference <= 0) {
55
+		// Present
56
+		return sprintf($locales->TIME_LEFT, $difference_value.' '.$locales->$difference_label);
57
+	} else {
58
+		// Past
59
+		return sprintf($locales->TIME_AGO, $difference_value.' '.$locales->$difference_label);
60
+	}
61 61
 }
62 62
 
63 63
 //#######################################################################
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
 
71 71
 function percent($val, $val_total)
72 72
 {
73
-    $count1 = $val_total / $val;
74
-    $count2 = $count1 * 100;
73
+	$count1 = $val_total / $val;
74
+	$count2 = $count1 * 100;
75 75
 
76
-    $count = number_format($count2, 0);
76
+	$count = number_format($count2, 0);
77 77
 
78
-    return $count;
78
+	return $count;
79 79
 }
80 80
 
81 81
 //#######################################################################
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
 
88 88
 function auto_ver($url)
89 89
 {
90
-    if (is_file(SYS_PATH.'/'.$url)) {
91
-        $path = pathinfo($url);
92
-        $ver = '.'.filemtime(SYS_PATH.'/'.$url).'.';
93
-        echo $path['dirname'].'/'.preg_replace('/\.(css|js|json)$/', $ver.'$1', $path['basename']);
94
-    } else {
95
-        echo $url;
96
-    }
90
+	if (is_file(SYS_PATH.'/'.$url)) {
91
+		$path = pathinfo($url);
92
+		$ver = '.'.filemtime(SYS_PATH.'/'.$url).'.';
93
+		echo $path['dirname'].'/'.preg_replace('/\.(css|js|json)$/', $ver.'$1', $path['basename']);
94
+	} else {
95
+		echo $url;
96
+	}
97 97
 }
98 98
 
99 99
 //#######################################################################
@@ -105,15 +105,15 @@  discard block
 block discarded – undo
105 105
 
106 106
 function file_update_ago($filepath)
107 107
 {
108
-    if (is_file($filepath)) {
109
-        $filemtime = filemtime($filepath);
110
-        $now = time();
111
-        $diff = $now - $filemtime;
112
-
113
-        return $diff;
114
-    }
115
-    // file doesn't exist yet!
116
-    return PHP_INT_MAX;
108
+	if (is_file($filepath)) {
109
+		$filemtime = filemtime($filepath);
110
+		$now = time();
111
+		$diff = $now - $filemtime;
112
+
113
+		return $diff;
114
+	}
115
+	// file doesn't exist yet!
116
+	return PHP_INT_MAX;
117 117
 }
118 118
 
119 119
 //#######################################################################
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
 
127 127
 function trim_stats_json($array, $timestamp)
128 128
 {
129
-    foreach ($array as $key => $value) {
130
-        if ($value['timestamp'] < $timestamp) {
131
-            unset($array[$key]);
132
-        }
133
-    }
129
+	foreach ($array as $key => $value) {
130
+		if ($value['timestamp'] < $timestamp) {
131
+			unset($array[$key]);
132
+		}
133
+	}
134 134
 
135
-    return $array;
135
+	return $array;
136 136
 }
137 137
 
138 138
 //#######################################################################
@@ -144,31 +144,31 @@  discard block
 block discarded – undo
144 144
 
145 145
 function gym_level($prestige)
146 146
 {
147
-    if (0 == $prestige) {
148
-        $gym_level = 0;
149
-    } elseif ($prestige < 2000) {
150
-        $gym_level = 1;
151
-    } elseif ($prestige < 4000) {
152
-        $gym_level = 2;
153
-    } elseif ($prestige < 8000) {
154
-        $gym_level = 3;
155
-    } elseif ($prestige < 12000) {
156
-        $gym_level = 4;
157
-    } elseif ($prestige < 16000) {
158
-        $gym_level = 5;
159
-    } elseif ($prestige < 20000) {
160
-        $gym_level = 6;
161
-    } elseif ($prestige < 30000) {
162
-        $gym_level = 7;
163
-    } elseif ($prestige < 40000) {
164
-        $gym_level = 8;
165
-    } elseif ($prestige < 50000) {
166
-        $gym_level = 9;
167
-    } else {
168
-        $gym_level = 10;
169
-    }
170
-
171
-    return $gym_level;
147
+	if (0 == $prestige) {
148
+		$gym_level = 0;
149
+	} elseif ($prestige < 2000) {
150
+		$gym_level = 1;
151
+	} elseif ($prestige < 4000) {
152
+		$gym_level = 2;
153
+	} elseif ($prestige < 8000) {
154
+		$gym_level = 3;
155
+	} elseif ($prestige < 12000) {
156
+		$gym_level = 4;
157
+	} elseif ($prestige < 16000) {
158
+		$gym_level = 5;
159
+	} elseif ($prestige < 20000) {
160
+		$gym_level = 6;
161
+	} elseif ($prestige < 30000) {
162
+		$gym_level = 7;
163
+	} elseif ($prestige < 40000) {
164
+		$gym_level = 8;
165
+	} elseif ($prestige < 50000) {
166
+		$gym_level = 9;
167
+	} else {
168
+		$gym_level = 10;
169
+	}
170
+
171
+	return $gym_level;
172 172
 }
173 173
 
174 174
 //#######################################################################
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 //#######################################################################
180 180
 function get_depth($arr)
181 181
 {
182
-    $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
183
-    $depth = 0;
184
-    foreach ($it as $v) {
185
-        $it->getDepth() > $depth && $depth = $it->getDepth();
186
-    }
182
+	$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
183
+	$depth = 0;
184
+	foreach ($it as $v) {
185
+		$it->getDepth() > $depth && $depth = $it->getDepth();
186
+	}
187 187
 
188
-    return $depth;
188
+	return $depth;
189 189
 }
190 190
 
191 191
 //#######################################################################
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
 //#######################################################################
200 200
 function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0)
201 201
 {
202
-    if ($depth == $currentDepth) { // Found depth
203
-        return tree_remove_bellow($trees, $max_pokemon);
204
-    } else { // Go deeper
205
-        $arr = array();
206
-        foreach ($trees as $temp) { // Go into all trees
207
-            $tree = $temp->evolutions;
208
-            $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
209
-            $arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
210
-        }
211
-
212
-        return $arr;
213
-    }
202
+	if ($depth == $currentDepth) { // Found depth
203
+		return tree_remove_bellow($trees, $max_pokemon);
204
+	} else { // Go deeper
205
+		$arr = array();
206
+		foreach ($trees as $temp) { // Go into all trees
207
+			$tree = $temp->evolutions;
208
+			$results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
209
+			$arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
210
+		}
211
+
212
+		return $arr;
213
+	}
214 214
 }
215 215
 
216 216
 //#######################################################################
@@ -218,28 +218,28 @@  discard block
 block discarded – undo
218 218
 //#######################################################################
219 219
 function tree_check_array($array_check, $array_add, $correct_arrow)
220 220
 {
221
-    $count = count($array_check);
222
-    $i = 0;
223
-    if (!is_null($array_check)) { // check if exists
224
-        foreach ($array_check as $res) { // Check if above, equal or bellow center
225
-            if (1 != $count && $correct_arrow) { // only add arrow once
226
-                $num = $i / ($count - 1);
227
-                if ($num < 0.5) {
228
-                    $res->array_sufix = '_up';
229
-                } elseif ($num > 0.5) {
230
-                    $res->array_sufix = '_down';
231
-                } else {
232
-                    $res->array_sufix = '';
233
-                }
234
-            } elseif (!isset($res->array_sufix)) {
235
-                $res->array_sufix = '';
236
-            }
237
-            $array_add[] = $res;
238
-            ++$i;
239
-        }
240
-    }
241
-
242
-    return $array_add;
221
+	$count = count($array_check);
222
+	$i = 0;
223
+	if (!is_null($array_check)) { // check if exists
224
+		foreach ($array_check as $res) { // Check if above, equal or bellow center
225
+			if (1 != $count && $correct_arrow) { // only add arrow once
226
+				$num = $i / ($count - 1);
227
+				if ($num < 0.5) {
228
+					$res->array_sufix = '_up';
229
+				} elseif ($num > 0.5) {
230
+					$res->array_sufix = '_down';
231
+				} else {
232
+					$res->array_sufix = '';
233
+				}
234
+			} elseif (!isset($res->array_sufix)) {
235
+				$res->array_sufix = '';
236
+			}
237
+			$array_add[] = $res;
238
+			++$i;
239
+		}
240
+	}
241
+
242
+	return $array_add;
243 243
 }
244 244
 
245 245
 //#######################################################################
@@ -247,17 +247,17 @@  discard block
 block discarded – undo
247 247
 //#######################################################################
248 248
 function tree_remove_bellow($tree, $max_pokemon)
249 249
 {
250
-    if (is_null($tree)) {
251
-        return null;
252
-    }
253
-    $arr = array();
254
-    foreach ($tree as $item) { // Check if above, equal or bellow center
255
-        if ($item->id <= $max_pokemon) {
256
-            $arr[] = $item;
257
-        }
258
-    }
259
-
260
-    return $arr;
250
+	if (is_null($tree)) {
251
+		return null;
252
+	}
253
+	$arr = array();
254
+	foreach ($tree as $item) { // Check if above, equal or bellow center
255
+		if ($item->id <= $max_pokemon) {
256
+			$arr[] = $item;
257
+		}
258
+	}
259
+
260
+	return $arr;
261 261
 }
262 262
 
263 263
 //#######################################################################
@@ -265,22 +265,22 @@  discard block
 block discarded – undo
265 265
 //#######################################################################
266 266
 function generation($id)
267 267
 {
268
-    switch ($id) {
269
-        case $id >= 1 && $id <= 151:
270
-            return [1, 'Kanto'];
271
-        case $id >= 152 && $id <= 251:
272
-            return [2, 'Johto'];
273
-        case $id >= 252 && $id <= 386:
274
-            return [3, 'Hoenn'];
275
-        case $id >= 387 && $id <= 493:
276
-            return [4, 'Sinnoh'];
277
-        case $id >= 494 && $id <= 649:
278
-            return [5, 'Teselia'];
279
-        case $id >= 650 && $id <= 721:
280
-            return [6, 'Kalos'];
281
-        case $id >= 722 && $id <= 802:
282
-            return [7, 'Alola'];
283
-    }
268
+	switch ($id) {
269
+		case $id >= 1 && $id <= 151:
270
+			return [1, 'Kanto'];
271
+		case $id >= 152 && $id <= 251:
272
+			return [2, 'Johto'];
273
+		case $id >= 252 && $id <= 386:
274
+			return [3, 'Hoenn'];
275
+		case $id >= 387 && $id <= 493:
276
+			return [4, 'Sinnoh'];
277
+		case $id >= 494 && $id <= 649:
278
+			return [5, 'Teselia'];
279
+		case $id >= 650 && $id <= 721:
280
+			return [6, 'Kalos'];
281
+		case $id >= 722 && $id <= 802:
282
+			return [7, 'Alola'];
283
+	}
284 284
 }
285 285
 
286 286
 //#######################################################################
@@ -288,38 +288,38 @@  discard block
 block discarded – undo
288 288
 //#######################################################################
289 289
 function pointIsInsidePolygon($lat, $lng, $geos, $bounds)
290 290
 {
291
-    if ($lat >= $bounds['minlat'] && $lat <= $bounds['maxlat'] && $lng >= $bounds['minlon'] && $lng <= $bounds['maxlon']) {
292
-        $intersections = 0;
293
-        $geos_count = count($geos);
294
-
295
-        for ($i = 1; $i < $geos_count; ++$i) {
296
-            $geo1 = $geos[$i - 1];
297
-            $geo2 = $geos[$i];
298
-            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
299
-                return true;
300
-            }
301
-            if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { // Check if point is on an horizontal polygon boundary
302
-                return true;
303
-            }
304
-            if ($lng > min($geo1['lng'], $geo2['lng']) and $lng <= max($geo1['lng'], $geo2['lng']) and $lat <= max($geo1['lat'], $geo2['lat']) and $geo1['lng'] != $geo2['lng']) {
305
-                $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
306
-                if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
307
-                    return true;
308
-                }
309
-                if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
310
-                    ++$intersections;
311
-                }
312
-            }
313
-        }
314
-        // If the number of edges we passed through is odd, then it's in the polygon.
315
-        if (0 != $intersections % 2) {
316
-            return true;
317
-        } else {
318
-            return false;
319
-        }
320
-    } else {
321
-        return false; // outside bounds
322
-    }
291
+	if ($lat >= $bounds['minlat'] && $lat <= $bounds['maxlat'] && $lng >= $bounds['minlon'] && $lng <= $bounds['maxlon']) {
292
+		$intersections = 0;
293
+		$geos_count = count($geos);
294
+
295
+		for ($i = 1; $i < $geos_count; ++$i) {
296
+			$geo1 = $geos[$i - 1];
297
+			$geo2 = $geos[$i];
298
+			if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
299
+				return true;
300
+			}
301
+			if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { // Check if point is on an horizontal polygon boundary
302
+				return true;
303
+			}
304
+			if ($lng > min($geo1['lng'], $geo2['lng']) and $lng <= max($geo1['lng'], $geo2['lng']) and $lat <= max($geo1['lat'], $geo2['lat']) and $geo1['lng'] != $geo2['lng']) {
305
+				$xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
306
+				if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
307
+					return true;
308
+				}
309
+				if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
310
+					++$intersections;
311
+				}
312
+			}
313
+		}
314
+		// If the number of edges we passed through is odd, then it's in the polygon.
315
+		if (0 != $intersections % 2) {
316
+			return true;
317
+		} else {
318
+			return false;
319
+		}
320
+	} else {
321
+		return false; // outside bounds
322
+	}
323 323
 }
324 324
 
325 325
 //#######################################################################
@@ -327,18 +327,18 @@  discard block
 block discarded – undo
327 327
 //#######################################################################
328 328
 function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut)
329 329
 {
330
-    if ($boundsIn['minlat'] >= $boundsOut['minlat'] && $boundsIn['maxlat'] <= $boundsOut['maxlat'] && $boundsIn['minlon'] >= $boundsOut['minlon'] && $boundsIn['maxlon'] <= $boundsOut['maxlon']) {
331
-        $insideCount = 0;
332
-        foreach ($geoIn as $coord) {
333
-            if (pointIsInsidePolygon($coord['lat'], $coord['lng'], $geoOut, $boundsOut)) {
334
-                ++$insideCount;
335
-            }
336
-        }
337
-
338
-        return $insideCount / count($geoIn) >= 0.95;
339
-    } else {
340
-        return false; // bounds outside
341
-    }
330
+	if ($boundsIn['minlat'] >= $boundsOut['minlat'] && $boundsIn['maxlat'] <= $boundsOut['maxlat'] && $boundsIn['minlon'] >= $boundsOut['minlon'] && $boundsIn['maxlon'] <= $boundsOut['maxlon']) {
331
+		$insideCount = 0;
332
+		foreach ($geoIn as $coord) {
333
+			if (pointIsInsidePolygon($coord['lat'], $coord['lng'], $geoOut, $boundsOut)) {
334
+				++$insideCount;
335
+			}
336
+		}
337
+
338
+		return $insideCount / count($geoIn) >= 0.95;
339
+	} else {
340
+		return false; // bounds outside
341
+	}
342 342
 }
343 343
 
344 344
 //#######################################################################
@@ -346,45 +346,45 @@  discard block
 block discarded – undo
346 346
 //#######################################################################
347 347
 function combineOuter($outers)
348 348
 {
349
-    $polygons = array();
350
-    $index = 0;
351
-    $count = 0;
352
-    $maxCount = count($outers);
353
-    while (0 != count($outers) && $count <= $maxCount) {
354
-        ++$count;
355
-        foreach ($outers as $key => $outer) {
356
-            if (!isset($polygons[$index])) {
357
-                $polygons[$index] = $outer;
358
-                unset($outers[$key]);
359
-            } else {
360
-                $firstEle = $outer[0];
361
-                $lastEle = $outer[count($outer) - 1];
362
-                $firstElePoly = $polygons[$index][0];
363
-                $lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
364
-                if ($firstEle == $lastElePoly) {
365
-                    $polygons[$index] = array_merge($polygons[$index], $outer);
366
-                    unset($outers[$key]);
367
-                } elseif ($lastEle == $lastElePoly) {
368
-                    $polygons[$index] = array_merge($polygons[$index], array_reverse($outer));
369
-                    unset($outers[$key]);
370
-                } elseif ($firstEle == $firstElePoly) {
371
-                    $polygons[$index] = array_merge(array_reverse($outer), $polygons[$index]);
372
-                    unset($outers[$key]);
373
-                } elseif ($lastEle == $firstElePoly) {
374
-                    $polygons[$index] = array_merge($outer, $polygons[$index]);
375
-                    unset($outers[$key]);
376
-                }
377
-            }
378
-
379
-            $firstElePoly = $polygons[$index][0];
380
-            $lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
381
-            if ($firstElePoly == $lastElePoly) {
382
-                ++$index;
383
-            }
384
-        }
385
-    }
386
-
387
-    return $polygons;
349
+	$polygons = array();
350
+	$index = 0;
351
+	$count = 0;
352
+	$maxCount = count($outers);
353
+	while (0 != count($outers) && $count <= $maxCount) {
354
+		++$count;
355
+		foreach ($outers as $key => $outer) {
356
+			if (!isset($polygons[$index])) {
357
+				$polygons[$index] = $outer;
358
+				unset($outers[$key]);
359
+			} else {
360
+				$firstEle = $outer[0];
361
+				$lastEle = $outer[count($outer) - 1];
362
+				$firstElePoly = $polygons[$index][0];
363
+				$lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
364
+				if ($firstEle == $lastElePoly) {
365
+					$polygons[$index] = array_merge($polygons[$index], $outer);
366
+					unset($outers[$key]);
367
+				} elseif ($lastEle == $lastElePoly) {
368
+					$polygons[$index] = array_merge($polygons[$index], array_reverse($outer));
369
+					unset($outers[$key]);
370
+				} elseif ($firstEle == $firstElePoly) {
371
+					$polygons[$index] = array_merge(array_reverse($outer), $polygons[$index]);
372
+					unset($outers[$key]);
373
+				} elseif ($lastEle == $firstElePoly) {
374
+					$polygons[$index] = array_merge($outer, $polygons[$index]);
375
+					unset($outers[$key]);
376
+				}
377
+			}
378
+
379
+			$firstElePoly = $polygons[$index][0];
380
+			$lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
381
+			if ($firstElePoly == $lastElePoly) {
382
+				++$index;
383
+			}
384
+		}
385
+	}
386
+
387
+	return $polygons;
388 388
 }
389 389
 
390 390
 //#######################################################################
@@ -392,63 +392,63 @@  discard block
 block discarded – undo
392 392
 //#######################################################################
393 393
 function printMenuitems($menu, $level, $locales)
394 394
 {
395
-    if (isset($menu->locale)) {
396
-        $locale = $menu->locale;
397
-        $text = $locales->$locale;
398
-    } elseif (isset($menu->text)) {
399
-        $text = $menu->text;
400
-    } else {
401
-        $text = '';
402
-    }
403
-
404
-    switch ($menu->type) {
405
-        case 'group':
406
-            ?>
395
+	if (isset($menu->locale)) {
396
+		$locale = $menu->locale;
397
+		$text = $locales->$locale;
398
+	} elseif (isset($menu->text)) {
399
+		$text = $menu->text;
400
+	} else {
401
+		$text = '';
402
+	}
403
+
404
+	switch ($menu->type) {
405
+		case 'group':
406
+			?>
407 407
 			
408 408
 			<li>
409 409
 			<a class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $text; ?></a>
410 410
 			<ul class="dropdown">
411 411
 			
412 412
 			<?php
413
-            foreach ($menu->members as $childmenu) {
414
-                printMenuitems($childmenu, $level + 1, $locales);
415
-            }
416
-            ?>
413
+			foreach ($menu->members as $childmenu) {
414
+				printMenuitems($childmenu, $level + 1, $locales);
415
+			}
416
+			?>
417 417
 			
418 418
 			</ul>
419 419
 			</li>
420 420
 
421 421
 			<?php
422
-            break;
422
+			break;
423 423
 
424
-        case 'link':
425
-            ?>
424
+		case 'link':
425
+			?>
426 426
 
427 427
 			<li>
428 428
 				<a href="<?= $menu->href; ?>" class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $text; ?></a>
429 429
 			</li>
430 430
 
431 431
 			<?php
432
-            break;
432
+			break;
433 433
 
434
-        case 'link_external':
435
-            ?>
434
+		case 'link_external':
435
+			?>
436 436
 
437 437
 			<li>
438 438
 				<a href="<?= $menu->href; ?>" target="_blank" class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $menu->text; ?></a>
439 439
 			</li>
440 440
 
441 441
 			<?php
442
-            break;
442
+			break;
443 443
 
444
-        case 'html':
445
-            ?>
444
+		case 'html':
445
+			?>
446 446
 
447 447
 			<li> <?= $menu->value; ?> </li>
448 448
 
449 449
 			<?php
450
-            break;
451
-    }
450
+			break;
451
+	}
452 452
 }
453 453
 
454 454
 ?>
Please login to merge, or discard this patch.
Braces   +20 added lines, -10 removed lines patch added patch discarded remove patch
@@ -199,11 +199,14 @@  discard block
 block discarded – undo
199 199
 //#######################################################################
200 200
 function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0)
201 201
 {
202
-    if ($depth == $currentDepth) { // Found depth
202
+    if ($depth == $currentDepth) {
203
+// Found depth
203 204
         return tree_remove_bellow($trees, $max_pokemon);
204
-    } else { // Go deeper
205
+    } else {
206
+// Go deeper
205 207
         $arr = array();
206
-        foreach ($trees as $temp) { // Go into all trees
208
+        foreach ($trees as $temp) {
209
+// Go into all trees
207 210
             $tree = $temp->evolutions;
208 211
             $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
209 212
             $arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
@@ -220,9 +223,12 @@  discard block
 block discarded – undo
220 223
 {
221 224
     $count = count($array_check);
222 225
     $i = 0;
223
-    if (!is_null($array_check)) { // check if exists
224
-        foreach ($array_check as $res) { // Check if above, equal or bellow center
225
-            if (1 != $count && $correct_arrow) { // only add arrow once
226
+    if (!is_null($array_check)) {
227
+// check if exists
228
+        foreach ($array_check as $res) {
229
+// Check if above, equal or bellow center
230
+            if (1 != $count && $correct_arrow) {
231
+// only add arrow once
226 232
                 $num = $i / ($count - 1);
227 233
                 if ($num < 0.5) {
228 234
                     $res->array_sufix = '_up';
@@ -251,7 +257,8 @@  discard block
 block discarded – undo
251 257
         return null;
252 258
     }
253 259
     $arr = array();
254
-    foreach ($tree as $item) { // Check if above, equal or bellow center
260
+    foreach ($tree as $item) {
261
+// Check if above, equal or bellow center
255 262
         if ($item->id <= $max_pokemon) {
256 263
             $arr[] = $item;
257 264
         }
@@ -295,15 +302,18 @@  discard block
 block discarded – undo
295 302
         for ($i = 1; $i < $geos_count; ++$i) {
296 303
             $geo1 = $geos[$i - 1];
297 304
             $geo2 = $geos[$i];
298
-            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
305
+            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) {
306
+// On one of the coords
299 307
                 return true;
300 308
             }
301
-            if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { // Check if point is on an horizontal polygon boundary
309
+            if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) {
310
+// Check if point is on an horizontal polygon boundary
302 311
                 return true;
303 312
             }
304 313
             if ($lng > min($geo1['lng'], $geo2['lng']) and $lng <= max($geo1['lng'], $geo2['lng']) and $lat <= max($geo1['lat'], $geo2['lat']) and $geo1['lng'] != $geo2['lng']) {
305 314
                 $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
306
-                if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
315
+                if ($xinters == $lat) {
316
+// Check if point is on the polygon boundary (other than horizontal)
307 317
                     return true;
308 318
                 }
309 319
                 if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
Please login to merge, or discard this patch.
core/process/data.loader.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@  discard block
 block discarded – undo
10 10
 $trees = json_decode($pokedex_tree_file);
11 11
 
12 12
 if (!defined('SYS_PATH')) {
13
-    echo 'Error: config.php does not exist or failed to load.<br>';
14
-    echo 'Check whether you renamed the config.example.php file!';
15
-    exit();
13
+	echo 'Error: config.php does not exist or failed to load.<br>';
14
+	echo 'Check whether you renamed the config.example.php file!';
15
+	exit();
16 16
 }
17 17
 if (!isset($config->system)) {
18
-    echo 'Error: Could not load core/json/variables.json.<br>';
19
-    echo 'json_last_error(): '.json_last_error().'<br>';
20
-    echo 'Check the file encoding as well. It have to be UTF-8 without BOM!';
21
-    exit();
18
+	echo 'Error: Could not load core/json/variables.json.<br>';
19
+	echo 'json_last_error(): '.json_last_error().'<br>';
20
+	echo 'Check the file encoding as well. It have to be UTF-8 without BOM!';
21
+	exit();
22 22
 }
23 23
 
24 24
 // Manage Time Interval
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 //############
31 31
 
32 32
 if (SYS_DEVELOPMENT_MODE) {
33
-    error_reporting(E_ALL);
33
+	error_reporting(E_ALL);
34 34
 }
35 35
 
36 36
 // Perform some tests to be sure that we got datas and rights
@@ -39,20 +39,20 @@  discard block
 block discarded – undo
39 39
 //#############################################################
40 40
 
41 41
 if (!file_exists(SYS_PATH.'/install/done.lock')) {
42
-    // run install tests
43
-    include_once 'install/tester.php';
44
-    run_tests();
45
-
46
-    // check for error
47
-    if (file_exists(SYS_PATH.'/install/website.lock')) {
48
-        echo file_get_contents(SYS_PATH.'/install/website.lock');
49
-        exit();
50
-    } else {
51
-        $content = time();
52
-        file_put_contents(SYS_PATH.'/install/done.lock', $content);
53
-        // everything seems to be fine let's run an initial cronjob
54
-        include_once SYS_PATH.'/core/cron/crontabs.include.php';
55
-    }
42
+	// run install tests
43
+	include_once 'install/tester.php';
44
+	run_tests();
45
+
46
+	// check for error
47
+	if (file_exists(SYS_PATH.'/install/website.lock')) {
48
+		echo file_get_contents(SYS_PATH.'/install/website.lock');
49
+		exit();
50
+	} else {
51
+		$content = time();
52
+		file_put_contents(SYS_PATH.'/install/done.lock', $content);
53
+		// everything seems to be fine let's run an initial cronjob
54
+		include_once SYS_PATH.'/core/cron/crontabs.include.php';
55
+	}
56 56
 }
57 57
 
58 58
 // Load the locale elements
@@ -73,324 +73,324 @@  discard block
 block discarded – undo
73 73
 //#########################
74 74
 
75 75
 if (isset($_GET['page'])) {
76
-    $page = htmlentities($_GET['page']);
76
+	$page = htmlentities($_GET['page']);
77 77
 } else {
78
-    $page = '';
78
+	$page = '';
79 79
 }
80 80
 
81 81
 if (!empty($page)) {
82
-    switch ($page) {
83
-        // Single Pokemon
84
-        //################
82
+	switch ($page) {
83
+		// Single Pokemon
84
+		//################
85 85
 
86
-        case 'pokemon':
87
-            // Current Pokemon datas
88
-            // ---------------------
86
+		case 'pokemon':
87
+			// Current Pokemon datas
88
+			// ---------------------
89 89
 
90
-            $pokemon_id = $manager->getEcapedString($_GET['id']);
90
+			$pokemon_id = $manager->getEcapedString($_GET['id']);
91 91
 
92
-            if (!is_object($pokemons->pokemon->$pokemon_id)) {
93
-                header('Location:/404');
94
-                exit();
95
-            }
92
+			if (!is_object($pokemons->pokemon->$pokemon_id)) {
93
+				header('Location:/404');
94
+				exit();
95
+			}
96 96
 
97
-            $pokemon = new stdClass();
98
-            $pokemon = $pokemons->pokemon->$pokemon_id;
99
-            $pokemon->id = $pokemon_id;
97
+			$pokemon = new stdClass();
98
+			$pokemon = $pokemons->pokemon->$pokemon_id;
99
+			$pokemon->id = $pokemon_id;
100 100
 
101
-            // Gen
102
-            // ----
101
+			// Gen
102
+			// ----
103 103
 
104
-            $gen = generation($pokemon_id);
105
-            $pokemon->gen = $gen[0].' ('.$gen[1].')';
104
+			$gen = generation($pokemon_id);
105
+			$pokemon->gen = $gen[0].' ('.$gen[1].')';
106 106
 
107
-            // Some math
108
-            // ----------
107
+			// Some math
108
+			// ----------
109 109
 
110
-            $pokemon->max_cp_percent = percent(4548, $pokemon->max_cp); //Slaking #289
111
-            $pokemon->max_hp_percent = percent(415, $pokemon->max_hp); //Blissey #242
110
+			$pokemon->max_cp_percent = percent(4548, $pokemon->max_cp); //Slaking #289
111
+			$pokemon->max_hp_percent = percent(415, $pokemon->max_hp); //Blissey #242
112 112
 
113
-            // Set tree
114
-            // ----------
113
+			// Set tree
114
+			// ----------
115 115
 
116
-            $candy_id = $pokemon->candy_id;
117
-            $pokemon->tree = $trees->$candy_id;
116
+			$candy_id = $pokemon->candy_id;
117
+			$pokemon->tree = $trees->$candy_id;
118 118
 
119
-            // Get Dabase results
120
-            //-------------------
119
+			// Get Dabase results
120
+			//-------------------
121 121
 
122
-            // Total gym protected
122
+			// Total gym protected
123 123
 
124
-            $data = $manager->getGymsProtectedByPokemon($pokemon_id);
125
-            $pokemon->protected_gyms = $data->total;
124
+			$data = $manager->getGymsProtectedByPokemon($pokemon_id);
125
+			$pokemon->protected_gyms = $data->total;
126 126
 
127
-            // Spawn rate
127
+			// Spawn rate
128 128
 
129
-            if ($pokemon->spawn_count > 0 && 0 == $pokemon->per_day) {
130
-                $pokemon->spawns_per_day = '<1';
131
-            } else {
132
-                $pokemon->spawns_per_day = $pokemon->per_day;
133
-            }
129
+			if ($pokemon->spawn_count > 0 && 0 == $pokemon->per_day) {
130
+				$pokemon->spawns_per_day = '<1';
131
+			} else {
132
+				$pokemon->spawns_per_day = $pokemon->per_day;
133
+			}
134 134
 
135
-            // Related Pokemons
136
-            // ----------------
135
+			// Related Pokemons
136
+			// ----------------
137 137
 
138
-            foreach ($pokemon->types as $type) {
139
-                $types[] = $type;
140
-            }
138
+			foreach ($pokemon->types as $type) {
139
+				$types[] = $type;
140
+			}
141 141
 
142
-            $related = array();
143
-            foreach ($pokemons->pokemon as $pokeid => $test_pokemon) {
144
-                if (!empty($test_pokemon->types)) {
145
-                    foreach ($test_pokemon->types as $type) {
146
-                        if (in_array($type, $types) && $pokeid <= $config->system->max_pokemon) {
147
-                            if (!in_array($pokeid, $related)) {
148
-                                $related[] = $pokeid;
149
-                            }
150
-                        }
151
-                    }
152
-                }
153
-            }
154
-            sort($related);
142
+			$related = array();
143
+			foreach ($pokemons->pokemon as $pokeid => $test_pokemon) {
144
+				if (!empty($test_pokemon->types)) {
145
+					foreach ($test_pokemon->types as $type) {
146
+						if (in_array($type, $types) && $pokeid <= $config->system->max_pokemon) {
147
+							if (!in_array($pokeid, $related)) {
148
+								$related[] = $pokeid;
149
+							}
150
+						}
151
+					}
152
+				}
153
+			}
154
+			sort($related);
155 155
 
156
-            // Top50 Pokemon List
157
-            // Don't run the query for super common pokemon because it's too heavy
156
+			// Top50 Pokemon List
157
+			// Don't run the query for super common pokemon because it's too heavy
158 158
 
159
-            // Make it sortable; default sort: cp DESC
160
-            $top_possible_sort = array('IV', 'cp', 'individual_attack', 'individual_defense', 'individual_stamina', 'move_1', 'move_2', 'disappear_time');
161
-            $top_order = isset($_GET['order']) ? $_GET['order'] : '';
162
-            $top_order_by = in_array($top_order, $top_possible_sort) ? $_GET['order'] : 'cp';
163
-            $top_direction = isset($_GET['direction']) ? 'ASC' : 'DESC';
164
-            $top_direction = !isset($_GET['order']) && !isset($_GET['direction']) ? 'DESC' : $top_direction;
159
+			// Make it sortable; default sort: cp DESC
160
+			$top_possible_sort = array('IV', 'cp', 'individual_attack', 'individual_defense', 'individual_stamina', 'move_1', 'move_2', 'disappear_time');
161
+			$top_order = isset($_GET['order']) ? $_GET['order'] : '';
162
+			$top_order_by = in_array($top_order, $top_possible_sort) ? $_GET['order'] : 'cp';
163
+			$top_direction = isset($_GET['direction']) ? 'ASC' : 'DESC';
164
+			$top_direction = !isset($_GET['order']) && !isset($_GET['direction']) ? 'DESC' : $top_direction;
165 165
 
166
-            $best_possible_sort = array('trainer_name', 'IV', 'cp', 'move_1', 'move_2', 'last_seen');
167
-            $best_order = isset($_GET['order']) ? $_GET['order'] : '';
168
-            $best_order_by = in_array($best_order, $best_possible_sort) ? $_GET['order'] : 'cp';
169
-            $best_direction = isset($_GET['direction']) ? 'ASC' : 'DESC';
170
-            $best_direction = !isset($_GET['order']) && !isset($_GET['direction']) ? 'DESC' : $best_direction;
166
+			$best_possible_sort = array('trainer_name', 'IV', 'cp', 'move_1', 'move_2', 'last_seen');
167
+			$best_order = isset($_GET['order']) ? $_GET['order'] : '';
168
+			$best_order_by = in_array($best_order, $best_possible_sort) ? $_GET['order'] : 'cp';
169
+			$best_direction = isset($_GET['direction']) ? 'ASC' : 'DESC';
170
+			$best_direction = !isset($_GET['order']) && !isset($_GET['direction']) ? 'DESC' : $best_direction;
171 171
 
172
-            if ($pokemon->spawn_rate < 0.20) {
173
-                $top = $manager->getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
174
-            } else {
175
-                $top = array();
176
-            }
172
+			if ($pokemon->spawn_rate < 0.20) {
173
+				$top = $manager->getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
174
+			} else {
175
+				$top = array();
176
+			}
177 177
 
178
-            // Trainer with highest Pokemon
178
+			// Trainer with highest Pokemon
179 179
 
180
-            $toptrainer = $manager->getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
180
+			$toptrainer = $manager->getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
181 181
 
182
-            break;
182
+			break;
183 183
 
184
-        // Pokedex
185
-        //#########
184
+		// Pokedex
185
+		//#########
186 186
 
187
-        case 'pokedex':
188
-            // Pokemon List from the JSON file
189
-            // --------------------------------
187
+		case 'pokedex':
188
+			// Pokemon List from the JSON file
189
+			// --------------------------------
190 190
 
191
-            $max = $config->system->max_pokemon;
192
-            $pokedex = new stdClass();
191
+			$max = $config->system->max_pokemon;
192
+			$pokedex = new stdClass();
193 193
 
194
-            for ($i = 1; $i <= $max; ++$i) {
195
-                $pokedex->$i = new stdClass();
196
-                $pokedex->$i->id = $i;
197
-                $pokedex->$i->permalink = 'pokemon/'.$i;
198
-                $pokedex->$i->img = $pokemons->pokemon->$i->img;
199
-                $pokedex->$i->name = $pokemons->pokemon->$i->name;
200
-                $pokedex->$i->spawn = ($pokemons->pokemon->$i->spawn_count > 0) ? 1 : 0;
201
-                $pokedex->$i->spawn_count = $pokemons->pokemon->$i->spawn_count;
202
-            }
194
+			for ($i = 1; $i <= $max; ++$i) {
195
+				$pokedex->$i = new stdClass();
196
+				$pokedex->$i->id = $i;
197
+				$pokedex->$i->permalink = 'pokemon/'.$i;
198
+				$pokedex->$i->img = $pokemons->pokemon->$i->img;
199
+				$pokedex->$i->name = $pokemons->pokemon->$i->name;
200
+				$pokedex->$i->spawn = ($pokemons->pokemon->$i->spawn_count > 0) ? 1 : 0;
201
+				$pokedex->$i->spawn_count = $pokemons->pokemon->$i->spawn_count;
202
+			}
203 203
 
204
-            break;
204
+			break;
205 205
 
206
-        // Pokestops
207
-        //###########
206
+		// Pokestops
207
+		//###########
208 208
 
209
-        case 'pokestops':
210
-            $pokestop = new stdClass();
209
+		case 'pokestops':
210
+			$pokestop = new stdClass();
211 211
 
212
-            $data = $manager->getTotalPokestops();
213
-            $pokestop->total = $data->total;
212
+			$data = $manager->getTotalPokestops();
213
+			$pokestop->total = $data->total;
214 214
 
215
-            $data = $manager->getTotalLures();
216
-            $pokestop->lured = $data->total;
215
+			$data = $manager->getTotalLures();
216
+			$pokestop->lured = $data->total;
217 217
 
218
-            break;
218
+			break;
219 219
 
220
-        // Gyms
221
-        //#######
220
+		// Gyms
221
+		//#######
222 222
 
223
-        case 'gym':
224
-            // 3 Teams (teamm rocket is neutral)
225
-            // 1 Fight
223
+		case 'gym':
224
+			// 3 Teams (teamm rocket is neutral)
225
+			// 1 Fight
226 226
 
227
-            $teams = new stdClass();
227
+			$teams = new stdClass();
228 228
 
229
-            $teams->mystic = new stdClass();
230
-            $teams->mystic->guardians = new stdClass();
231
-            $teams->mystic->id = 1;
229
+			$teams->mystic = new stdClass();
230
+			$teams->mystic->guardians = new stdClass();
231
+			$teams->mystic->id = 1;
232 232
 
233
-            $teams->valor = new stdClass();
234
-            $teams->valor->guardians = new stdClass();
235
-            $teams->valor->id = 2;
233
+			$teams->valor = new stdClass();
234
+			$teams->valor->guardians = new stdClass();
235
+			$teams->valor->id = 2;
236 236
 
237
-            $teams->instinct = new stdClass();
238
-            $teams->instinct->guardians = new stdClass();
239
-            $teams->instinct->id = 3;
237
+			$teams->instinct = new stdClass();
238
+			$teams->instinct->guardians = new stdClass();
239
+			$teams->instinct->id = 3;
240 240
 
241
-            $teams->rocket = new stdClass();
242
-            $teams->rocket->guardians = new stdClass();
243
-            $teams->rocket->id = 0;
241
+			$teams->rocket = new stdClass();
242
+			$teams->rocket->guardians = new stdClass();
243
+			$teams->rocket->id = 0;
244 244
 
245
-            foreach ($teams as $team_key => $team_values) {
246
-                // Team Guardians
247
-                $i = 0;
248
-                $datas = $manager->getTeamGuardians($team_values->id);
249
-                foreach ($datas as $data) {
250
-                    $teams->$team_key->guardians->$i = $data->guard_pokemon_id;
245
+			foreach ($teams as $team_key => $team_values) {
246
+				// Team Guardians
247
+				$i = 0;
248
+				$datas = $manager->getTeamGuardians($team_values->id);
249
+				foreach ($datas as $data) {
250
+					$teams->$team_key->guardians->$i = $data->guard_pokemon_id;
251 251
 
252
-                    ++$i;
253
-                }
252
+					++$i;
253
+				}
254 254
 
255
-                // Gym owned and average points
256
-                $data = $manager->getOwnedAndPoints($team_values->id);
255
+				// Gym owned and average points
256
+				$data = $manager->getOwnedAndPoints($team_values->id);
257 257
 
258
-                $teams->$team_key->gym_owned = $data->total;
259
-                $teams->$team_key->average = $data->average_points;
260
-            }
258
+				$teams->$team_key->gym_owned = $data->total;
259
+				$teams->$team_key->average = $data->average_points;
260
+			}
261 261
 
262
-            break;
262
+			break;
263 263
 
264
-        case 'dashboard':
265
-            // This case is only used for test purpose.
264
+		case 'dashboard':
265
+			// This case is only used for test purpose.
266 266
 
267
-            $stats_file = SYS_PATH.'/core/json/gym.stats.json';
267
+			$stats_file = SYS_PATH.'/core/json/gym.stats.json';
268 268
 
269
-            if (!is_file($stats_file)) {
270
-                echo 'Sorry, no Gym stats file was found. <br> Did you enable cron? ';
271
-                exit();
272
-            }
269
+			if (!is_file($stats_file)) {
270
+				echo 'Sorry, no Gym stats file was found. <br> Did you enable cron? ';
271
+				exit();
272
+			}
273 273
 
274
-            $stats_file = SYS_PATH.'/core/json/pokemon.stats.json';
274
+			$stats_file = SYS_PATH.'/core/json/pokemon.stats.json';
275 275
 
276
-            if (!is_file($stats_file)) {
277
-                echo 'Sorry, no Pokémon stats file was found. <br> Did you enabled cron?';
278
-                exit();
279
-            }
276
+			if (!is_file($stats_file)) {
277
+				echo 'Sorry, no Pokémon stats file was found. <br> Did you enabled cron?';
278
+				exit();
279
+			}
280 280
 
281
-            $stats_file = SYS_PATH.'/core/json/pokestop.stats.json';
281
+			$stats_file = SYS_PATH.'/core/json/pokestop.stats.json';
282 282
 
283
-            if (!is_file($stats_file)) {
284
-                echo 'Sorry, no Pokéstop stats file was found. <br> Did you enabled cron?';
285
-                exit();
286
-            }
283
+			if (!is_file($stats_file)) {
284
+				echo 'Sorry, no Pokéstop stats file was found. <br> Did you enabled cron?';
285
+				exit();
286
+			}
287 287
 
288
-            if ($config->system->captcha_support) {
289
-                $stats_file = SYS_PATH.'/core/json/captcha.stats.json';
288
+			if ($config->system->captcha_support) {
289
+				$stats_file = SYS_PATH.'/core/json/captcha.stats.json';
290 290
 
291
-                if (!is_file($stats_file)) {
292
-                    echo 'Sorry, no Captcha stats file were found  <br> Have you enable cron?';
293
-                    exit();
294
-                }
295
-            }
291
+				if (!is_file($stats_file)) {
292
+					echo 'Sorry, no Captcha stats file were found  <br> Have you enable cron?';
293
+					exit();
294
+				}
295
+			}
296 296
 
297
-            break;
298
-    }
297
+			break;
298
+	}
299 299
 } /////////////
300 300
 // Homepage
301 301
 /////////////
302 302
 
303 303
 else {
304
-    $home = new stdClass();
305
-
306
-    // Right now
307
-    // ---------
308
-    $data = $manager->getTotalPokemon();
309
-    $home->pokemon_now = $data->total;
310
-
311
-    // Lured stops
312
-    // -----------
313
-    $data = $manager->getTotalLures();
314
-    $home->pokestop_lured = $data->total;
315
-
316
-    // Active Raids
317
-    // -----------
318
-    $data = $manager->getTotalRaids();
319
-    $home->active_raids = $data->total;
320
-
321
-    // Gyms
322
-    // ----
323
-    $data = $manager->getTotalGyms();
324
-    $home->gyms = $data->total;
325
-
326
-    // Recent spawns
327
-    // ------------
328
-
329
-    $recents = array();
330
-    if ($config->system->recents_filter) {
331
-        // get all mythic pokemon ids
332
-        $mythic_pokemons = array();
333
-        foreach ($pokemons->pokemon as $id => $pokemon) {
334
-            if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
335
-                $mythic_pokemons[] = $id;
336
-            }
337
-        }
338
-        // get all mythic pokemon
339
-        $result = $manager->getRecentMythic($mythic_pokemons);
340
-    } else {
341
-        // get all pokemon
342
-        $result = $manager->getRecentAll();
343
-    }
344
-    $recents = array();
345
-
346
-    if (count($result) > 0) {
347
-        foreach ($result as $data) {
348
-            $recent = new stdClass();
349
-            $recent->id = $data->pokemon_id;
350
-            $recent->uid = $data->encounter_id;
351
-            $recent->last_seen = strtotime($data->disappear_time_real);
352
-
353
-            $location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
354
-            $location_link = str_replace('{latitude}', $data->latitude, $location_link);
355
-            $location_link = str_replace('{longitude}', $data->longitude, $location_link);
356
-            $recent->location_link = $location_link;
357
-
358
-            if ($config->system->recents_encounter_details) {
359
-                $recent->encdetails = new stdClass();
360
-                $recent->encdetails->cp = $data->cp;
361
-                $recent->encdetails->attack = $data->individual_attack;
362
-                $recent->encdetails->defense = $data->individual_defense;
363
-                $recent->encdetails->stamina = $data->individual_stamina;
364
-                if (isset($recent->encdetails->cp) && isset($recent->encdetails->attack) && isset($recent->encdetails->defense) && isset($recent->encdetails->stamina)) {
365
-                    $recent->encdetails->available = true;
366
-                } else {
367
-                    $recent->encdetails->available = false;
368
-                }
369
-            }
370
-
371
-            $recents[] = $recent;
372
-        }
373
-    }
374
-
375
-    // Team battle
376
-    // -----------
377
-
378
-    $home->teams = new stdClass();
379
-
380
-    // Team
381
-    // 1 = bleu
382
-    // 2 = rouge
383
-    // 3 = jaune
384
-
385
-    $data = $manager->getTotalGymsForTeam(1);
386
-    $home->teams->mystic = $data->total;
387
-
388
-    $data = $manager->getTotalGymsForTeam(2);
389
-    $home->teams->valor = $data->total;
390
-
391
-    $data = $manager->getTotalGymsForTeam(3);
392
-    $home->teams->instinct = $data->total;
393
-
394
-    $data = $manager->getTotalGymsForTeam(0);
395
-    $home->teams->rocket = $data->total;
304
+	$home = new stdClass();
305
+
306
+	// Right now
307
+	// ---------
308
+	$data = $manager->getTotalPokemon();
309
+	$home->pokemon_now = $data->total;
310
+
311
+	// Lured stops
312
+	// -----------
313
+	$data = $manager->getTotalLures();
314
+	$home->pokestop_lured = $data->total;
315
+
316
+	// Active Raids
317
+	// -----------
318
+	$data = $manager->getTotalRaids();
319
+	$home->active_raids = $data->total;
320
+
321
+	// Gyms
322
+	// ----
323
+	$data = $manager->getTotalGyms();
324
+	$home->gyms = $data->total;
325
+
326
+	// Recent spawns
327
+	// ------------
328
+
329
+	$recents = array();
330
+	if ($config->system->recents_filter) {
331
+		// get all mythic pokemon ids
332
+		$mythic_pokemons = array();
333
+		foreach ($pokemons->pokemon as $id => $pokemon) {
334
+			if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
335
+				$mythic_pokemons[] = $id;
336
+			}
337
+		}
338
+		// get all mythic pokemon
339
+		$result = $manager->getRecentMythic($mythic_pokemons);
340
+	} else {
341
+		// get all pokemon
342
+		$result = $manager->getRecentAll();
343
+	}
344
+	$recents = array();
345
+
346
+	if (count($result) > 0) {
347
+		foreach ($result as $data) {
348
+			$recent = new stdClass();
349
+			$recent->id = $data->pokemon_id;
350
+			$recent->uid = $data->encounter_id;
351
+			$recent->last_seen = strtotime($data->disappear_time_real);
352
+
353
+			$location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
354
+			$location_link = str_replace('{latitude}', $data->latitude, $location_link);
355
+			$location_link = str_replace('{longitude}', $data->longitude, $location_link);
356
+			$recent->location_link = $location_link;
357
+
358
+			if ($config->system->recents_encounter_details) {
359
+				$recent->encdetails = new stdClass();
360
+				$recent->encdetails->cp = $data->cp;
361
+				$recent->encdetails->attack = $data->individual_attack;
362
+				$recent->encdetails->defense = $data->individual_defense;
363
+				$recent->encdetails->stamina = $data->individual_stamina;
364
+				if (isset($recent->encdetails->cp) && isset($recent->encdetails->attack) && isset($recent->encdetails->defense) && isset($recent->encdetails->stamina)) {
365
+					$recent->encdetails->available = true;
366
+				} else {
367
+					$recent->encdetails->available = false;
368
+				}
369
+			}
370
+
371
+			$recents[] = $recent;
372
+		}
373
+	}
374
+
375
+	// Team battle
376
+	// -----------
377
+
378
+	$home->teams = new stdClass();
379
+
380
+	// Team
381
+	// 1 = bleu
382
+	// 2 = rouge
383
+	// 3 = jaune
384
+
385
+	$data = $manager->getTotalGymsForTeam(1);
386
+	$home->teams->mystic = $data->total;
387
+
388
+	$data = $manager->getTotalGymsForTeam(2);
389
+	$home->teams->valor = $data->total;
390
+
391
+	$data = $manager->getTotalGymsForTeam(3);
392
+	$home->teams->instinct = $data->total;
393
+
394
+	$data = $manager->getTotalGymsForTeam(0);
395
+	$home->teams->rocket = $data->total;
396 396
 }
Please login to merge, or discard this patch.
core/process/aru.php 2 patches
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $pos = !empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], getenv('HTTP_HOST'));
9 9
 
10 10
 if (false === $pos) {
11
-    http_response_code(401);
12
-    die('Restricted access');
11
+	http_response_code(401);
12
+	die('Restricted access');
13 13
 }
14 14
 
15 15
 include_once '../../config.php';
@@ -42,130 +42,130 @@  discard block
 block discarded – undo
42 42
 
43 43
 $request = '';
44 44
 if (isset($_GET['type'])) {
45
-    $request = $_GET['type'];
45
+	$request = $_GET['type'];
46 46
 }
47 47
 $postRequest = '';
48 48
 if (isset($_POST['type'])) {
49
-    $postRequest = $_POST['type'];
50
-    $request = 'postRequest';
49
+	$postRequest = $_POST['type'];
50
+	$request = 'postRequest';
51 51
 }
52 52
 switch ($request) {
53
-    //###########################
54
-    //
55
-    // Update datas on homepage
56
-    //
57
-    //###########################
58
-
59
-    case 'home_update':
60
-        $values = [];
61
-        // Right now
62
-        // ---------
63
-        $data = $manager->getTotalPokemon();
64
-        $values[] = $data->total;
65
-
66
-        // Lured stops
67
-        // -----------
68
-        $data = $manager->getTotalLures();
69
-        $values[] = $data->total;
70
-
71
-        // Active Raids
72
-        // -----------
73
-        $data = $manager->getTotalRaids();
74
-        $values[] = $data->total;
75
-
76
-        // Team battle
77
-        // -----------
78
-        $data = $manager->getTotalGyms();
79
-        $values[] = $data->total;
80
-
81
-        // Red
82
-        $data = $manager->getTotalGymsForTeam(2);
83
-        $values[] = $data->total;
84
-
85
-        // Blue
86
-        $data = $manager->getTotalGymsForTeam(1);
87
-        $values[] = $data->total;
88
-
89
-        // Yellow
90
-        $data = $manager->getTotalGymsForTeam(3);
91
-        $values[] = $data->total;
92
-
93
-        // Neutral
94
-        $data = $manager->getTotalGymsForTeam(0);
95
-        $values[] = $data->total;
96
-
97
-        header('Content-Type: application/json');
98
-        echo json_encode($values);
99
-
100
-        break;
101
-
102
-    //###################################
103
-    //
104
-    // Update latests spawn on homepage
105
-    //
106
-    //###################################
107
-
108
-    case 'spawnlist_update':
109
-        // Recent spawn
110
-        // ------------
111
-        $total_spawns = array();
112
-        $last_uid_param = '';
113
-        if (isset($_GET['last_uid'])) {
114
-            $last_uid_param = $_GET['last_uid'];
115
-        }
116
-        if ($config->system->recents_filter) {
117
-            // get all mythic pokemon ids
118
-            $mythic_pokemons = array();
119
-            foreach ($pokemons->pokemon as $id => $pokemon) {
120
-                if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
121
-                    $mythic_pokemons[] = $id;
122
-                }
123
-            }
124
-
125
-            // get last mythic pokemon
126
-            $result = $manager->getRecentMythic($mythic_pokemons);
127
-        } else {
128
-            // get last pokemon
129
-            $result = $manager->getRecentAll();
130
-        }
131
-
132
-        if (count($result) > 0) {
133
-            foreach ($result as $data) {
134
-                $new_spawn = array();
135
-                $pokeid = $data->pokemon_id;
136
-                $pokeuid = $data->encounter_id;
137
-
138
-                if ($last_uid_param != $pokeuid) {
139
-                    $last_seen = strtotime($data->disappear_time_real);
140
-
141
-                    $location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
142
-                    $location_link = str_replace('{latitude}', $data->latitude, $location_link);
143
-                    $location_link = str_replace('{longitude}', $data->longitude, $location_link);
144
-
145
-                    if ($config->system->recents_encounter_details) {
146
-                        $encdetails = new stdClass();
147
-                        $encdetails->cp = $data->cp;
148
-                        $encdetails->attack = $data->individual_attack;
149
-                        $encdetails->defense = $data->individual_defense;
150
-                        $encdetails->stamina = $data->individual_stamina;
151
-                        if (isset($encdetails->cp) && isset($encdetails->attack) && isset($encdetails->defense) && isset($encdetails->stamina)) {
152
-                            $encdetails->available = true;
153
-                        } else {
154
-                            $encdetails->available = false;
155
-                        }
156
-                    }
157
-
158
-                    $html = '
53
+	//###########################
54
+	//
55
+	// Update datas on homepage
56
+	//
57
+	//###########################
58
+
59
+	case 'home_update':
60
+		$values = [];
61
+		// Right now
62
+		// ---------
63
+		$data = $manager->getTotalPokemon();
64
+		$values[] = $data->total;
65
+
66
+		// Lured stops
67
+		// -----------
68
+		$data = $manager->getTotalLures();
69
+		$values[] = $data->total;
70
+
71
+		// Active Raids
72
+		// -----------
73
+		$data = $manager->getTotalRaids();
74
+		$values[] = $data->total;
75
+
76
+		// Team battle
77
+		// -----------
78
+		$data = $manager->getTotalGyms();
79
+		$values[] = $data->total;
80
+
81
+		// Red
82
+		$data = $manager->getTotalGymsForTeam(2);
83
+		$values[] = $data->total;
84
+
85
+		// Blue
86
+		$data = $manager->getTotalGymsForTeam(1);
87
+		$values[] = $data->total;
88
+
89
+		// Yellow
90
+		$data = $manager->getTotalGymsForTeam(3);
91
+		$values[] = $data->total;
92
+
93
+		// Neutral
94
+		$data = $manager->getTotalGymsForTeam(0);
95
+		$values[] = $data->total;
96
+
97
+		header('Content-Type: application/json');
98
+		echo json_encode($values);
99
+
100
+		break;
101
+
102
+	//###################################
103
+	//
104
+	// Update latests spawn on homepage
105
+	//
106
+	//###################################
107
+
108
+	case 'spawnlist_update':
109
+		// Recent spawn
110
+		// ------------
111
+		$total_spawns = array();
112
+		$last_uid_param = '';
113
+		if (isset($_GET['last_uid'])) {
114
+			$last_uid_param = $_GET['last_uid'];
115
+		}
116
+		if ($config->system->recents_filter) {
117
+			// get all mythic pokemon ids
118
+			$mythic_pokemons = array();
119
+			foreach ($pokemons->pokemon as $id => $pokemon) {
120
+				if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
121
+					$mythic_pokemons[] = $id;
122
+				}
123
+			}
124
+
125
+			// get last mythic pokemon
126
+			$result = $manager->getRecentMythic($mythic_pokemons);
127
+		} else {
128
+			// get last pokemon
129
+			$result = $manager->getRecentAll();
130
+		}
131
+
132
+		if (count($result) > 0) {
133
+			foreach ($result as $data) {
134
+				$new_spawn = array();
135
+				$pokeid = $data->pokemon_id;
136
+				$pokeuid = $data->encounter_id;
137
+
138
+				if ($last_uid_param != $pokeuid) {
139
+					$last_seen = strtotime($data->disappear_time_real);
140
+
141
+					$location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
142
+					$location_link = str_replace('{latitude}', $data->latitude, $location_link);
143
+					$location_link = str_replace('{longitude}', $data->longitude, $location_link);
144
+
145
+					if ($config->system->recents_encounter_details) {
146
+						$encdetails = new stdClass();
147
+						$encdetails->cp = $data->cp;
148
+						$encdetails->attack = $data->individual_attack;
149
+						$encdetails->defense = $data->individual_defense;
150
+						$encdetails->stamina = $data->individual_stamina;
151
+						if (isset($encdetails->cp) && isset($encdetails->attack) && isset($encdetails->defense) && isset($encdetails->stamina)) {
152
+							$encdetails->available = true;
153
+						} else {
154
+							$encdetails->available = false;
155
+						}
156
+					}
157
+
158
+					$html = '
159 159
                     <div class="col-md-1 col-xs-4 pokemon-single" data-pokeid="'.$pokeid.'" data-pokeuid="'.$pokeuid.'" style="display: none;">
160 160
                     <a href="pokemon/'.$pokeid.'"><img src="'.$pokemons->pokemon->$pokeid->img.'" alt="'.$pokemons->pokemon->$pokeid->name.'" class="img-responsive"></a>
161 161
                     <a href="pokemon/'.$pokeid.'"><p class="pkmn-name">'.$pokemons->pokemon->$pokeid->name.'</p></a>
162 162
                     <a href="'.$location_link.'" target="_blank">
163 163
                         <small class="pokemon-timer">00:00:00</small>
164 164
                     </a>';
165
-                    if ($config->system->recents_encounter_details) {
166
-                        if ($encdetails->available) {
167
-                            if ($config->system->iv_numbers) {
168
-                                $html .= '
165
+					if ($config->system->recents_encounter_details) {
166
+						if ($encdetails->available) {
167
+							if ($config->system->iv_numbers) {
168
+								$html .= '
169 169
                                 <div class="progress" style="height: 15px; margin-bottom: 0">
170 170
                                     <div title="'.$locales->IV_ATTACK.': '.$encdetails->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px">
171 171
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$encdetails->attack.'</span>'.$encdetails->attack.'
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$encdetails->stamina.'</span>'.$encdetails->stamina.'
178 178
                                     </div>
179 179
                                 </div>';
180
-                            } else {
181
-                                $html .= '
180
+							} else {
181
+								$html .= '
182 182
                                 <div class="progress" style="height: 6px; width: 80%; margin: 5px auto 0 auto">
183 183
                                 <div title="'.$locales->IV_ATTACK.': '.$encdetails->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(((100 / 15) * $encdetails->attack) / 3).'%">
184 184
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$encdetails->attack.'</span>
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$encdetails->stamina.'</span>
191 191
                                 </div>
192 192
                                 </div>';
193
-                            }
194
-                            $html .= '<small>'.$encdetails->cp.'</small>';
195
-                        } else {
196
-                            if ($config->system->iv_numbers) {
197
-                                $html .= '
193
+							}
194
+							$html .= '<small>'.$encdetails->cp.'</small>';
195
+						} else {
196
+							if ($config->system->iv_numbers) {
197
+								$html .= '
198 198
                                 <div class="progress" style="height: 15px; margin-bottom: 0">
199 199
                                     <div title="'.$locales->IV_ATTACK.': not available" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px">
200 200
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$locales->NOT_AVAILABLE.'</span>?
@@ -206,202 +206,202 @@  discard block
 block discarded – undo
206 206
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$locales->NOT_AVAILABLE.'</span>?
207 207
                                     </div>
208 208
                                 </div>';
209
-                            } else {
210
-                                $html .= '
209
+							} else {
210
+								$html .= '
211 211
                             <div class="progress" style="height: 6px; width: 80%; margin: 5px auto 0 auto">
212 212
                                 <div title="IV not available" class="progress-bar" role="progressbar" style="width: 100%; background-color: rgb(210,210,210)" aria-valuenow="1" aria-valuemin="0" aria-valuemax="1">
213 213
                                     <span class="sr-only">IV '.$locales->NOT_AVAILABLE.'</span>
214 214
                                 </div>
215 215
                             </div>';
216
-                            }
217
-                            $html .= '<small>???</small>';
218
-                        }
219
-                    }
220
-                    $html .= '
216
+							}
217
+							$html .= '<small>???</small>';
218
+						}
219
+					}
220
+					$html .= '
221 221
                     </div>';
222
-                    $new_spawn['html'] = $html;
223
-                    $countdown = $last_seen - time();
224
-                    $new_spawn['countdown'] = $countdown;
225
-                    $new_spawn['pokemon_uid'] = $pokeuid;
226
-                    $total_spawns[] = $new_spawn;
227
-                } else {
228
-                    break;
229
-                }
230
-            }
231
-        }
232
-
233
-        header('Content-Type: application/json');
234
-        echo json_encode($total_spawns);
235
-
236
-        break;
237
-
238
-    //###################################
239
-    //
240
-    // List Pokestop
241
-    //
242
-    //###################################
243
-
244
-    case 'pokestop':
245
-        $datas = $manager->getAllPokestops();
246
-
247
-        $pokestops = [];
248
-        foreach ($datas as $data) {
249
-            if ($data->lure_expiration >= $data->now) {
250
-                $icon = 'pokestap_lured.png';
251
-                $text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
252
-                $lured = true;
253
-            } else {
254
-                $icon = 'pokestap.png';
255
-                $text = $locales->POKESTOPS_MAP_REGULAR;
256
-                $lured = false;
257
-            }
258
-
259
-            $pokestops[] = [
260
-                $text,
261
-                $icon,
262
-                $data->latitude,
263
-                $data->longitude,
264
-                $lured,
265
-            ];
266
-        }
267
-
268
-        header('Content-Type: application/json');
269
-        echo json_encode($pokestops);
270
-
271
-        break;
272
-
273
-    //###################################
274
-    //
275
-    // Update data for the gym battle
276
-    //
277
-    //###################################
278
-
279
-    case 'update_gym':
280
-        $teams = new stdClass();
281
-        $teams->mystic = 1;
282
-        $teams->valor = 2;
283
-        $teams->instinct = 3;
284
-
285
-        foreach ($teams as $team_name => $team_id) {
286
-            $data = $manager->getOwnedAndPoints($team_id);
287
-
288
-            $return[] = $data->total;
289
-            $return[] = $data->average_points;
290
-        }
291
-
292
-        header('Content-Type: application/json');
293
-        echo json_encode($return);
294
-
295
-        break;
296
-
297
-    //###################################
298
-    //
299
-    // Get datas for the gym map
300
-    //
301
-    //###################################
302
-
303
-    case 'gym_map':
304
-        $datas = $manager->getAllGyms();
305
-
306
-        $gyms = [];
307
-        foreach ($datas as $data) {
308
-            // Team
309
-            // 1 = bleu
310
-            // 2 = rouge
311
-            // 3 = jaune
312
-
313
-            switch ($data->team_id) {
314
-                case 0:
315
-                    $icon = 'map_white.png';
316
-                    $team = 'No Team (yet)';
317
-                    $color = 'rgba(0, 0, 0, .6)';
318
-                    break;
319
-
320
-                case 1:
321
-                    $icon = 'map_blue_';
322
-                    $team = 'Team Mystic';
323
-                    $color = 'rgba(74, 138, 202, .6)';
324
-                    break;
325
-
326
-                case 2:
327
-                    $icon = 'map_red_';
328
-                    $team = 'Team Valor';
329
-                    $color = 'rgba(240, 68, 58, .6)';
330
-                    break;
331
-
332
-                case 3:
333
-                    $icon = 'map_yellow_';
334
-                    $team = 'Team Instinct';
335
-                    $color = 'rgba(254, 217, 40, .6)';
336
-                    break;
337
-            }
338
-
339
-            if (0 != $data->team_id) {
340
-                $icon .= $data->level.'.png';
341
-            }
342
-
343
-            $gyms[] = [
344
-                $icon,
345
-                $data->latitude,
346
-                $data->longitude,
347
-                $data->gym_id,
348
-            ];
349
-        }
350
-
351
-        header('Content-Type: application/json');
352
-        echo json_encode($gyms);
353
-
354
-        break;
355
-
356
-    //###################################
357
-    //
358
-    // Get datas for gym defenders
359
-    //
360
-    //###################################
361
-
362
-    case 'gym_defenders':
363
-        $gym_id = $manager->getEcapedString($_GET['gym_id']);
364
-
365
-        $data = $manager->getGymData($gym_id);
366
-        $gymData['gymDetails']['gymInfos'] = false;
367
-
368
-        if (!is_null($data)) {
369
-            if (null == $data->name) {
370
-                $gymData['gymDetails']['gymInfos']['name'] = '?';
371
-            } else {
372
-                $gymData['gymDetails']['gymInfos']['name'] = $data->name;
373
-            }
374
-            $gymData['gymDetails']['gymInfos']['description'] = $data->description;
375
-            if (null == $data->url) {
376
-                $gymData['gymDetails']['gymInfos']['url'] = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Solid_grey.svg/200px-Solid_grey.svg.png';
377
-            } else {
378
-                $gymData['gymDetails']['gymInfos']['url'] = $data->url;
379
-            }
380
-            if (null == $data->url) {
381
-                $gymData['gymDetails']['gymInfos']['points'] = '?';
382
-            } else {
383
-                $gymData['gymDetails']['gymInfos']['points'] = $data->total_cp;
384
-            }
385
-            $gymData['gymDetails']['gymInfos']['level'] = $data->level;
386
-            if (null == $data->last_scanned) {
387
-                $gymData['gymDetails']['gymInfos']['last_scanned'] = '?';
388
-            } else {
389
-                $gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
390
-            }
391
-            $gymData['gymDetails']['gymInfos']['team'] = $data->team;
392
-            $gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
393
-
394
-            // Skip Query if team is none
395
-            if ($data->team > 0) {
396
-                $datas = $manager->getGymDefenders($gym_id);
397
-                $gymData['infoWindow'] = '
222
+					$new_spawn['html'] = $html;
223
+					$countdown = $last_seen - time();
224
+					$new_spawn['countdown'] = $countdown;
225
+					$new_spawn['pokemon_uid'] = $pokeuid;
226
+					$total_spawns[] = $new_spawn;
227
+				} else {
228
+					break;
229
+				}
230
+			}
231
+		}
232
+
233
+		header('Content-Type: application/json');
234
+		echo json_encode($total_spawns);
235
+
236
+		break;
237
+
238
+	//###################################
239
+	//
240
+	// List Pokestop
241
+	//
242
+	//###################################
243
+
244
+	case 'pokestop':
245
+		$datas = $manager->getAllPokestops();
246
+
247
+		$pokestops = [];
248
+		foreach ($datas as $data) {
249
+			if ($data->lure_expiration >= $data->now) {
250
+				$icon = 'pokestap_lured.png';
251
+				$text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
252
+				$lured = true;
253
+			} else {
254
+				$icon = 'pokestap.png';
255
+				$text = $locales->POKESTOPS_MAP_REGULAR;
256
+				$lured = false;
257
+			}
258
+
259
+			$pokestops[] = [
260
+				$text,
261
+				$icon,
262
+				$data->latitude,
263
+				$data->longitude,
264
+				$lured,
265
+			];
266
+		}
267
+
268
+		header('Content-Type: application/json');
269
+		echo json_encode($pokestops);
270
+
271
+		break;
272
+
273
+	//###################################
274
+	//
275
+	// Update data for the gym battle
276
+	//
277
+	//###################################
278
+
279
+	case 'update_gym':
280
+		$teams = new stdClass();
281
+		$teams->mystic = 1;
282
+		$teams->valor = 2;
283
+		$teams->instinct = 3;
284
+
285
+		foreach ($teams as $team_name => $team_id) {
286
+			$data = $manager->getOwnedAndPoints($team_id);
287
+
288
+			$return[] = $data->total;
289
+			$return[] = $data->average_points;
290
+		}
291
+
292
+		header('Content-Type: application/json');
293
+		echo json_encode($return);
294
+
295
+		break;
296
+
297
+	//###################################
298
+	//
299
+	// Get datas for the gym map
300
+	//
301
+	//###################################
302
+
303
+	case 'gym_map':
304
+		$datas = $manager->getAllGyms();
305
+
306
+		$gyms = [];
307
+		foreach ($datas as $data) {
308
+			// Team
309
+			// 1 = bleu
310
+			// 2 = rouge
311
+			// 3 = jaune
312
+
313
+			switch ($data->team_id) {
314
+				case 0:
315
+					$icon = 'map_white.png';
316
+					$team = 'No Team (yet)';
317
+					$color = 'rgba(0, 0, 0, .6)';
318
+					break;
319
+
320
+				case 1:
321
+					$icon = 'map_blue_';
322
+					$team = 'Team Mystic';
323
+					$color = 'rgba(74, 138, 202, .6)';
324
+					break;
325
+
326
+				case 2:
327
+					$icon = 'map_red_';
328
+					$team = 'Team Valor';
329
+					$color = 'rgba(240, 68, 58, .6)';
330
+					break;
331
+
332
+				case 3:
333
+					$icon = 'map_yellow_';
334
+					$team = 'Team Instinct';
335
+					$color = 'rgba(254, 217, 40, .6)';
336
+					break;
337
+			}
338
+
339
+			if (0 != $data->team_id) {
340
+				$icon .= $data->level.'.png';
341
+			}
342
+
343
+			$gyms[] = [
344
+				$icon,
345
+				$data->latitude,
346
+				$data->longitude,
347
+				$data->gym_id,
348
+			];
349
+		}
350
+
351
+		header('Content-Type: application/json');
352
+		echo json_encode($gyms);
353
+
354
+		break;
355
+
356
+	//###################################
357
+	//
358
+	// Get datas for gym defenders
359
+	//
360
+	//###################################
361
+
362
+	case 'gym_defenders':
363
+		$gym_id = $manager->getEcapedString($_GET['gym_id']);
364
+
365
+		$data = $manager->getGymData($gym_id);
366
+		$gymData['gymDetails']['gymInfos'] = false;
367
+
368
+		if (!is_null($data)) {
369
+			if (null == $data->name) {
370
+				$gymData['gymDetails']['gymInfos']['name'] = '?';
371
+			} else {
372
+				$gymData['gymDetails']['gymInfos']['name'] = $data->name;
373
+			}
374
+			$gymData['gymDetails']['gymInfos']['description'] = $data->description;
375
+			if (null == $data->url) {
376
+				$gymData['gymDetails']['gymInfos']['url'] = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Solid_grey.svg/200px-Solid_grey.svg.png';
377
+			} else {
378
+				$gymData['gymDetails']['gymInfos']['url'] = $data->url;
379
+			}
380
+			if (null == $data->url) {
381
+				$gymData['gymDetails']['gymInfos']['points'] = '?';
382
+			} else {
383
+				$gymData['gymDetails']['gymInfos']['points'] = $data->total_cp;
384
+			}
385
+			$gymData['gymDetails']['gymInfos']['level'] = $data->level;
386
+			if (null == $data->last_scanned) {
387
+				$gymData['gymDetails']['gymInfos']['last_scanned'] = '?';
388
+			} else {
389
+				$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
390
+			}
391
+			$gymData['gymDetails']['gymInfos']['team'] = $data->team;
392
+			$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
393
+
394
+			// Skip Query if team is none
395
+			if ($data->team > 0) {
396
+				$datas = $manager->getGymDefenders($gym_id);
397
+				$gymData['infoWindow'] = '
398 398
 				<div class="gym_defenders">
399 399
 				';
400
-                foreach ($datas as $data) {
401
-                    $gymData['gymDetails']['pokemons'][] = $data;
402
-                    $pokemon_id = $data->pokemon_id;
403
-                    if ($config->system->iv_numbers) {
404
-                        $gymData['infoWindow'] .= '
400
+				foreach ($datas as $data) {
401
+					$gymData['gymDetails']['pokemons'][] = $data;
402
+					$pokemon_id = $data->pokemon_id;
403
+					if ($config->system->iv_numbers) {
404
+						$gymData['infoWindow'] .= '
405 405
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
406 406
 						<a href="pokemon/'.$data->pokemon_id.'">
407 407
 						<img src="'.$pokemons->pokemon->$pokemon_id->img.'" height="50" style="display:inline-block" >
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 								</div>
420 420
 							</div>
421 421
 						</div>';
422
-                    } else {
423
-                        $gymData['infoWindow'] .= '
422
+					} else {
423
+						$gymData['infoWindow'] .= '
424 424
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
425 425
 						<a href="pokemon/'.$data->pokemon_id.'">
426 426
 						<img src="'.$pokemons->pokemon->$pokemon_id->img.'" height="50" style="display:inline-block" >
@@ -438,299 +438,299 @@  discard block
 block discarded – undo
438 438
 							</div>
439 439
 						</div>
440 440
 					</div>';
441
-                    }
442
-                }
443
-            }
444
-            $gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
445
-        }
446
-
447
-        header('Content-Type: application/json');
448
-        echo json_encode($gymData);
449
-
450
-        break;
451
-
452
-    case 'trainer':
453
-        $name = '';
454
-        $page = '0';
455
-        $team = 0;
456
-        $ranking = 0;
457
-        if (isset($_GET['name'])) {
458
-            $trainer_name = $manager->getEcapedString($_GET['name']);
459
-        }
460
-        if (isset($_GET['team'])) {
461
-            $team = $manager->getEcapedString($_GET['team']);
462
-        }
463
-        if (isset($_GET['page'])) {
464
-            $page = $manager->getEcapedString($_GET['page']);
465
-        }
466
-        if (isset($_GET['ranking'])) {
467
-            $ranking = $manager->getEcapedString($_GET['ranking']);
468
-        }
469
-
470
-        $trainers = $manager->getTrainers($trainer_name, $team, $page, $ranking);
471
-        $json = array();
472
-        $json['trainers'] = $trainers;
473
-        $locale = array();
474
-        $locale['today'] = $locales->TODAY;
475
-        $locale['day'] = $locales->DAY;
476
-        $locale['days'] = $locales->DAYS;
477
-        $locale['ivAttack'] = $locales->IV_ATTACK;
478
-        $locale['ivDefense'] = $locales->IV_DEFENSE;
479
-        $locale['ivStamina'] = $locales->IV_STAMINA;
480
-        $json['locale'] = $locale;
481
-
482
-        header('Content-Type: application/json');
483
-        echo json_encode($json);
484
-
485
-        break;
486
-
487
-    case 'raids':
488
-        $page = '0';
489
-        if (isset($_GET['page'])) {
490
-            $page = $manager->getEcapedString($_GET['page']);
491
-        }
492
-
493
-        $datas = $manager->getAllRaids($page);
494
-        $i = 1;
495
-        $raids = array();
496
-        foreach ($datas as $data) {
497
-            $data->starttime = date('H:i', strtotime($data->start));
498
-            $data->endtime = date('H:i', strtotime($data->end));
499
-            $data->gym_id = str_replace('.', '_', $data->gym_id);
500
-            if (isset($data->move_1)) {
501
-                $move1 = $data->move_1;
502
-                $data->quick_move = $move->$move1->name;
503
-            } else {
504
-                $data->quick_move = '?';
505
-            }
506
-            if (isset($data->move_2)) {
507
-                $move2 = $data->move_2;
508
-                $data->charge_move = $move->$move2->name;
509
-            } else {
510
-                $data->charge_move = '?';
511
-            }
512
-            $raids[10 * $page + $i] = $data;
513
-            ++$i;
514
-        }
515
-        $json = array();
516
-        $json['raids'] = $raids;
517
-        $locale = array();
518
-        $locale['noraids'] = $locales->RAIDS_NONE;
519
-        $json['locale'] = $locale;
520
-
521
-        header('Content-Type: application/json');
522
-        echo json_encode($json);
523
-
524
-        break;
525
-
526
-    case 'gyms':
527
-        $page = '0';
528
-        $ranking = 0;
529
-        $gym_name = '';
530
-        $team = '';
531
-        if (isset($_GET['name']) && '' != $_GET['name']) {
532
-            $gym_name = $manager->getEcapedString($_GET['name']);
533
-        }
534
-        if (isset($_GET['team']) && '' != $_GET['team']) {
535
-            $team = $manager->getEcapedString($_GET['team']);
536
-        }
537
-        if (isset($_GET['page'])) {
538
-            $page = $manager->getEcapedString($_GET['page']);
539
-        }
540
-        if (isset($_GET['ranking'])) {
541
-            $ranking = $manager->getEcapedString($_GET['ranking']);
542
-        }
543
-
544
-        $datas = $manager->getGymHistories($gym_name, $team, $page, $ranking);
545
-        $gyms = array();
546
-        foreach ($datas as $data) {
547
-            $pkm = array();
548
-            if ($data->total_cp > 0) {
549
-                $pkm = $manager->getGymHistoriesPokemon($data->gym_id);
550
-            }
551
-            $data->pokemon = $pkm;
552
-            unset($data->pokemon_uids);
553
-            $data->gym_id = str_replace('.', '_', $data->gym_id);
554
-            $gyms[] = $data;
555
-        }
556
-        $json = array();
557
-        $json['gyms'] = $gyms;
558
-        $locale = array();
559
-        $json['locale'] = $locale;
560
-
561
-        header('Content-Type: application/json');
562
-        echo json_encode($json);
563
-
564
-        break;
565
-
566
-    case 'gymhistory':
567
-        $gym_id = '';
568
-        $page = '0';
569
-        if (isset($_GET['gym_id'])) {
570
-            $gym_id = $manager->getEcapedString($_GET['gym_id']);
571
-            $gym_id = str_replace('_', '.', $gym_id);
572
-        }
573
-        if (isset($_GET['page'])) {
574
-            $page = $manager->getEcapedString($_GET['page']);
575
-        }
576
-
577
-        $entries = array();
578
-
579
-        $last_page = true;
580
-        if ('' != $gym_id) {
581
-            $datas = $manager->getHistoryForGym($page, $gym_id);
582
-            foreach ($datas['data'] as $data) {
583
-                $data->gym_id = str_replace('.', '_', $data->gym_id);
584
-                $entries[] = $data;
585
-            }
586
-            $last_page = $datas['last_page'];
587
-
588
-            foreach ($entries as $idx => $entry) {
589
-                $entry->total_cp_diff = 0;
590
-                $entry->only_cp_changed = true;
591
-                if ($idx < count($entries) - 1) {
592
-                    $next_entry = $entries[$idx + 1];
593
-                    $entry->total_cp_diff = $entry->total_cp - $next_entry->total_cp;
594
-                    $entry->class = $entry->total_cp_diff > 0 ? 'gain' : ($entry->total_cp_diff < 0 ? 'loss' : '');
595
-                    $entry_pokemon = preg_split('/,/', $entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
596
-                    $next_entry_pokemon = preg_split('/,/', $next_entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
597
-                    $new_pokemon = array_diff($entry_pokemon, $next_entry_pokemon);
598
-                    $old_pokemon = array_diff($next_entry_pokemon, $entry_pokemon);
599
-                    foreach ($new_pokemon as $pkm) {
600
-                        $entry->pokemon[$pkm]->class = 'new';
601
-                    }
602
-                    foreach ($old_pokemon as $pkm) {
603
-                        $next_entry->pokemon[$pkm]->class = 'old';
604
-                    }
605
-                    if ($entry->team_id != $next_entry->team_id || $entry->pokemon_uids != $next_entry->pokemon_uids) {
606
-                        $entry->only_cp_changed = false;
607
-                    }
608
-                }
609
-                unset($entry->pokemon_uids);
610
-            }
611
-
612
-            if (count($entries) > 10) {
613
-                array_pop($entries);
614
-            }
615
-        }
616
-
617
-        $json = array();
618
-        $json['entries'] = $entries;
619
-        $locale = array();
620
-        $json['locale'] = $locale;
621
-        $json['last_page'] = $last_page;
622
-
623
-        header('Content-Type: application/json');
624
-        echo json_encode($json);
625
-
626
-        break;
627
-
628
-    case 'pokemon_slider_init':
629
-        $bounds = $manager->getPokemonSliderMinMax();
630
-
631
-        header('Content-Type: application/json');
632
-        echo json_encode($bounds);
633
-
634
-        break;
635
-
636
-    case 'pokemon_heatmap_points':
637
-        $json = '';
638
-        if (isset($_GET['start']) && isset($_GET['end']) && isset($_GET['pokemon_id'])) {
639
-            $start = date('Y-m-d H:i', (int) $_GET['start']);
640
-            $end = date('Y-m-d H:i', (int) $_GET['end']);
641
-            $pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
642
-            $points = $manager->getPokemonHeatmap($pokemon_id, $start, $end);
643
-
644
-            $json = json_encode($points);
645
-        }
646
-
647
-        header('Content-Type: application/json');
648
-        echo $json;
649
-        break;
650
-
651
-    case 'maps_localization_coordinates':
652
-        $coordinates = $manager->getMapsCoords();
653
-
654
-        header('Content-Type: application/json');
655
-        echo json_encode($coordinates);
656
-
657
-        break;
658
-
659
-    case 'pokemon_graph_data':
660
-        $json = '';
661
-        if (isset($_GET['pokemon_id'])) {
662
-            $pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
663
-            $array = $manager->getPokemonGraph($pokemon_id);
664
-
665
-            $json = json_encode($array);
666
-        }
667
-
668
-        header('Content-Type: application/json');
669
-        echo $json;
670
-        break;
671
-
672
-    case 'postRequest':
673
-        break;
674
-
675
-    default:
676
-        echo 'What do you mean?';
677
-        exit();
678
-    break;
441
+					}
442
+				}
443
+			}
444
+			$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
445
+		}
446
+
447
+		header('Content-Type: application/json');
448
+		echo json_encode($gymData);
449
+
450
+		break;
451
+
452
+	case 'trainer':
453
+		$name = '';
454
+		$page = '0';
455
+		$team = 0;
456
+		$ranking = 0;
457
+		if (isset($_GET['name'])) {
458
+			$trainer_name = $manager->getEcapedString($_GET['name']);
459
+		}
460
+		if (isset($_GET['team'])) {
461
+			$team = $manager->getEcapedString($_GET['team']);
462
+		}
463
+		if (isset($_GET['page'])) {
464
+			$page = $manager->getEcapedString($_GET['page']);
465
+		}
466
+		if (isset($_GET['ranking'])) {
467
+			$ranking = $manager->getEcapedString($_GET['ranking']);
468
+		}
469
+
470
+		$trainers = $manager->getTrainers($trainer_name, $team, $page, $ranking);
471
+		$json = array();
472
+		$json['trainers'] = $trainers;
473
+		$locale = array();
474
+		$locale['today'] = $locales->TODAY;
475
+		$locale['day'] = $locales->DAY;
476
+		$locale['days'] = $locales->DAYS;
477
+		$locale['ivAttack'] = $locales->IV_ATTACK;
478
+		$locale['ivDefense'] = $locales->IV_DEFENSE;
479
+		$locale['ivStamina'] = $locales->IV_STAMINA;
480
+		$json['locale'] = $locale;
481
+
482
+		header('Content-Type: application/json');
483
+		echo json_encode($json);
484
+
485
+		break;
486
+
487
+	case 'raids':
488
+		$page = '0';
489
+		if (isset($_GET['page'])) {
490
+			$page = $manager->getEcapedString($_GET['page']);
491
+		}
492
+
493
+		$datas = $manager->getAllRaids($page);
494
+		$i = 1;
495
+		$raids = array();
496
+		foreach ($datas as $data) {
497
+			$data->starttime = date('H:i', strtotime($data->start));
498
+			$data->endtime = date('H:i', strtotime($data->end));
499
+			$data->gym_id = str_replace('.', '_', $data->gym_id);
500
+			if (isset($data->move_1)) {
501
+				$move1 = $data->move_1;
502
+				$data->quick_move = $move->$move1->name;
503
+			} else {
504
+				$data->quick_move = '?';
505
+			}
506
+			if (isset($data->move_2)) {
507
+				$move2 = $data->move_2;
508
+				$data->charge_move = $move->$move2->name;
509
+			} else {
510
+				$data->charge_move = '?';
511
+			}
512
+			$raids[10 * $page + $i] = $data;
513
+			++$i;
514
+		}
515
+		$json = array();
516
+		$json['raids'] = $raids;
517
+		$locale = array();
518
+		$locale['noraids'] = $locales->RAIDS_NONE;
519
+		$json['locale'] = $locale;
520
+
521
+		header('Content-Type: application/json');
522
+		echo json_encode($json);
523
+
524
+		break;
525
+
526
+	case 'gyms':
527
+		$page = '0';
528
+		$ranking = 0;
529
+		$gym_name = '';
530
+		$team = '';
531
+		if (isset($_GET['name']) && '' != $_GET['name']) {
532
+			$gym_name = $manager->getEcapedString($_GET['name']);
533
+		}
534
+		if (isset($_GET['team']) && '' != $_GET['team']) {
535
+			$team = $manager->getEcapedString($_GET['team']);
536
+		}
537
+		if (isset($_GET['page'])) {
538
+			$page = $manager->getEcapedString($_GET['page']);
539
+		}
540
+		if (isset($_GET['ranking'])) {
541
+			$ranking = $manager->getEcapedString($_GET['ranking']);
542
+		}
543
+
544
+		$datas = $manager->getGymHistories($gym_name, $team, $page, $ranking);
545
+		$gyms = array();
546
+		foreach ($datas as $data) {
547
+			$pkm = array();
548
+			if ($data->total_cp > 0) {
549
+				$pkm = $manager->getGymHistoriesPokemon($data->gym_id);
550
+			}
551
+			$data->pokemon = $pkm;
552
+			unset($data->pokemon_uids);
553
+			$data->gym_id = str_replace('.', '_', $data->gym_id);
554
+			$gyms[] = $data;
555
+		}
556
+		$json = array();
557
+		$json['gyms'] = $gyms;
558
+		$locale = array();
559
+		$json['locale'] = $locale;
560
+
561
+		header('Content-Type: application/json');
562
+		echo json_encode($json);
563
+
564
+		break;
565
+
566
+	case 'gymhistory':
567
+		$gym_id = '';
568
+		$page = '0';
569
+		if (isset($_GET['gym_id'])) {
570
+			$gym_id = $manager->getEcapedString($_GET['gym_id']);
571
+			$gym_id = str_replace('_', '.', $gym_id);
572
+		}
573
+		if (isset($_GET['page'])) {
574
+			$page = $manager->getEcapedString($_GET['page']);
575
+		}
576
+
577
+		$entries = array();
578
+
579
+		$last_page = true;
580
+		if ('' != $gym_id) {
581
+			$datas = $manager->getHistoryForGym($page, $gym_id);
582
+			foreach ($datas['data'] as $data) {
583
+				$data->gym_id = str_replace('.', '_', $data->gym_id);
584
+				$entries[] = $data;
585
+			}
586
+			$last_page = $datas['last_page'];
587
+
588
+			foreach ($entries as $idx => $entry) {
589
+				$entry->total_cp_diff = 0;
590
+				$entry->only_cp_changed = true;
591
+				if ($idx < count($entries) - 1) {
592
+					$next_entry = $entries[$idx + 1];
593
+					$entry->total_cp_diff = $entry->total_cp - $next_entry->total_cp;
594
+					$entry->class = $entry->total_cp_diff > 0 ? 'gain' : ($entry->total_cp_diff < 0 ? 'loss' : '');
595
+					$entry_pokemon = preg_split('/,/', $entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
596
+					$next_entry_pokemon = preg_split('/,/', $next_entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
597
+					$new_pokemon = array_diff($entry_pokemon, $next_entry_pokemon);
598
+					$old_pokemon = array_diff($next_entry_pokemon, $entry_pokemon);
599
+					foreach ($new_pokemon as $pkm) {
600
+						$entry->pokemon[$pkm]->class = 'new';
601
+					}
602
+					foreach ($old_pokemon as $pkm) {
603
+						$next_entry->pokemon[$pkm]->class = 'old';
604
+					}
605
+					if ($entry->team_id != $next_entry->team_id || $entry->pokemon_uids != $next_entry->pokemon_uids) {
606
+						$entry->only_cp_changed = false;
607
+					}
608
+				}
609
+				unset($entry->pokemon_uids);
610
+			}
611
+
612
+			if (count($entries) > 10) {
613
+				array_pop($entries);
614
+			}
615
+		}
616
+
617
+		$json = array();
618
+		$json['entries'] = $entries;
619
+		$locale = array();
620
+		$json['locale'] = $locale;
621
+		$json['last_page'] = $last_page;
622
+
623
+		header('Content-Type: application/json');
624
+		echo json_encode($json);
625
+
626
+		break;
627
+
628
+	case 'pokemon_slider_init':
629
+		$bounds = $manager->getPokemonSliderMinMax();
630
+
631
+		header('Content-Type: application/json');
632
+		echo json_encode($bounds);
633
+
634
+		break;
635
+
636
+	case 'pokemon_heatmap_points':
637
+		$json = '';
638
+		if (isset($_GET['start']) && isset($_GET['end']) && isset($_GET['pokemon_id'])) {
639
+			$start = date('Y-m-d H:i', (int) $_GET['start']);
640
+			$end = date('Y-m-d H:i', (int) $_GET['end']);
641
+			$pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
642
+			$points = $manager->getPokemonHeatmap($pokemon_id, $start, $end);
643
+
644
+			$json = json_encode($points);
645
+		}
646
+
647
+		header('Content-Type: application/json');
648
+		echo $json;
649
+		break;
650
+
651
+	case 'maps_localization_coordinates':
652
+		$coordinates = $manager->getMapsCoords();
653
+
654
+		header('Content-Type: application/json');
655
+		echo json_encode($coordinates);
656
+
657
+		break;
658
+
659
+	case 'pokemon_graph_data':
660
+		$json = '';
661
+		if (isset($_GET['pokemon_id'])) {
662
+			$pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
663
+			$array = $manager->getPokemonGraph($pokemon_id);
664
+
665
+			$json = json_encode($array);
666
+		}
667
+
668
+		header('Content-Type: application/json');
669
+		echo $json;
670
+		break;
671
+
672
+	case 'postRequest':
673
+		break;
674
+
675
+	default:
676
+		echo 'What do you mean?';
677
+		exit();
678
+	break;
679 679
 }
680 680
 
681 681
 if ('' != $postRequest) {
682
-    switch ($postRequest) {
683
-        case 'pokemon_live':
684
-            $json = '';
685
-            if (isset($_POST['pokemon_id'])) {
686
-                $pokemon_id = $manager->getEcapedString($_POST['pokemon_id']);
687
-                $ivMin = $manager->getEcapedString($_POST['ivMin']);
688
-                $ivMax = $manager->getEcapedString($_POST['ivMax']);
689
-                if (isset($_POST['inmap_pokemons'])) {
690
-                    $inmap_pokemons = $manager->getEcapedString($_POST['inmap_pokemons']);
691
-                } else {
692
-                    $inmap_pokemons = null;
693
-                }
694
-
695
-                $datas = $manager->getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
696
-
697
-                $json = array();
698
-                $json['points'] = array();
699
-                $locale = array();
700
-                $locale['ivAttack'] = $locales->IV_ATTACK;
701
-                $locale['ivDefense'] = $locales->IV_DEFENSE;
702
-                $locale['ivStamina'] = $locales->IV_STAMINA;
703
-                $json['locale'] = $locale;
704
-                foreach ($datas as $data) {
705
-                    $pokeid = $data->pokemon_id;
706
-                    $data->name = $pokemons->pokemon->$pokeid->name;
707
-                    if (isset($data->move_1)) {
708
-                        $move1 = $data->move_1;
709
-                        $data->quick_move = $move->$move1->name;
710
-                    } else {
711
-                        $data->quick_move = '?';
712
-                    }
713
-                    if (isset($data->move_2)) {
714
-                        $move2 = $data->move_2;
715
-                        $data->charge_move = $move->$move2->name;
716
-                    } else {
717
-                        $data->charge_move = '?';
718
-                    }
719
-                    $json['points'][] = $data;
720
-                }
721
-
722
-                $json = json_encode($json);
723
-            }
724
-
725
-            header('Content-Type: application/json');
726
-
727
-            echo $json;
728
-
729
-        break;
730
-
731
-        default:
732
-            echo 'What do you mean?';
733
-            exit();
734
-        break;
735
-    }
682
+	switch ($postRequest) {
683
+		case 'pokemon_live':
684
+			$json = '';
685
+			if (isset($_POST['pokemon_id'])) {
686
+				$pokemon_id = $manager->getEcapedString($_POST['pokemon_id']);
687
+				$ivMin = $manager->getEcapedString($_POST['ivMin']);
688
+				$ivMax = $manager->getEcapedString($_POST['ivMax']);
689
+				if (isset($_POST['inmap_pokemons'])) {
690
+					$inmap_pokemons = $manager->getEcapedString($_POST['inmap_pokemons']);
691
+				} else {
692
+					$inmap_pokemons = null;
693
+				}
694
+
695
+				$datas = $manager->getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
696
+
697
+				$json = array();
698
+				$json['points'] = array();
699
+				$locale = array();
700
+				$locale['ivAttack'] = $locales->IV_ATTACK;
701
+				$locale['ivDefense'] = $locales->IV_DEFENSE;
702
+				$locale['ivStamina'] = $locales->IV_STAMINA;
703
+				$json['locale'] = $locale;
704
+				foreach ($datas as $data) {
705
+					$pokeid = $data->pokemon_id;
706
+					$data->name = $pokemons->pokemon->$pokeid->name;
707
+					if (isset($data->move_1)) {
708
+						$move1 = $data->move_1;
709
+						$data->quick_move = $move->$move1->name;
710
+					} else {
711
+						$data->quick_move = '?';
712
+					}
713
+					if (isset($data->move_2)) {
714
+						$move2 = $data->move_2;
715
+						$data->charge_move = $move->$move2->name;
716
+					} else {
717
+						$data->charge_move = '?';
718
+					}
719
+					$json['points'][] = $data;
720
+				}
721
+
722
+				$json = json_encode($json);
723
+			}
724
+
725
+			header('Content-Type: application/json');
726
+
727
+			echo $json;
728
+
729
+		break;
730
+
731
+		default:
732
+			echo 'What do you mean?';
733
+			exit();
734
+		break;
735
+	}
736 736
 }
Please login to merge, or discard this patch.
Switch Indentation   +492 added lines, -492 removed lines patch added patch discarded remove patch
@@ -56,116 +56,116 @@  discard block
 block discarded – undo
56 56
     //
57 57
     //###########################
58 58
 
59
-    case 'home_update':
60
-        $values = [];
61
-        // Right now
62
-        // ---------
63
-        $data = $manager->getTotalPokemon();
64
-        $values[] = $data->total;
65
-
66
-        // Lured stops
67
-        // -----------
68
-        $data = $manager->getTotalLures();
69
-        $values[] = $data->total;
70
-
71
-        // Active Raids
72
-        // -----------
73
-        $data = $manager->getTotalRaids();
74
-        $values[] = $data->total;
75
-
76
-        // Team battle
77
-        // -----------
78
-        $data = $manager->getTotalGyms();
79
-        $values[] = $data->total;
80
-
81
-        // Red
82
-        $data = $manager->getTotalGymsForTeam(2);
83
-        $values[] = $data->total;
84
-
85
-        // Blue
86
-        $data = $manager->getTotalGymsForTeam(1);
87
-        $values[] = $data->total;
88
-
89
-        // Yellow
90
-        $data = $manager->getTotalGymsForTeam(3);
91
-        $values[] = $data->total;
92
-
93
-        // Neutral
94
-        $data = $manager->getTotalGymsForTeam(0);
95
-        $values[] = $data->total;
96
-
97
-        header('Content-Type: application/json');
98
-        echo json_encode($values);
99
-
100
-        break;
101
-
102
-    //###################################
103
-    //
104
-    // Update latests spawn on homepage
105
-    //
106
-    //###################################
107
-
108
-    case 'spawnlist_update':
109
-        // Recent spawn
110
-        // ------------
111
-        $total_spawns = array();
112
-        $last_uid_param = '';
113
-        if (isset($_GET['last_uid'])) {
114
-            $last_uid_param = $_GET['last_uid'];
115
-        }
116
-        if ($config->system->recents_filter) {
117
-            // get all mythic pokemon ids
118
-            $mythic_pokemons = array();
119
-            foreach ($pokemons->pokemon as $id => $pokemon) {
120
-                if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
121
-                    $mythic_pokemons[] = $id;
122
-                }
123
-            }
124
-
125
-            // get last mythic pokemon
126
-            $result = $manager->getRecentMythic($mythic_pokemons);
127
-        } else {
128
-            // get last pokemon
129
-            $result = $manager->getRecentAll();
130
-        }
131
-
132
-        if (count($result) > 0) {
133
-            foreach ($result as $data) {
134
-                $new_spawn = array();
135
-                $pokeid = $data->pokemon_id;
136
-                $pokeuid = $data->encounter_id;
137
-
138
-                if ($last_uid_param != $pokeuid) {
139
-                    $last_seen = strtotime($data->disappear_time_real);
140
-
141
-                    $location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
142
-                    $location_link = str_replace('{latitude}', $data->latitude, $location_link);
143
-                    $location_link = str_replace('{longitude}', $data->longitude, $location_link);
144
-
145
-                    if ($config->system->recents_encounter_details) {
146
-                        $encdetails = new stdClass();
147
-                        $encdetails->cp = $data->cp;
148
-                        $encdetails->attack = $data->individual_attack;
149
-                        $encdetails->defense = $data->individual_defense;
150
-                        $encdetails->stamina = $data->individual_stamina;
151
-                        if (isset($encdetails->cp) && isset($encdetails->attack) && isset($encdetails->defense) && isset($encdetails->stamina)) {
152
-                            $encdetails->available = true;
153
-                        } else {
154
-                            $encdetails->available = false;
155
-                        }
156
-                    }
157
-
158
-                    $html = '
59
+    	case 'home_update':
60
+        	$values = [];
61
+        	// Right now
62
+        	// ---------
63
+        	$data = $manager->getTotalPokemon();
64
+        	$values[] = $data->total;
65
+
66
+        	// Lured stops
67
+        	// -----------
68
+        	$data = $manager->getTotalLures();
69
+        	$values[] = $data->total;
70
+
71
+        	// Active Raids
72
+        	// -----------
73
+        	$data = $manager->getTotalRaids();
74
+        	$values[] = $data->total;
75
+
76
+        	// Team battle
77
+        	// -----------
78
+        	$data = $manager->getTotalGyms();
79
+        	$values[] = $data->total;
80
+
81
+        	// Red
82
+        	$data = $manager->getTotalGymsForTeam(2);
83
+        	$values[] = $data->total;
84
+
85
+        	// Blue
86
+        	$data = $manager->getTotalGymsForTeam(1);
87
+        	$values[] = $data->total;
88
+
89
+        	// Yellow
90
+        	$data = $manager->getTotalGymsForTeam(3);
91
+        	$values[] = $data->total;
92
+
93
+        	// Neutral
94
+        	$data = $manager->getTotalGymsForTeam(0);
95
+        	$values[] = $data->total;
96
+
97
+        	header('Content-Type: application/json');
98
+        	echo json_encode($values);
99
+
100
+        	break;
101
+
102
+    	//###################################
103
+    	//
104
+    	// Update latests spawn on homepage
105
+    	//
106
+    	//###################################
107
+
108
+    	case 'spawnlist_update':
109
+        	// Recent spawn
110
+        	// ------------
111
+        	$total_spawns = array();
112
+        	$last_uid_param = '';
113
+        	if (isset($_GET['last_uid'])) {
114
+            	$last_uid_param = $_GET['last_uid'];
115
+        	}
116
+        	if ($config->system->recents_filter) {
117
+            	// get all mythic pokemon ids
118
+            	$mythic_pokemons = array();
119
+            	foreach ($pokemons->pokemon as $id => $pokemon) {
120
+                	if ($pokemon->spawn_rate < $config->system->recents_filter_rarity && $pokemon->rating >= $config->system->recents_filter_rating) {
121
+                    	$mythic_pokemons[] = $id;
122
+                	}
123
+            	}
124
+
125
+            	// get last mythic pokemon
126
+            	$result = $manager->getRecentMythic($mythic_pokemons);
127
+        	} else {
128
+            	// get last pokemon
129
+            	$result = $manager->getRecentAll();
130
+        	}
131
+
132
+        	if (count($result) > 0) {
133
+            	foreach ($result as $data) {
134
+                	$new_spawn = array();
135
+                	$pokeid = $data->pokemon_id;
136
+                	$pokeuid = $data->encounter_id;
137
+
138
+                	if ($last_uid_param != $pokeuid) {
139
+                    	$last_seen = strtotime($data->disappear_time_real);
140
+
141
+                    	$location_link = isset($config->system->location_url) ? $config->system->location_url : 'https://maps.google.com/?q={latitude},{longitude}&ll={latitude},{longitude}&z=16';
142
+                    	$location_link = str_replace('{latitude}', $data->latitude, $location_link);
143
+                    	$location_link = str_replace('{longitude}', $data->longitude, $location_link);
144
+
145
+                    	if ($config->system->recents_encounter_details) {
146
+                        	$encdetails = new stdClass();
147
+                        	$encdetails->cp = $data->cp;
148
+                        	$encdetails->attack = $data->individual_attack;
149
+                        	$encdetails->defense = $data->individual_defense;
150
+                        	$encdetails->stamina = $data->individual_stamina;
151
+                        	if (isset($encdetails->cp) && isset($encdetails->attack) && isset($encdetails->defense) && isset($encdetails->stamina)) {
152
+                            	$encdetails->available = true;
153
+                        	} else {
154
+                            	$encdetails->available = false;
155
+                        	}
156
+                    	}
157
+
158
+                    	$html = '
159 159
                     <div class="col-md-1 col-xs-4 pokemon-single" data-pokeid="'.$pokeid.'" data-pokeuid="'.$pokeuid.'" style="display: none;">
160 160
                     <a href="pokemon/'.$pokeid.'"><img src="'.$pokemons->pokemon->$pokeid->img.'" alt="'.$pokemons->pokemon->$pokeid->name.'" class="img-responsive"></a>
161 161
                     <a href="pokemon/'.$pokeid.'"><p class="pkmn-name">'.$pokemons->pokemon->$pokeid->name.'</p></a>
162 162
                     <a href="'.$location_link.'" target="_blank">
163 163
                         <small class="pokemon-timer">00:00:00</small>
164 164
                     </a>';
165
-                    if ($config->system->recents_encounter_details) {
166
-                        if ($encdetails->available) {
167
-                            if ($config->system->iv_numbers) {
168
-                                $html .= '
165
+                    	if ($config->system->recents_encounter_details) {
166
+                        	if ($encdetails->available) {
167
+                            	if ($config->system->iv_numbers) {
168
+                                	$html .= '
169 169
                                 <div class="progress" style="height: 15px; margin-bottom: 0">
170 170
                                     <div title="'.$locales->IV_ATTACK.': '.$encdetails->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px">
171 171
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$encdetails->attack.'</span>'.$encdetails->attack.'
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$encdetails->stamina.'</span>'.$encdetails->stamina.'
178 178
                                     </div>
179 179
                                 </div>';
180
-                            } else {
181
-                                $html .= '
180
+                            	} else {
181
+                                	$html .= '
182 182
                                 <div class="progress" style="height: 6px; width: 80%; margin: 5px auto 0 auto">
183 183
                                 <div title="'.$locales->IV_ATTACK.': '.$encdetails->attack.'" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(((100 / 15) * $encdetails->attack) / 3).'%">
184 184
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$encdetails->attack.'</span>
@@ -190,11 +190,11 @@  discard block
 block discarded – undo
190 190
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$encdetails->stamina.'</span>
191 191
                                 </div>
192 192
                                 </div>';
193
-                            }
194
-                            $html .= '<small>'.$encdetails->cp.'</small>';
195
-                        } else {
196
-                            if ($config->system->iv_numbers) {
197
-                                $html .= '
193
+                            	}
194
+                            	$html .= '<small>'.$encdetails->cp.'</small>';
195
+                        	} else {
196
+                            	if ($config->system->iv_numbers) {
197
+                                	$html .= '
198 198
                                 <div class="progress" style="height: 15px; margin-bottom: 0">
199 199
                                     <div title="'.$locales->IV_ATTACK.': not available" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="'.$encdetails->attack.'" aria-valuemin="0" aria-valuemax="45" style="width: '.(100 / 3).'%; line-height: 16px">
200 200
                                         <span class="sr-only">'.$locales->IV_ATTACK.': '.$locales->NOT_AVAILABLE.'</span>?
@@ -206,111 +206,111 @@  discard block
 block discarded – undo
206 206
                                         <span class="sr-only">'.$locales->IV_STAMINA.': '.$locales->NOT_AVAILABLE.'</span>?
207 207
                                     </div>
208 208
                                 </div>';
209
-                            } else {
210
-                                $html .= '
209
+                            	} else {
210
+                                	$html .= '
211 211
                             <div class="progress" style="height: 6px; width: 80%; margin: 5px auto 0 auto">
212 212
                                 <div title="IV not available" class="progress-bar" role="progressbar" style="width: 100%; background-color: rgb(210,210,210)" aria-valuenow="1" aria-valuemin="0" aria-valuemax="1">
213 213
                                     <span class="sr-only">IV '.$locales->NOT_AVAILABLE.'</span>
214 214
                                 </div>
215 215
                             </div>';
216
-                            }
217
-                            $html .= '<small>???</small>';
218
-                        }
219
-                    }
220
-                    $html .= '
216
+                            	}
217
+                            	$html .= '<small>???</small>';
218
+                        	}
219
+                    	}
220
+                    	$html .= '
221 221
                     </div>';
222
-                    $new_spawn['html'] = $html;
223
-                    $countdown = $last_seen - time();
224
-                    $new_spawn['countdown'] = $countdown;
225
-                    $new_spawn['pokemon_uid'] = $pokeuid;
226
-                    $total_spawns[] = $new_spawn;
227
-                } else {
228
-                    break;
229
-                }
230
-            }
231
-        }
232
-
233
-        header('Content-Type: application/json');
234
-        echo json_encode($total_spawns);
235
-
236
-        break;
237
-
238
-    //###################################
239
-    //
240
-    // List Pokestop
241
-    //
242
-    //###################################
243
-
244
-    case 'pokestop':
245
-        $datas = $manager->getAllPokestops();
246
-
247
-        $pokestops = [];
248
-        foreach ($datas as $data) {
249
-            if ($data->lure_expiration >= $data->now) {
250
-                $icon = 'pokestap_lured.png';
251
-                $text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
252
-                $lured = true;
253
-            } else {
254
-                $icon = 'pokestap.png';
255
-                $text = $locales->POKESTOPS_MAP_REGULAR;
256
-                $lured = false;
257
-            }
258
-
259
-            $pokestops[] = [
260
-                $text,
261
-                $icon,
262
-                $data->latitude,
263
-                $data->longitude,
264
-                $lured,
265
-            ];
266
-        }
267
-
268
-        header('Content-Type: application/json');
269
-        echo json_encode($pokestops);
270
-
271
-        break;
272
-
273
-    //###################################
274
-    //
275
-    // Update data for the gym battle
276
-    //
277
-    //###################################
278
-
279
-    case 'update_gym':
280
-        $teams = new stdClass();
281
-        $teams->mystic = 1;
282
-        $teams->valor = 2;
283
-        $teams->instinct = 3;
284
-
285
-        foreach ($teams as $team_name => $team_id) {
286
-            $data = $manager->getOwnedAndPoints($team_id);
287
-
288
-            $return[] = $data->total;
289
-            $return[] = $data->average_points;
290
-        }
291
-
292
-        header('Content-Type: application/json');
293
-        echo json_encode($return);
294
-
295
-        break;
296
-
297
-    //###################################
298
-    //
299
-    // Get datas for the gym map
300
-    //
301
-    //###################################
302
-
303
-    case 'gym_map':
304
-        $datas = $manager->getAllGyms();
305
-
306
-        $gyms = [];
307
-        foreach ($datas as $data) {
308
-            // Team
309
-            // 1 = bleu
310
-            // 2 = rouge
311
-            // 3 = jaune
312
-
313
-            switch ($data->team_id) {
222
+                    	$new_spawn['html'] = $html;
223
+                    	$countdown = $last_seen - time();
224
+                    	$new_spawn['countdown'] = $countdown;
225
+                    	$new_spawn['pokemon_uid'] = $pokeuid;
226
+                    	$total_spawns[] = $new_spawn;
227
+                	} else {
228
+                    	break;
229
+                	}
230
+            	}
231
+        	}
232
+
233
+        	header('Content-Type: application/json');
234
+        	echo json_encode($total_spawns);
235
+
236
+        	break;
237
+
238
+    	//###################################
239
+    	//
240
+    	// List Pokestop
241
+    	//
242
+    	//###################################
243
+
244
+    	case 'pokestop':
245
+        	$datas = $manager->getAllPokestops();
246
+
247
+        	$pokestops = [];
248
+        	foreach ($datas as $data) {
249
+            	if ($data->lure_expiration >= $data->now) {
250
+                	$icon = 'pokestap_lured.png';
251
+                	$text = sprintf($locales->POKESTOPS_MAP_LURED, date('H:i:s', strtotime($data->lure_expiration_real)));
252
+                	$lured = true;
253
+            	} else {
254
+                	$icon = 'pokestap.png';
255
+                	$text = $locales->POKESTOPS_MAP_REGULAR;
256
+                	$lured = false;
257
+            	}
258
+
259
+            	$pokestops[] = [
260
+                	$text,
261
+                	$icon,
262
+                	$data->latitude,
263
+                	$data->longitude,
264
+                	$lured,
265
+            	];
266
+        	}
267
+
268
+        	header('Content-Type: application/json');
269
+        	echo json_encode($pokestops);
270
+
271
+        	break;
272
+
273
+    	//###################################
274
+    	//
275
+    	// Update data for the gym battle
276
+    	//
277
+    	//###################################
278
+
279
+    	case 'update_gym':
280
+        	$teams = new stdClass();
281
+        	$teams->mystic = 1;
282
+        	$teams->valor = 2;
283
+        	$teams->instinct = 3;
284
+
285
+        	foreach ($teams as $team_name => $team_id) {
286
+            	$data = $manager->getOwnedAndPoints($team_id);
287
+
288
+            	$return[] = $data->total;
289
+            	$return[] = $data->average_points;
290
+        	}
291
+
292
+        	header('Content-Type: application/json');
293
+        	echo json_encode($return);
294
+
295
+        	break;
296
+
297
+    	//###################################
298
+    	//
299
+    	// Get datas for the gym map
300
+    	//
301
+    	//###################################
302
+
303
+    	case 'gym_map':
304
+        	$datas = $manager->getAllGyms();
305
+
306
+        	$gyms = [];
307
+        	foreach ($datas as $data) {
308
+            	// Team
309
+            	// 1 = bleu
310
+            	// 2 = rouge
311
+            	// 3 = jaune
312
+
313
+            	switch ($data->team_id) {
314 314
                 case 0:
315 315
                     $icon = 'map_white.png';
316 316
                     $team = 'No Team (yet)';
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
                     $team = 'Team Instinct';
335 335
                     $color = 'rgba(254, 217, 40, .6)';
336 336
                     break;
337
-            }
337
+            	}
338 338
 
339 339
             if (0 != $data->team_id) {
340 340
                 $icon .= $data->level.'.png';
@@ -359,49 +359,49 @@  discard block
 block discarded – undo
359 359
     //
360 360
     //###################################
361 361
 
362
-    case 'gym_defenders':
363
-        $gym_id = $manager->getEcapedString($_GET['gym_id']);
364
-
365
-        $data = $manager->getGymData($gym_id);
366
-        $gymData['gymDetails']['gymInfos'] = false;
367
-
368
-        if (!is_null($data)) {
369
-            if (null == $data->name) {
370
-                $gymData['gymDetails']['gymInfos']['name'] = '?';
371
-            } else {
372
-                $gymData['gymDetails']['gymInfos']['name'] = $data->name;
373
-            }
374
-            $gymData['gymDetails']['gymInfos']['description'] = $data->description;
375
-            if (null == $data->url) {
376
-                $gymData['gymDetails']['gymInfos']['url'] = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Solid_grey.svg/200px-Solid_grey.svg.png';
377
-            } else {
378
-                $gymData['gymDetails']['gymInfos']['url'] = $data->url;
379
-            }
380
-            if (null == $data->url) {
381
-                $gymData['gymDetails']['gymInfos']['points'] = '?';
382
-            } else {
383
-                $gymData['gymDetails']['gymInfos']['points'] = $data->total_cp;
384
-            }
385
-            $gymData['gymDetails']['gymInfos']['level'] = $data->level;
386
-            if (null == $data->last_scanned) {
387
-                $gymData['gymDetails']['gymInfos']['last_scanned'] = '?';
388
-            } else {
389
-                $gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
390
-            }
391
-            $gymData['gymDetails']['gymInfos']['team'] = $data->team;
392
-            $gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
393
-
394
-            // Skip Query if team is none
395
-            if ($data->team > 0) {
396
-                $datas = $manager->getGymDefenders($gym_id);
397
-                $gymData['infoWindow'] = '
362
+    	case 'gym_defenders':
363
+        	$gym_id = $manager->getEcapedString($_GET['gym_id']);
364
+
365
+        	$data = $manager->getGymData($gym_id);
366
+        	$gymData['gymDetails']['gymInfos'] = false;
367
+
368
+        	if (!is_null($data)) {
369
+            	if (null == $data->name) {
370
+                	$gymData['gymDetails']['gymInfos']['name'] = '?';
371
+            	} else {
372
+                	$gymData['gymDetails']['gymInfos']['name'] = $data->name;
373
+            	}
374
+            	$gymData['gymDetails']['gymInfos']['description'] = $data->description;
375
+            	if (null == $data->url) {
376
+                	$gymData['gymDetails']['gymInfos']['url'] = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/86/Solid_grey.svg/200px-Solid_grey.svg.png';
377
+            	} else {
378
+                	$gymData['gymDetails']['gymInfos']['url'] = $data->url;
379
+            	}
380
+            	if (null == $data->url) {
381
+                	$gymData['gymDetails']['gymInfos']['points'] = '?';
382
+            	} else {
383
+                	$gymData['gymDetails']['gymInfos']['points'] = $data->total_cp;
384
+            	}
385
+            	$gymData['gymDetails']['gymInfos']['level'] = $data->level;
386
+            	if (null == $data->last_scanned) {
387
+                	$gymData['gymDetails']['gymInfos']['last_scanned'] = '?';
388
+            	} else {
389
+                	$gymData['gymDetails']['gymInfos']['last_scanned'] = $data->last_scanned;
390
+            	}
391
+            	$gymData['gymDetails']['gymInfos']['team'] = $data->team;
392
+            	$gymData['gymDetails']['gymInfos']['guardPokemonId'] = $data->guard_pokemon_id;
393
+
394
+            	// Skip Query if team is none
395
+            	if ($data->team > 0) {
396
+                	$datas = $manager->getGymDefenders($gym_id);
397
+                	$gymData['infoWindow'] = '
398 398
 				<div class="gym_defenders">
399 399
 				';
400
-                foreach ($datas as $data) {
401
-                    $gymData['gymDetails']['pokemons'][] = $data;
402
-                    $pokemon_id = $data->pokemon_id;
403
-                    if ($config->system->iv_numbers) {
404
-                        $gymData['infoWindow'] .= '
400
+                	foreach ($datas as $data) {
401
+                    	$gymData['gymDetails']['pokemons'][] = $data;
402
+                    	$pokemon_id = $data->pokemon_id;
403
+                    	if ($config->system->iv_numbers) {
404
+                        	$gymData['infoWindow'] .= '
405 405
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
406 406
 						<a href="pokemon/'.$data->pokemon_id.'">
407 407
 						<img src="'.$pokemons->pokemon->$pokemon_id->img.'" height="50" style="display:inline-block" >
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 								</div>
420 420
 							</div>
421 421
 						</div>';
422
-                    } else {
423
-                        $gymData['infoWindow'] .= '
422
+                    	} else {
423
+                        	$gymData['infoWindow'] .= '
424 424
 					<div style="text-align: center; width: 50px; display: inline-block; margin-right: 3px">
425 425
 						<a href="pokemon/'.$data->pokemon_id.'">
426 426
 						<img src="'.$pokemons->pokemon->$pokemon_id->img.'" height="50" style="display:inline-block" >
@@ -438,244 +438,244 @@  discard block
 block discarded – undo
438 438
 							</div>
439 439
 						</div>
440 440
 					</div>';
441
-                    }
442
-                }
443
-            }
444
-            $gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
445
-        }
446
-
447
-        header('Content-Type: application/json');
448
-        echo json_encode($gymData);
449
-
450
-        break;
451
-
452
-    case 'trainer':
453
-        $name = '';
454
-        $page = '0';
455
-        $team = 0;
456
-        $ranking = 0;
457
-        if (isset($_GET['name'])) {
458
-            $trainer_name = $manager->getEcapedString($_GET['name']);
459
-        }
460
-        if (isset($_GET['team'])) {
461
-            $team = $manager->getEcapedString($_GET['team']);
462
-        }
463
-        if (isset($_GET['page'])) {
464
-            $page = $manager->getEcapedString($_GET['page']);
465
-        }
466
-        if (isset($_GET['ranking'])) {
467
-            $ranking = $manager->getEcapedString($_GET['ranking']);
468
-        }
469
-
470
-        $trainers = $manager->getTrainers($trainer_name, $team, $page, $ranking);
471
-        $json = array();
472
-        $json['trainers'] = $trainers;
473
-        $locale = array();
474
-        $locale['today'] = $locales->TODAY;
475
-        $locale['day'] = $locales->DAY;
476
-        $locale['days'] = $locales->DAYS;
477
-        $locale['ivAttack'] = $locales->IV_ATTACK;
478
-        $locale['ivDefense'] = $locales->IV_DEFENSE;
479
-        $locale['ivStamina'] = $locales->IV_STAMINA;
480
-        $json['locale'] = $locale;
481
-
482
-        header('Content-Type: application/json');
483
-        echo json_encode($json);
484
-
485
-        break;
486
-
487
-    case 'raids':
488
-        $page = '0';
489
-        if (isset($_GET['page'])) {
490
-            $page = $manager->getEcapedString($_GET['page']);
491
-        }
492
-
493
-        $datas = $manager->getAllRaids($page);
494
-        $i = 1;
495
-        $raids = array();
496
-        foreach ($datas as $data) {
497
-            $data->starttime = date('H:i', strtotime($data->start));
498
-            $data->endtime = date('H:i', strtotime($data->end));
499
-            $data->gym_id = str_replace('.', '_', $data->gym_id);
500
-            if (isset($data->move_1)) {
501
-                $move1 = $data->move_1;
502
-                $data->quick_move = $move->$move1->name;
503
-            } else {
504
-                $data->quick_move = '?';
505
-            }
506
-            if (isset($data->move_2)) {
507
-                $move2 = $data->move_2;
508
-                $data->charge_move = $move->$move2->name;
509
-            } else {
510
-                $data->charge_move = '?';
511
-            }
512
-            $raids[10 * $page + $i] = $data;
513
-            ++$i;
514
-        }
515
-        $json = array();
516
-        $json['raids'] = $raids;
517
-        $locale = array();
518
-        $locale['noraids'] = $locales->RAIDS_NONE;
519
-        $json['locale'] = $locale;
520
-
521
-        header('Content-Type: application/json');
522
-        echo json_encode($json);
523
-
524
-        break;
525
-
526
-    case 'gyms':
527
-        $page = '0';
528
-        $ranking = 0;
529
-        $gym_name = '';
530
-        $team = '';
531
-        if (isset($_GET['name']) && '' != $_GET['name']) {
532
-            $gym_name = $manager->getEcapedString($_GET['name']);
533
-        }
534
-        if (isset($_GET['team']) && '' != $_GET['team']) {
535
-            $team = $manager->getEcapedString($_GET['team']);
536
-        }
537
-        if (isset($_GET['page'])) {
538
-            $page = $manager->getEcapedString($_GET['page']);
539
-        }
540
-        if (isset($_GET['ranking'])) {
541
-            $ranking = $manager->getEcapedString($_GET['ranking']);
542
-        }
543
-
544
-        $datas = $manager->getGymHistories($gym_name, $team, $page, $ranking);
545
-        $gyms = array();
546
-        foreach ($datas as $data) {
547
-            $pkm = array();
548
-            if ($data->total_cp > 0) {
549
-                $pkm = $manager->getGymHistoriesPokemon($data->gym_id);
550
-            }
551
-            $data->pokemon = $pkm;
552
-            unset($data->pokemon_uids);
553
-            $data->gym_id = str_replace('.', '_', $data->gym_id);
554
-            $gyms[] = $data;
555
-        }
556
-        $json = array();
557
-        $json['gyms'] = $gyms;
558
-        $locale = array();
559
-        $json['locale'] = $locale;
560
-
561
-        header('Content-Type: application/json');
562
-        echo json_encode($json);
563
-
564
-        break;
565
-
566
-    case 'gymhistory':
567
-        $gym_id = '';
568
-        $page = '0';
569
-        if (isset($_GET['gym_id'])) {
570
-            $gym_id = $manager->getEcapedString($_GET['gym_id']);
571
-            $gym_id = str_replace('_', '.', $gym_id);
572
-        }
573
-        if (isset($_GET['page'])) {
574
-            $page = $manager->getEcapedString($_GET['page']);
575
-        }
576
-
577
-        $entries = array();
578
-
579
-        $last_page = true;
580
-        if ('' != $gym_id) {
581
-            $datas = $manager->getHistoryForGym($page, $gym_id);
582
-            foreach ($datas['data'] as $data) {
583
-                $data->gym_id = str_replace('.', '_', $data->gym_id);
584
-                $entries[] = $data;
585
-            }
586
-            $last_page = $datas['last_page'];
587
-
588
-            foreach ($entries as $idx => $entry) {
589
-                $entry->total_cp_diff = 0;
590
-                $entry->only_cp_changed = true;
591
-                if ($idx < count($entries) - 1) {
592
-                    $next_entry = $entries[$idx + 1];
593
-                    $entry->total_cp_diff = $entry->total_cp - $next_entry->total_cp;
594
-                    $entry->class = $entry->total_cp_diff > 0 ? 'gain' : ($entry->total_cp_diff < 0 ? 'loss' : '');
595
-                    $entry_pokemon = preg_split('/,/', $entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
596
-                    $next_entry_pokemon = preg_split('/,/', $next_entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
597
-                    $new_pokemon = array_diff($entry_pokemon, $next_entry_pokemon);
598
-                    $old_pokemon = array_diff($next_entry_pokemon, $entry_pokemon);
599
-                    foreach ($new_pokemon as $pkm) {
600
-                        $entry->pokemon[$pkm]->class = 'new';
601
-                    }
602
-                    foreach ($old_pokemon as $pkm) {
603
-                        $next_entry->pokemon[$pkm]->class = 'old';
604
-                    }
605
-                    if ($entry->team_id != $next_entry->team_id || $entry->pokemon_uids != $next_entry->pokemon_uids) {
606
-                        $entry->only_cp_changed = false;
607
-                    }
608
-                }
609
-                unset($entry->pokemon_uids);
610
-            }
611
-
612
-            if (count($entries) > 10) {
613
-                array_pop($entries);
614
-            }
615
-        }
616
-
617
-        $json = array();
618
-        $json['entries'] = $entries;
619
-        $locale = array();
620
-        $json['locale'] = $locale;
621
-        $json['last_page'] = $last_page;
622
-
623
-        header('Content-Type: application/json');
624
-        echo json_encode($json);
625
-
626
-        break;
627
-
628
-    case 'pokemon_slider_init':
629
-        $bounds = $manager->getPokemonSliderMinMax();
630
-
631
-        header('Content-Type: application/json');
632
-        echo json_encode($bounds);
633
-
634
-        break;
635
-
636
-    case 'pokemon_heatmap_points':
637
-        $json = '';
638
-        if (isset($_GET['start']) && isset($_GET['end']) && isset($_GET['pokemon_id'])) {
639
-            $start = date('Y-m-d H:i', (int) $_GET['start']);
640
-            $end = date('Y-m-d H:i', (int) $_GET['end']);
641
-            $pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
642
-            $points = $manager->getPokemonHeatmap($pokemon_id, $start, $end);
643
-
644
-            $json = json_encode($points);
645
-        }
646
-
647
-        header('Content-Type: application/json');
648
-        echo $json;
649
-        break;
650
-
651
-    case 'maps_localization_coordinates':
652
-        $coordinates = $manager->getMapsCoords();
653
-
654
-        header('Content-Type: application/json');
655
-        echo json_encode($coordinates);
656
-
657
-        break;
658
-
659
-    case 'pokemon_graph_data':
660
-        $json = '';
661
-        if (isset($_GET['pokemon_id'])) {
662
-            $pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
663
-            $array = $manager->getPokemonGraph($pokemon_id);
664
-
665
-            $json = json_encode($array);
666
-        }
667
-
668
-        header('Content-Type: application/json');
669
-        echo $json;
670
-        break;
671
-
672
-    case 'postRequest':
673
-        break;
674
-
675
-    default:
676
-        echo 'What do you mean?';
677
-        exit();
678
-    break;
441
+                    	}
442
+                	}
443
+            	}
444
+            	$gymData['infoWindow'] = $gymData['infoWindow'].'</div>';
445
+        	}
446
+
447
+        	header('Content-Type: application/json');
448
+        	echo json_encode($gymData);
449
+
450
+        	break;
451
+
452
+    	case 'trainer':
453
+        	$name = '';
454
+        	$page = '0';
455
+        	$team = 0;
456
+        	$ranking = 0;
457
+        	if (isset($_GET['name'])) {
458
+            	$trainer_name = $manager->getEcapedString($_GET['name']);
459
+        	}
460
+        	if (isset($_GET['team'])) {
461
+            	$team = $manager->getEcapedString($_GET['team']);
462
+        	}
463
+        	if (isset($_GET['page'])) {
464
+            	$page = $manager->getEcapedString($_GET['page']);
465
+        	}
466
+        	if (isset($_GET['ranking'])) {
467
+            	$ranking = $manager->getEcapedString($_GET['ranking']);
468
+        	}
469
+
470
+        	$trainers = $manager->getTrainers($trainer_name, $team, $page, $ranking);
471
+        	$json = array();
472
+        	$json['trainers'] = $trainers;
473
+        	$locale = array();
474
+        	$locale['today'] = $locales->TODAY;
475
+        	$locale['day'] = $locales->DAY;
476
+        	$locale['days'] = $locales->DAYS;
477
+        	$locale['ivAttack'] = $locales->IV_ATTACK;
478
+        	$locale['ivDefense'] = $locales->IV_DEFENSE;
479
+        	$locale['ivStamina'] = $locales->IV_STAMINA;
480
+        	$json['locale'] = $locale;
481
+
482
+        	header('Content-Type: application/json');
483
+        	echo json_encode($json);
484
+
485
+        	break;
486
+
487
+    	case 'raids':
488
+        	$page = '0';
489
+        	if (isset($_GET['page'])) {
490
+            	$page = $manager->getEcapedString($_GET['page']);
491
+        	}
492
+
493
+        	$datas = $manager->getAllRaids($page);
494
+        	$i = 1;
495
+        	$raids = array();
496
+        	foreach ($datas as $data) {
497
+            	$data->starttime = date('H:i', strtotime($data->start));
498
+            	$data->endtime = date('H:i', strtotime($data->end));
499
+            	$data->gym_id = str_replace('.', '_', $data->gym_id);
500
+            	if (isset($data->move_1)) {
501
+                	$move1 = $data->move_1;
502
+                	$data->quick_move = $move->$move1->name;
503
+            	} else {
504
+                	$data->quick_move = '?';
505
+            	}
506
+            	if (isset($data->move_2)) {
507
+                	$move2 = $data->move_2;
508
+                	$data->charge_move = $move->$move2->name;
509
+            	} else {
510
+                	$data->charge_move = '?';
511
+            	}
512
+            	$raids[10 * $page + $i] = $data;
513
+            	++$i;
514
+        	}
515
+        	$json = array();
516
+        	$json['raids'] = $raids;
517
+        	$locale = array();
518
+        	$locale['noraids'] = $locales->RAIDS_NONE;
519
+        	$json['locale'] = $locale;
520
+
521
+        	header('Content-Type: application/json');
522
+        	echo json_encode($json);
523
+
524
+        	break;
525
+
526
+    	case 'gyms':
527
+        	$page = '0';
528
+        	$ranking = 0;
529
+        	$gym_name = '';
530
+        	$team = '';
531
+        	if (isset($_GET['name']) && '' != $_GET['name']) {
532
+            	$gym_name = $manager->getEcapedString($_GET['name']);
533
+        	}
534
+        	if (isset($_GET['team']) && '' != $_GET['team']) {
535
+            	$team = $manager->getEcapedString($_GET['team']);
536
+        	}
537
+        	if (isset($_GET['page'])) {
538
+            	$page = $manager->getEcapedString($_GET['page']);
539
+        	}
540
+        	if (isset($_GET['ranking'])) {
541
+            	$ranking = $manager->getEcapedString($_GET['ranking']);
542
+        	}
543
+
544
+        	$datas = $manager->getGymHistories($gym_name, $team, $page, $ranking);
545
+        	$gyms = array();
546
+        	foreach ($datas as $data) {
547
+            	$pkm = array();
548
+            	if ($data->total_cp > 0) {
549
+                	$pkm = $manager->getGymHistoriesPokemon($data->gym_id);
550
+            	}
551
+            	$data->pokemon = $pkm;
552
+            	unset($data->pokemon_uids);
553
+            	$data->gym_id = str_replace('.', '_', $data->gym_id);
554
+            	$gyms[] = $data;
555
+        	}
556
+        	$json = array();
557
+        	$json['gyms'] = $gyms;
558
+        	$locale = array();
559
+        	$json['locale'] = $locale;
560
+
561
+        	header('Content-Type: application/json');
562
+        	echo json_encode($json);
563
+
564
+        	break;
565
+
566
+    	case 'gymhistory':
567
+        	$gym_id = '';
568
+        	$page = '0';
569
+        	if (isset($_GET['gym_id'])) {
570
+            	$gym_id = $manager->getEcapedString($_GET['gym_id']);
571
+            	$gym_id = str_replace('_', '.', $gym_id);
572
+        	}
573
+        	if (isset($_GET['page'])) {
574
+            	$page = $manager->getEcapedString($_GET['page']);
575
+        	}
576
+
577
+        	$entries = array();
578
+
579
+        	$last_page = true;
580
+        	if ('' != $gym_id) {
581
+            	$datas = $manager->getHistoryForGym($page, $gym_id);
582
+            	foreach ($datas['data'] as $data) {
583
+                	$data->gym_id = str_replace('.', '_', $data->gym_id);
584
+                	$entries[] = $data;
585
+            	}
586
+            	$last_page = $datas['last_page'];
587
+
588
+            	foreach ($entries as $idx => $entry) {
589
+                	$entry->total_cp_diff = 0;
590
+                	$entry->only_cp_changed = true;
591
+                	if ($idx < count($entries) - 1) {
592
+                    	$next_entry = $entries[$idx + 1];
593
+                    	$entry->total_cp_diff = $entry->total_cp - $next_entry->total_cp;
594
+                    	$entry->class = $entry->total_cp_diff > 0 ? 'gain' : ($entry->total_cp_diff < 0 ? 'loss' : '');
595
+                    	$entry_pokemon = preg_split('/,/', $entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
596
+                    	$next_entry_pokemon = preg_split('/,/', $next_entry->pokemon_uids, null, PREG_SPLIT_NO_EMPTY);
597
+                    	$new_pokemon = array_diff($entry_pokemon, $next_entry_pokemon);
598
+                    	$old_pokemon = array_diff($next_entry_pokemon, $entry_pokemon);
599
+                    	foreach ($new_pokemon as $pkm) {
600
+                        	$entry->pokemon[$pkm]->class = 'new';
601
+                    	}
602
+                    	foreach ($old_pokemon as $pkm) {
603
+                        	$next_entry->pokemon[$pkm]->class = 'old';
604
+                    	}
605
+                    	if ($entry->team_id != $next_entry->team_id || $entry->pokemon_uids != $next_entry->pokemon_uids) {
606
+                        	$entry->only_cp_changed = false;
607
+                    	}
608
+                	}
609
+                	unset($entry->pokemon_uids);
610
+            	}
611
+
612
+            	if (count($entries) > 10) {
613
+                	array_pop($entries);
614
+            	}
615
+        	}
616
+
617
+        	$json = array();
618
+        	$json['entries'] = $entries;
619
+        	$locale = array();
620
+        	$json['locale'] = $locale;
621
+        	$json['last_page'] = $last_page;
622
+
623
+        	header('Content-Type: application/json');
624
+        	echo json_encode($json);
625
+
626
+        	break;
627
+
628
+    	case 'pokemon_slider_init':
629
+        	$bounds = $manager->getPokemonSliderMinMax();
630
+
631
+        	header('Content-Type: application/json');
632
+        	echo json_encode($bounds);
633
+
634
+        	break;
635
+
636
+    	case 'pokemon_heatmap_points':
637
+        	$json = '';
638
+        	if (isset($_GET['start']) && isset($_GET['end']) && isset($_GET['pokemon_id'])) {
639
+            	$start = date('Y-m-d H:i', (int) $_GET['start']);
640
+            	$end = date('Y-m-d H:i', (int) $_GET['end']);
641
+            	$pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
642
+            	$points = $manager->getPokemonHeatmap($pokemon_id, $start, $end);
643
+
644
+            	$json = json_encode($points);
645
+        	}
646
+
647
+        	header('Content-Type: application/json');
648
+        	echo $json;
649
+        	break;
650
+
651
+    	case 'maps_localization_coordinates':
652
+        	$coordinates = $manager->getMapsCoords();
653
+
654
+        	header('Content-Type: application/json');
655
+        	echo json_encode($coordinates);
656
+
657
+        	break;
658
+
659
+    	case 'pokemon_graph_data':
660
+        	$json = '';
661
+        	if (isset($_GET['pokemon_id'])) {
662
+            	$pokemon_id = $manager->getEcapedString($_GET['pokemon_id']);
663
+            	$array = $manager->getPokemonGraph($pokemon_id);
664
+
665
+            	$json = json_encode($array);
666
+        	}
667
+
668
+        	header('Content-Type: application/json');
669
+        	echo $json;
670
+        	break;
671
+
672
+    	case 'postRequest':
673
+        	break;
674
+
675
+    	default:
676
+        	echo 'What do you mean?';
677
+        	exit();
678
+    	break;
679 679
 }
680 680
 
681 681
 if ('' != $postRequest) {
Please login to merge, or discard this patch.
core/process/queries/QueryManagerMysqlRocketmap.php 1 patch
Indentation   +641 added lines, -641 removed lines patch added patch discarded remove patch
@@ -2,193 +2,193 @@  discard block
 block discarded – undo
2 2
 
3 3
 final class QueryManagerMysqlRocketmap extends QueryManagerMysql
4 4
 {
5
-    public function __construct()
6
-    {
7
-        parent::__construct();
8
-    }
9
-
10
-    public function __destruct()
11
-    {
12
-        parent::__destruct();
13
-    }
14
-
15
-    ///////////
16
-    // Tester
17
-    ///////////
18
-
19
-    public function testTotalPokemon()
20
-    {
21
-        $req = 'SELECT COUNT(*) as total FROM pokemon';
22
-        $result = $this->mysqli->query($req);
23
-        if (!is_object($result)) {
24
-            return 1;
25
-        } else {
26
-            $data = $result->fetch_object();
27
-            $total = $data->total;
28
-
29
-            if (0 == $total) {
30
-                return 2;
31
-            }
32
-        }
33
-
34
-        return 0;
35
-    }
36
-
37
-    public function testTotalGyms()
38
-    {
39
-        $req = 'SELECT COUNT(*) as total FROM gym';
40
-        $result = $this->mysqli->query($req);
41
-        if (!is_object($result)) {
42
-            return 1;
43
-        } else {
44
-            $data = $result->fetch_object();
45
-            $total = $data->total;
46
-
47
-            if (0 == $total) {
48
-                return 2;
49
-            }
50
-        }
51
-
52
-        return 0;
53
-    }
54
-
55
-    public function testTotalPokestops()
56
-    {
57
-        $req = 'SELECT COUNT(*) as total FROM pokestop';
58
-        $result = $this->mysqli->query($req);
59
-        if (!is_object($result)) {
60
-            return 1;
61
-        } else {
62
-            $data = $result->fetch_object();
63
-            $total = $data->total;
64
-
65
-            if (0 == $total) {
66
-                return 2;
67
-            }
68
-        }
69
-
70
-        return 0;
71
-    }
72
-
73
-    /////////////
74
-    // Homepage
75
-    /////////////
76
-
77
-    public function getTotalPokemon()
78
-    {
79
-        $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()';
80
-        $result = $this->mysqli->query($req);
81
-        $data = $result->fetch_object();
82
-
83
-        return $data;
84
-    }
85
-
86
-    public function getTotalLures()
87
-    {
88
-        $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()';
89
-        $result = $this->mysqli->query($req);
90
-        $data = $result->fetch_object();
91
-
92
-        return $data;
93
-    }
94
-
95
-    public function getTotalGyms()
96
-    {
97
-        $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym';
98
-        $result = $this->mysqli->query($req);
99
-        $data = $result->fetch_object();
100
-
101
-        return $data;
102
-    }
103
-
104
-    public function getTotalRaids()
105
-    {
106
-        $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND  end >= UTC_TIMESTAMP()';
107
-        $result = $this->mysqli->query($req);
108
-        $data = $result->fetch_object();
109
-
110
-        return $data;
111
-    }
112
-
113
-    public function getTotalGymsForTeam($team_id)
114
-    {
115
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
116
-        $result = $this->mysqli->query($req);
117
-        $data = $result->fetch_object();
118
-
119
-        return $data;
120
-    }
121
-
122
-    public function getRecentAll()
123
-    {
124
-        $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
5
+	public function __construct()
6
+	{
7
+		parent::__construct();
8
+	}
9
+
10
+	public function __destruct()
11
+	{
12
+		parent::__destruct();
13
+	}
14
+
15
+	///////////
16
+	// Tester
17
+	///////////
18
+
19
+	public function testTotalPokemon()
20
+	{
21
+		$req = 'SELECT COUNT(*) as total FROM pokemon';
22
+		$result = $this->mysqli->query($req);
23
+		if (!is_object($result)) {
24
+			return 1;
25
+		} else {
26
+			$data = $result->fetch_object();
27
+			$total = $data->total;
28
+
29
+			if (0 == $total) {
30
+				return 2;
31
+			}
32
+		}
33
+
34
+		return 0;
35
+	}
36
+
37
+	public function testTotalGyms()
38
+	{
39
+		$req = 'SELECT COUNT(*) as total FROM gym';
40
+		$result = $this->mysqli->query($req);
41
+		if (!is_object($result)) {
42
+			return 1;
43
+		} else {
44
+			$data = $result->fetch_object();
45
+			$total = $data->total;
46
+
47
+			if (0 == $total) {
48
+				return 2;
49
+			}
50
+		}
51
+
52
+		return 0;
53
+	}
54
+
55
+	public function testTotalPokestops()
56
+	{
57
+		$req = 'SELECT COUNT(*) as total FROM pokestop';
58
+		$result = $this->mysqli->query($req);
59
+		if (!is_object($result)) {
60
+			return 1;
61
+		} else {
62
+			$data = $result->fetch_object();
63
+			$total = $data->total;
64
+
65
+			if (0 == $total) {
66
+				return 2;
67
+			}
68
+		}
69
+
70
+		return 0;
71
+	}
72
+
73
+	/////////////
74
+	// Homepage
75
+	/////////////
76
+
77
+	public function getTotalPokemon()
78
+	{
79
+		$req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()';
80
+		$result = $this->mysqli->query($req);
81
+		$data = $result->fetch_object();
82
+
83
+		return $data;
84
+	}
85
+
86
+	public function getTotalLures()
87
+	{
88
+		$req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()';
89
+		$result = $this->mysqli->query($req);
90
+		$data = $result->fetch_object();
91
+
92
+		return $data;
93
+	}
94
+
95
+	public function getTotalGyms()
96
+	{
97
+		$req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym';
98
+		$result = $this->mysqli->query($req);
99
+		$data = $result->fetch_object();
100
+
101
+		return $data;
102
+	}
103
+
104
+	public function getTotalRaids()
105
+	{
106
+		$req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP AND  end >= UTC_TIMESTAMP()';
107
+		$result = $this->mysqli->query($req);
108
+		$data = $result->fetch_object();
109
+
110
+		return $data;
111
+	}
112
+
113
+	public function getTotalGymsForTeam($team_id)
114
+	{
115
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'";
116
+		$result = $this->mysqli->query($req);
117
+		$data = $result->fetch_object();
118
+
119
+		return $data;
120
+	}
121
+
122
+	public function getRecentAll()
123
+	{
124
+		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
125 125
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
126 126
 				latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
127 127
 				FROM pokemon
128 128
 				ORDER BY last_modified DESC
129 129
 				LIMIT 0,12";
130
-        $result = $this->mysqli->query($req);
131
-        $data = array();
132
-        if ($result->num_rows > 0) {
133
-            while ($row = $result->fetch_object()) {
134
-                $data[] = $row;
135
-            }
136
-        }
137
-
138
-        return $data;
139
-    }
140
-
141
-    public function getRecentMythic($mythic_pokemons)
142
-    {
143
-        $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
130
+		$result = $this->mysqli->query($req);
131
+		$data = array();
132
+		if ($result->num_rows > 0) {
133
+			while ($row = $result->fetch_object()) {
134
+				$data[] = $row;
135
+			}
136
+		}
137
+
138
+		return $data;
139
+	}
140
+
141
+	public function getRecentMythic($mythic_pokemons)
142
+	{
143
+		$req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified,
144 144
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
145 145
 				latitude, longitude, cp, individual_attack, individual_defense, individual_stamina
146 146
 				FROM pokemon
147 147
 				WHERE pokemon_id IN (".implode(',', $mythic_pokemons).')
148 148
 				ORDER BY last_modified DESC
149 149
 				LIMIT 0,12';
150
-        $result = $this->mysqli->query($req);
151
-        $data = array();
152
-        if ($result->num_rows > 0) {
153
-            while ($row = $result->fetch_object()) {
154
-                $data[] = $row;
155
-            }
156
-        }
157
-
158
-        return $data;
159
-    }
160
-
161
-    ///////////////////
162
-    // Single Pokemon
163
-    ///////////////////
164
-
165
-    public function getGymsProtectedByPokemon($pokemon_id)
166
-    {
167
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
168
-        $result = $this->mysqli->query($req);
169
-        $data = $result->fetch_object();
170
-
171
-        return $data;
172
-    }
173
-
174
-    public function getPokemonLastSeen($pokemon_id)
175
-    {
176
-        $req = "SELECT disappear_time,
150
+		$result = $this->mysqli->query($req);
151
+		$data = array();
152
+		if ($result->num_rows > 0) {
153
+			while ($row = $result->fetch_object()) {
154
+				$data[] = $row;
155
+			}
156
+		}
157
+
158
+		return $data;
159
+	}
160
+
161
+	///////////////////
162
+	// Single Pokemon
163
+	///////////////////
164
+
165
+	public function getGymsProtectedByPokemon($pokemon_id)
166
+	{
167
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'";
168
+		$result = $this->mysqli->query($req);
169
+		$data = $result->fetch_object();
170
+
171
+		return $data;
172
+	}
173
+
174
+	public function getPokemonLastSeen($pokemon_id)
175
+	{
176
+		$req = "SELECT disappear_time,
177 177
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
178 178
 				latitude, longitude
179 179
 				FROM pokemon
180 180
 				WHERE pokemon_id = '".$pokemon_id."'
181 181
 				ORDER BY disappear_time DESC
182 182
 				LIMIT 0,1";
183
-        $result = $this->mysqli->query($req);
184
-        $data = $result->fetch_object();
183
+		$result = $this->mysqli->query($req);
184
+		$data = $result->fetch_object();
185 185
 
186
-        return $data;
187
-    }
186
+		return $data;
187
+	}
188 188
 
189
-    public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
-    {
191
-        $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime,
189
+	public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
+	{
191
+		$req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime,
192 192
 				pokemon_id, disappear_time, latitude, longitude,
193 193
 				cp, individual_attack, individual_defense, individual_stamina,
194 194
 				ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV,
@@ -197,22 +197,22 @@  discard block
 block discarded – undo
197 197
 				WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
198 198
 				ORDER BY $top_order_by $top_direction, disappear_time DESC
199 199
 				LIMIT 0,50";
200
-        $result = $this->mysqli->query($req);
201
-        $top = array();
202
-        while ($data = $result->fetch_object()) {
203
-            $top[] = $data;
204
-        }
205
-
206
-        return $top;
207
-    }
208
-
209
-    public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
210
-    {
211
-        $trainer_blacklist = '';
212
-        if (!empty(self::$config->system->trainer_blacklist)) {
213
-            $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
214
-        }
215
-        $req = "SELECT trainer_name,
200
+		$result = $this->mysqli->query($req);
201
+		$top = array();
202
+		while ($data = $result->fetch_object()) {
203
+			$top[] = $data;
204
+		}
205
+
206
+		return $top;
207
+	}
208
+
209
+	public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
210
+	{
211
+		$trainer_blacklist = '';
212
+		if (!empty(self::$config->system->trainer_blacklist)) {
213
+			$trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
214
+		}
215
+		$req = "SELECT trainer_name,
216 216
 				ROUND((100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV,
217 217
 				move_1, move_2, cp,
218 218
 				DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen
@@ -220,202 +220,202 @@  discard block
 block discarded – undo
220 220
 				WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
221 221
 				ORDER BY $best_order_by $best_direction, trainer_name ASC
222 222
 				LIMIT 0,50";
223
-        $result = $this->mysqli->query($req);
224
-        $toptrainer = array();
225
-        while ($data = $result->fetch_object()) {
226
-            $toptrainer[] = $data;
227
-        }
223
+		$result = $this->mysqli->query($req);
224
+		$toptrainer = array();
225
+		while ($data = $result->fetch_object()) {
226
+			$toptrainer[] = $data;
227
+		}
228 228
 
229
-        return $toptrainer;
230
-    }
229
+		return $toptrainer;
230
+	}
231 231
 
232
-    public function getPokemonHeatmap($pokemon_id, $start, $end)
233
-    {
232
+	public function getPokemonHeatmap($pokemon_id, $start, $end)
233
+	{
234 234
 		$req = "SELECT latitude, longitude
235 235
 				FROM pokemon
236 236
 				WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."'
237 237
 				LIMIT 10000";
238
-        $result = $this->mysqli->query($req);
239
-        $points = array();
240
-        while ($data = $result->fetch_object()) {
241
-            $points[] = $data;
242
-        }
243
-
244
-        return $points;
245
-    }
246
-
247
-    public function getPokemonGraph($pokemon_id)
248
-    {
249
-        $req = "SELECT COUNT(*) AS total,
238
+		$result = $this->mysqli->query($req);
239
+		$points = array();
240
+		while ($data = $result->fetch_object()) {
241
+			$points[] = $data;
242
+		}
243
+
244
+		return $points;
245
+	}
246
+
247
+	public function getPokemonGraph($pokemon_id)
248
+	{
249
+		$req = "SELECT COUNT(*) AS total,
250 250
 				HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour
251 251
 				FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
252 252
 				GROUP BY disappear_hour
253 253
 				ORDER BY disappear_hour";
254
-        $result = $this->mysqli->query($req);
255
-        $array = array_fill(0, 24, 0);
256
-        while ($result && $data = $result->fetch_object()) {
257
-            $array[$data->disappear_hour] = $data->total;
258
-        }
259
-        // shift array because AM/PM starts at 1AM not 0:00
260
-        $array[] = $array[0];
261
-        array_shift($array);
262
-
263
-        return $array;
264
-    }
265
-
266
-    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
267
-    {
268
-        $inmap_pkms_filter = '';
269
-        $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
270
-        $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
271
-        $resultTestIv = $this->mysqli->query($reqTestIv);
272
-        $testIv = $resultTestIv->fetch_object();
273
-        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
274
-            foreach ($inmap_pokemons as $inmap) {
275
-                $inmap_pkms_filter .= "'".$inmap."',";
276
-            }
277
-            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
278
-            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
279
-        }
280
-        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
281
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
282
-        }
283
-        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
284
-            $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
285
-        }
286
-        $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
254
+		$result = $this->mysqli->query($req);
255
+		$array = array_fill(0, 24, 0);
256
+		while ($result && $data = $result->fetch_object()) {
257
+			$array[$data->disappear_hour] = $data->total;
258
+		}
259
+		// shift array because AM/PM starts at 1AM not 0:00
260
+		$array[] = $array[0];
261
+		array_shift($array);
262
+
263
+		return $array;
264
+	}
265
+
266
+	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
267
+	{
268
+		$inmap_pkms_filter = '';
269
+		$where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
270
+		$reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where;
271
+		$resultTestIv = $this->mysqli->query($reqTestIv);
272
+		$testIv = $resultTestIv->fetch_object();
273
+		if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
274
+			foreach ($inmap_pokemons as $inmap) {
275
+				$inmap_pkms_filter .= "'".$inmap."',";
276
+			}
277
+			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
278
+			$where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
279
+		}
280
+		if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
281
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') ';
282
+		}
283
+		if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
284
+			$where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') ';
285
+		}
286
+		$req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time,
287 287
 				CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real,
288 288
 				individual_attack, individual_defense, individual_stamina, move_1, move_2
289 289
 				FROM pokemon ".$where.'
290 290
 				LIMIT 5000';
291
-        $result = $this->mysqli->query($req);
292
-        $spawns = array();
293
-        while ($data = $result->fetch_object()) {
294
-            $spawns[] = $data;
295
-        }
296
-
297
-        return $spawns;
298
-    }
299
-
300
-    public function getPokemonSliderMinMax()
301
-    {
302
-        $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
303
-        $result = $this->mysqli->query($req);
304
-        $data = $result->fetch_object();
305
-
306
-        return $data;
307
-    }
308
-
309
-    public function getMapsCoords()
310
-    {
311
-        $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
291
+		$result = $this->mysqli->query($req);
292
+		$spawns = array();
293
+		while ($data = $result->fetch_object()) {
294
+			$spawns[] = $data;
295
+		}
296
+
297
+		return $spawns;
298
+	}
299
+
300
+	public function getPokemonSliderMinMax()
301
+	{
302
+		$req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon';
303
+		$result = $this->mysqli->query($req);
304
+		$data = $result->fetch_object();
305
+
306
+		return $data;
307
+	}
308
+
309
+	public function getMapsCoords()
310
+	{
311
+		$req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude,
312 312
 				MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude
313 313
 				FROM spawnpoint';
314
-        $result = $this->mysqli->query($req);
315
-        $data = $result->fetch_object();
314
+		$result = $this->mysqli->query($req);
315
+		$data = $result->fetch_object();
316 316
 
317
-        return $data;
318
-    }
317
+		return $data;
318
+	}
319 319
 
320
-    public function getPokemonCount($pokemon_id)
321
-    {
322
-        $req = 'SELECT count, last_seen, latitude, longitude
320
+	public function getPokemonCount($pokemon_id)
321
+	{
322
+		$req = 'SELECT count, last_seen, latitude, longitude
323 323
 				FROM pokemon_stats
324 324
 				WHERE pid = '.$pokemon_id;
325
-        $result = $this->mysqli->query($req);
326
-        $data = $result->fetch_object();
325
+		$result = $this->mysqli->query($req);
326
+		$data = $result->fetch_object();
327 327
 
328
-        return $data;
329
-    }
328
+		return $data;
329
+	}
330 330
 
331
-    public function getRaidCount($pokemon_id)
332
-    {
333
-        $req = 'SELECT count, last_seen, latitude, longitude
331
+	public function getRaidCount($pokemon_id)
332
+	{
333
+		$req = 'SELECT count, last_seen, latitude, longitude
334 334
 				FROM raid_stats
335 335
 				WHERE pid = '.$pokemon_id;
336
-        $result = $this->mysqli->query($req);
337
-        $data = $result->fetch_object();
336
+		$result = $this->mysqli->query($req);
337
+		$data = $result->fetch_object();
338 338
 
339
-        return $data;
340
-    }
339
+		return $data;
340
+	}
341 341
 
342
-    ///////////////
343
-    // Pokestops
344
-    //////////////
342
+	///////////////
343
+	// Pokestops
344
+	//////////////
345 345
 
346
-    public function getTotalPokestops()
347
-    {
348
-        $req = 'SELECT COUNT(*) as total FROM pokestop';
349
-        $result = $this->mysqli->query($req);
350
-        $data = $result->fetch_object();
346
+	public function getTotalPokestops()
347
+	{
348
+		$req = 'SELECT COUNT(*) as total FROM pokestop';
349
+		$result = $this->mysqli->query($req);
350
+		$data = $result->fetch_object();
351 351
 
352
-        return $data;
353
-    }
352
+		return $data;
353
+	}
354 354
 
355
-    public function getAllPokestops()
356
-    {
357
-        $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
355
+	public function getAllPokestops()
356
+	{
357
+		$req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now,
358 358
 				CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."') AS lure_expiration_real
359 359
 				FROM pokestop";
360
-        $result = $this->mysqli->query($req);
361
-        $pokestops = array();
362
-        while ($data = $result->fetch_object()) {
363
-            $pokestops[] = $data;
364
-        }
365
-
366
-        return $pokestops;
367
-    }
368
-
369
-    /////////
370
-    // Gyms
371
-    /////////
372
-
373
-    public function getTeamGuardians($team_id)
374
-    {
375
-        $req = "SELECT COUNT(*) AS total, guard_pokemon_id
360
+		$result = $this->mysqli->query($req);
361
+		$pokestops = array();
362
+		while ($data = $result->fetch_object()) {
363
+			$pokestops[] = $data;
364
+		}
365
+
366
+		return $pokestops;
367
+	}
368
+
369
+	/////////
370
+	// Gyms
371
+	/////////
372
+
373
+	public function getTeamGuardians($team_id)
374
+	{
375
+		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
376 376
 				FROM gym WHERE team_id = '".$team_id."'
377 377
 				GROUP BY guard_pokemon_id
378 378
 				ORDER BY total DESC
379 379
 				LIMIT 0,3";
380
-        $result = $this->mysqli->query($req);
381
-        $datas = array();
382
-        while ($data = $result->fetch_object()) {
383
-            $datas[] = $data;
384
-        }
385
-
386
-        return $datas;
387
-    }
388
-
389
-    public function getOwnedAndPoints($team_id)
390
-    {
391
-        $req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
380
+		$result = $this->mysqli->query($req);
381
+		$datas = array();
382
+		while ($data = $result->fetch_object()) {
383
+			$datas[] = $data;
384
+		}
385
+
386
+		return $datas;
387
+	}
388
+
389
+	public function getOwnedAndPoints($team_id)
390
+	{
391
+		$req = "SELECT COUNT(DISTINCT(gym_id)) AS total,
392 392
 				ROUND(AVG(total_cp),0) AS average_points
393 393
 				FROM gym
394 394
 				WHERE team_id = '".$team_id."'";
395
-        $result = $this->mysqli->query($req);
396
-        $data = $result->fetch_object();
395
+		$result = $this->mysqli->query($req);
396
+		$data = $result->fetch_object();
397 397
 
398
-        return $data;
399
-    }
398
+		return $data;
399
+	}
400 400
 
401
-    public function getAllGyms()
402
-    {
403
-        $req = "SELECT gym_id, team_id, latitude, longitude,
401
+	public function getAllGyms()
402
+	{
403
+		$req = "SELECT gym_id, team_id, latitude, longitude,
404 404
 				CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
405 405
 				(6 - slots_available) AS level
406 406
 				FROM gym";
407
-        $result = $this->mysqli->query($req);
408
-        $gyms = array();
409
-        while ($data = $result->fetch_object()) {
410
-            $gyms[] = $data;
411
-        }
412
-
413
-        return $gyms;
414
-    }
415
-
416
-    public function getGymData($gym_id)
417
-    {
418
-        $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
407
+		$result = $this->mysqli->query($req);
408
+		$gyms = array();
409
+		while ($data = $result->fetch_object()) {
410
+			$gyms[] = $data;
411
+		}
412
+
413
+		return $gyms;
414
+	}
415
+
416
+	public function getGymData($gym_id)
417
+	{
418
+		$req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team,
419 419
 				CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned,
420 420
 				gym.guard_pokemon_id AS guard_pokemon_id,
421 421
 				gym.total_cp AS total_cp,
@@ -423,53 +423,53 @@  discard block
 block discarded – undo
423 423
 				FROM gymdetails
424 424
 				LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id
425 425
 				WHERE gym.gym_id='".$gym_id."'";
426
-        $result = $this->mysqli->query($req);
427
-        $data = $result->fetch_object();
426
+		$result = $this->mysqli->query($req);
427
+		$data = $result->fetch_object();
428 428
 
429
-        return $data;
430
-    }
429
+		return $data;
430
+	}
431 431
 
432
-    public function getGymDefenders($gym_id)
433
-    {
434
-        $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
432
+	public function getGymDefenders($gym_id)
433
+	{
434
+		$req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id
435 435
 				FROM gympokemon
436 436
 				INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid
437 437
 				GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id
438 438
 				HAVING gymmember.gym_id='".$gym_id."'
439 439
 				ORDER BY cp DESC";
440
-        $result = $this->mysqli->query($req);
441
-        $defenders = array();
442
-        while ($data = $result->fetch_object()) {
443
-            $defenders[] = $data;
444
-        }
445
-
446
-        return $defenders;
447
-    }
448
-
449
-    ////////////////
450
-    // Gym History
451
-    ////////////////
452
-
453
-    public function getGymHistories($gym_name, $team, $page, $ranking)
454
-    {
455
-        $where = '';
456
-        if (isset($gym_name) && '' != $gym_name) {
457
-            $where = " WHERE name LIKE '%".$gym_name."%'";
458
-        }
459
-        if (isset($team) && '' != $team) {
460
-            $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
461
-        }
462
-        switch ($ranking) {
463
-            case 1:
464
-                $order = ' ORDER BY name, last_modified DESC';
465
-                break;
466
-            case 2:
467
-                $order = ' ORDER BY total_cp DESC, last_modified DESC';
468
-                break;
469
-            default:
470
-                $order = ' ORDER BY last_modified DESC, name';
471
-        }
472
-        $req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
440
+		$result = $this->mysqli->query($req);
441
+		$defenders = array();
442
+		while ($data = $result->fetch_object()) {
443
+			$defenders[] = $data;
444
+		}
445
+
446
+		return $defenders;
447
+	}
448
+
449
+	////////////////
450
+	// Gym History
451
+	////////////////
452
+
453
+	public function getGymHistories($gym_name, $team, $page, $ranking)
454
+	{
455
+		$where = '';
456
+		if (isset($gym_name) && '' != $gym_name) {
457
+			$where = " WHERE name LIKE '%".$gym_name."%'";
458
+		}
459
+		if (isset($team) && '' != $team) {
460
+			$where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team;
461
+		}
462
+		switch ($ranking) {
463
+			case 1:
464
+				$order = ' ORDER BY name, last_modified DESC';
465
+				break;
466
+			case 2:
467
+				$order = ' ORDER BY total_cp DESC, last_modified DESC';
468
+				break;
469
+			default:
470
+				$order = ' ORDER BY last_modified DESC, name';
471
+		}
472
+		$req = "SELECT gymdetails.gym_id, name, team_id, total_cp,
473 473
 				(6 - slots_available) as pokemon_count,
474 474
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
475 475
 				FROM gymdetails
@@ -477,93 +477,93 @@  discard block
 block discarded – undo
477 477
 				ON gymdetails.gym_id = gym.gym_id
478 478
 				".$where.$order."
479 479
 				LIMIT ".($page * 10).",10";
480
-        $result = $this->mysqli->query($req);
481
-        $gym_history = array();
482
-        while ($data = $result->fetch_object()) {
483
-            $gym_history[] = $data;
484
-        }
485
-
486
-        return $gym_history;
487
-    }
488
-
489
-    public function getGymHistoriesPokemon($gym_id)
490
-    {
491
-        $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
480
+		$result = $this->mysqli->query($req);
481
+		$gym_history = array();
482
+		while ($data = $result->fetch_object()) {
483
+			$gym_history[] = $data;
484
+		}
485
+
486
+		return $gym_history;
487
+	}
488
+
489
+	public function getGymHistoriesPokemon($gym_id)
490
+	{
491
+		$req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name
492 492
 				FROM gymmember
493 493
 				LEFT JOIN gympokemon
494 494
 				ON gymmember.pokemon_uid = gympokemon.pokemon_uid
495 495
 				WHERE gymmember.gym_id = '".$gym_id."'
496 496
 				ORDER BY deployment_time";
497
-        $result = $this->mysqli->query($req);
498
-        $pokemons = array();
499
-        while ($data = $result->fetch_object()) {
500
-            $pokemons[] = $data;
501
-        }
502
-
503
-        return $pokemons;
504
-    }
505
-
506
-    public function getHistoryForGym($page, $gym_id)
507
-    {
508
-        if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
509
-            $pageSize = 25;
510
-        } else {
511
-            $pageSize = 10;
512
-        }
513
-        $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
497
+		$result = $this->mysqli->query($req);
498
+		$pokemons = array();
499
+		while ($data = $result->fetch_object()) {
500
+			$pokemons[] = $data;
501
+		}
502
+
503
+		return $pokemons;
504
+	}
505
+
506
+	public function getHistoryForGym($page, $gym_id)
507
+	{
508
+		if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
509
+			$pageSize = 25;
510
+		} else {
511
+			$pageSize = 10;
512
+		}
513
+		$req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count,
514 514
 				CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified
515 515
 				FROM gymhistory
516 516
 				WHERE gym_id='".$gym_id."'
517 517
 				ORDER BY last_modified DESC
518 518
 				LIMIT ".($page * $pageSize).','.($pageSize + 1);
519
-        $result = $this->mysqli->query($req);
520
-        $history = array();
521
-        $count = 0;
522
-        while ($data = $result->fetch_object()) {
523
-            ++$count;
524
-            $pkm = array();
525
-            if (0 == $data->total_cp) {
526
-                $data->pokemon_uids = '';
527
-                $data->pokemon_count = 0;
528
-            }
529
-            if ('' != $data->pokemon_uids) {
530
-                $pkm_uids = explode(',', $data->pokemon_uids);
531
-                $pkm = $this->getHistoryForGymPokemon($pkm_uids);
532
-            }
533
-            $data->pokemon = $pkm;
534
-            $history[] = $data;
535
-        }
536
-        if ($count !== ($pageSize + 1)) {
537
-            $last_page = true;
538
-        } else {
539
-            $last_page = false;
540
-        }
541
-
542
-        return array('last_page' => $last_page, 'data' => $history);
543
-    }
544
-
545
-    private function getHistoryForGymPokemon($pkm_uids)
546
-    {
547
-        $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
519
+		$result = $this->mysqli->query($req);
520
+		$history = array();
521
+		$count = 0;
522
+		while ($data = $result->fetch_object()) {
523
+			++$count;
524
+			$pkm = array();
525
+			if (0 == $data->total_cp) {
526
+				$data->pokemon_uids = '';
527
+				$data->pokemon_count = 0;
528
+			}
529
+			if ('' != $data->pokemon_uids) {
530
+				$pkm_uids = explode(',', $data->pokemon_uids);
531
+				$pkm = $this->getHistoryForGymPokemon($pkm_uids);
532
+			}
533
+			$data->pokemon = $pkm;
534
+			$history[] = $data;
535
+		}
536
+		if ($count !== ($pageSize + 1)) {
537
+			$last_page = true;
538
+		} else {
539
+			$last_page = false;
540
+		}
541
+
542
+		return array('last_page' => $last_page, 'data' => $history);
543
+	}
544
+
545
+	private function getHistoryForGymPokemon($pkm_uids)
546
+	{
547
+		$req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name
548 548
 				FROM gympokemon
549 549
 				WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."')
550 550
 				ORDER BY FIND_IN_SET(pokemon_uid, '".implode(',', $pkm_uids)."')";
551
-        $result = $this->mysqli->query($req);
552
-        $pokemons = array();
553
-        while ($data = $result->fetch_object()) {
554
-            $pokemons[$data->pokemon_uid] = $data;
555
-        }
556
-
557
-        return $pokemons;
558
-    }
559
-
560
-    ///////////
561
-    // Raids
562
-    ///////////
563
-
564
-    public function getAllRaids($page)
565
-    {
566
-        $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
551
+		$result = $this->mysqli->query($req);
552
+		$pokemons = array();
553
+		while ($data = $result->fetch_object()) {
554
+			$pokemons[$data->pokemon_uid] = $data;
555
+		}
556
+
557
+		return $pokemons;
558
+	}
559
+
560
+	///////////
561
+	// Raids
562
+	///////////
563
+
564
+	public function getAllRaids($page)
565
+	{
566
+		$req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2,
567 567
 				CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn,
568 568
 				CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start,
569 569
 				CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end,
@@ -575,121 +575,121 @@  discard block
 block discarded – undo
575 575
 				WHERE raid.end > UTC_TIMESTAMP()
576 576
 				ORDER BY raid.level DESC, raid.start
577 577
 				LIMIT ".($page * 10).",10";
578
-        $result = $this->mysqli->query($req);
579
-        $raids = array();
580
-        while ($data = $result->fetch_object()) {
581
-            $raids[] = $data;
582
-        }
583
-
584
-        return $raids;
585
-    }
586
-
587
-    //////////////
588
-    // Trainers
589
-    //////////////
590
-
591
-    public function getTrainers($trainer_name, $team, $page, $ranking)
592
-    {
593
-        $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
594
-        foreach ($trainers as $trainer) {
595
-            $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
596
-            $active_gyms = 0;
597
-            $pkmCount = 0;
598
-            $trainer->pokemons = array();
599
-            $active_pokemon = $this->getTrainerActivePokemon($trainer->name);
600
-            foreach ($active_pokemon as $pokemon) {
601
-                ++$active_gyms;
602
-                $trainer->pokemons[$pkmCount++] = $pokemon;
603
-            }
604
-            $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
605
-            foreach ($inactive_pokemon as $pokemon) {
606
-                $trainer->pokemons[$pkmCount++] = $pokemon;
607
-            }
608
-            $trainer->gyms = ''.$active_gyms;
609
-        }
610
-
611
-        return $trainers;
612
-    }
613
-
614
-    public function getTrainerLevelCount($team_id)
615
-    {
616
-        $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
617
-        if (!empty(self::$config->system->trainer_blacklist)) {
618
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
619
-        }
620
-        $req .= ' GROUP BY level';
621
-        $result = $this->mysqli->query($req);
622
-        $levelData = array();
623
-        while ($data = $result->fetch_object()) {
624
-            $levelData[$data->level] = $data->count;
625
-        }
626
-        for ($i = 5; $i <= 40; ++$i) {
627
-            if (!isset($levelData[$i])) {
628
-                $levelData[$i] = 0;
629
-            }
630
-        }
631
-        // sort array again
632
-        ksort($levelData);
633
-
634
-        return $levelData;
635
-    }
636
-
637
-    private function getTrainerData($trainer_name, $team, $page, $ranking)
638
-    {
639
-        $where = '';
640
-        if (!empty(self::$config->system->trainer_blacklist)) {
641
-            $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
642
-        }
643
-        if ('' != $trainer_name) {
644
-            $where = " HAVING name LIKE '%".$trainer_name."%'";
645
-        }
646
-        if (0 != $team) {
647
-            $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
648
-        }
649
-        switch ($ranking) {
650
-            case 1:
651
-                $order = ' ORDER BY active DESC, level DESC';
652
-                break;
653
-            case 2:
654
-                $order = ' ORDER BY maxCp DESC, level DESC';
655
-                break;
656
-            default:
657
-                $order = ' ORDER BY level DESC, active DESC';
658
-        }
659
-        $order .= ', last_seen DESC, name ';
660
-        $limit = ' LIMIT '.($page * 10).',10 ';
661
-        $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
578
+		$result = $this->mysqli->query($req);
579
+		$raids = array();
580
+		while ($data = $result->fetch_object()) {
581
+			$raids[] = $data;
582
+		}
583
+
584
+		return $raids;
585
+	}
586
+
587
+	//////////////
588
+	// Trainers
589
+	//////////////
590
+
591
+	public function getTrainers($trainer_name, $team, $page, $ranking)
592
+	{
593
+		$trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking);
594
+		foreach ($trainers as $trainer) {
595
+			$trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank;
596
+			$active_gyms = 0;
597
+			$pkmCount = 0;
598
+			$trainer->pokemons = array();
599
+			$active_pokemon = $this->getTrainerActivePokemon($trainer->name);
600
+			foreach ($active_pokemon as $pokemon) {
601
+				++$active_gyms;
602
+				$trainer->pokemons[$pkmCount++] = $pokemon;
603
+			}
604
+			$inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name);
605
+			foreach ($inactive_pokemon as $pokemon) {
606
+				$trainer->pokemons[$pkmCount++] = $pokemon;
607
+			}
608
+			$trainer->gyms = ''.$active_gyms;
609
+		}
610
+
611
+		return $trainers;
612
+	}
613
+
614
+	public function getTrainerLevelCount($team_id)
615
+	{
616
+		$req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'";
617
+		if (!empty(self::$config->system->trainer_blacklist)) {
618
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
619
+		}
620
+		$req .= ' GROUP BY level';
621
+		$result = $this->mysqli->query($req);
622
+		$levelData = array();
623
+		while ($data = $result->fetch_object()) {
624
+			$levelData[$data->level] = $data->count;
625
+		}
626
+		for ($i = 5; $i <= 40; ++$i) {
627
+			if (!isset($levelData[$i])) {
628
+				$levelData[$i] = 0;
629
+			}
630
+		}
631
+		// sort array again
632
+		ksort($levelData);
633
+
634
+		return $levelData;
635
+	}
636
+
637
+	private function getTrainerData($trainer_name, $team, $page, $ranking)
638
+	{
639
+		$where = '';
640
+		if (!empty(self::$config->system->trainer_blacklist)) {
641
+			$where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
642
+		}
643
+		if ('' != $trainer_name) {
644
+			$where = " HAVING name LIKE '%".$trainer_name."%'";
645
+		}
646
+		if (0 != $team) {
647
+			$where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
648
+		}
649
+		switch ($ranking) {
650
+			case 1:
651
+				$order = ' ORDER BY active DESC, level DESC';
652
+				break;
653
+			case 2:
654
+				$order = ' ORDER BY maxCp DESC, level DESC';
655
+				break;
656
+			default:
657
+				$order = ' ORDER BY level DESC, active DESC';
658
+		}
659
+		$order .= ', last_seen DESC, name ';
660
+		$limit = ' LIMIT '.($page * 10).',10 ';
661
+		$req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp
662 662
 				FROM trainer
663 663
 				LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned
664 664
 				FROM gympokemon
665 665
 				INNER JOIN (SELECT gymmember.pokemon_uid, gymmember.gym_id FROM gymmember GROUP BY gymmember.pokemon_uid, gymmember.gym_id HAVING gymmember.gym_id <> '') AS filtered_gymmember
666 666
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name
667 667
 				GROUP BY trainer.name ".$where.$order.$limit;
668
-        $result = $this->mysqli->query($req);
669
-        $trainers = array();
670
-        while ($data = $result->fetch_object()) {
671
-            $data->last_seen = date('Y-m-d', strtotime($data->last_seen));
672
-            $trainers[$data->name] = $data;
673
-        }
674
-
675
-        return $trainers;
676
-    }
677
-
678
-    private function getTrainerLevelRating($level)
679
-    {
680
-        $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
681
-        if (!empty(self::$config->system->trainer_blacklist)) {
682
-            $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
683
-        }
684
-        $result = $this->mysqli->query($req);
685
-        $data = $result->fetch_object();
686
-
687
-        return $data;
688
-    }
689
-
690
-    private function getTrainerActivePokemon($trainer_name)
691
-    {
692
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
668
+		$result = $this->mysqli->query($req);
669
+		$trainers = array();
670
+		while ($data = $result->fetch_object()) {
671
+			$data->last_seen = date('Y-m-d', strtotime($data->last_seen));
672
+			$trainers[$data->name] = $data;
673
+		}
674
+
675
+		return $trainers;
676
+	}
677
+
678
+	private function getTrainerLevelRating($level)
679
+	{
680
+		$req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level;
681
+		if (!empty(self::$config->system->trainer_blacklist)) {
682
+			$req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
683
+		}
684
+		$result = $this->mysqli->query($req);
685
+		$data = $result->fetch_object();
686
+
687
+		return $data;
688
+	}
689
+
690
+	private function getTrainerActivePokemon($trainer_name)
691
+	{
692
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
693 693
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
694 694
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
695 695
 				filtered_gymmember.gym_id,
@@ -700,18 +700,18 @@  discard block
 block discarded – undo
700 700
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
701 701
 				WHERE gympokemon.trainer_name='".$trainer_name."'
702 702
 				ORDER BY gympokemon.cp DESC";
703
-        $result = $this->mysqli->query($req);
704
-        $pokemons = array();
705
-        while ($data = $result->fetch_object()) {
706
-            $pokemons[] = $data;
707
-        }
708
-
709
-        return $pokemons;
710
-    }
711
-
712
-    private function getTrainerInactivePokemon($trainer_name)
713
-    {
714
-        $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
703
+		$result = $this->mysqli->query($req);
704
+		$pokemons = array();
705
+		while ($data = $result->fetch_object()) {
706
+			$pokemons[] = $data;
707
+		}
708
+
709
+		return $pokemons;
710
+	}
711
+
712
+	private function getTrainerInactivePokemon($trainer_name)
713
+	{
714
+		$req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp,
715 715
 				DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned,
716 716
 				gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack,
717 717
 				null AS gym_id,
@@ -722,66 +722,66 @@  discard block
 block discarded – undo
722 722
 				ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid
723 723
 				WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."'
724 724
 				ORDER BY gympokemon.cp DESC";
725
-        $result = $this->mysqli->query($req);
726
-        $pokemons = array();
727
-        while ($data = $result->fetch_object()) {
728
-            $pokemons[] = $data;
729
-        }
730
-
731
-        return $pokemons;
732
-    }
733
-
734
-    /////////
735
-    // Cron
736
-    /////////
737
-
738
-    public function getPokemonCountsActive()
739
-    {
740
-        $req = 'SELECT pokemon_id, COUNT(*) as total
725
+		$result = $this->mysqli->query($req);
726
+		$pokemons = array();
727
+		while ($data = $result->fetch_object()) {
728
+			$pokemons[] = $data;
729
+		}
730
+
731
+		return $pokemons;
732
+	}
733
+
734
+	/////////
735
+	// Cron
736
+	/////////
737
+
738
+	public function getPokemonCountsActive()
739
+	{
740
+		$req = 'SELECT pokemon_id, COUNT(*) as total
741 741
 				FROM pokemon
742 742
 				WHERE disappear_time >= UTC_TIMESTAMP()
743 743
 				GROUP BY pokemon_id';
744
-        $result = $this->mysqli->query($req);
745
-        $counts = array();
746
-        while ($data = $result->fetch_object()) {
747
-            $counts[$data->pokemon_id] = $data->total;
748
-        }
749
-
750
-        return $counts;
751
-    }
752
-
753
-    public function getPokemonCountsLastDay()
754
-    {
755
-        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
744
+		$result = $this->mysqli->query($req);
745
+		$counts = array();
746
+		while ($data = $result->fetch_object()) {
747
+			$counts[$data->pokemon_id] = $data->total;
748
+		}
749
+
750
+		return $counts;
751
+	}
752
+
753
+	public function getPokemonCountsLastDay()
754
+	{
755
+		$req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
756 756
 				FROM pokemon
757 757
 				WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY
758 758
 				GROUP BY pokemon_id
759 759
 				ORDER BY pokemon_id ASC';
760
-        $result = $this->mysqli->query($req);
761
-        $counts = array();
762
-        while ($data = $result->fetch_object()) {
763
-            $counts[$data->pokemon_id] = $data->spawns_last_day;
764
-        }
765
-
766
-        return $counts;
767
-    }
768
-
769
-    public function getCaptchaCount()
770
-    {
771
-        $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
772
-        $result = $this->mysqli->query($req);
773
-        $data = $result->fetch_object();
774
-
775
-        return $data;
776
-    }
777
-
778
-    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
779
-    {
780
-        $pokemon_exclude_sql = '';
781
-        if (!empty(self::$config->system->nest_exclude_pokemon)) {
782
-            $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
783
-        }
784
-        $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
760
+		$result = $this->mysqli->query($req);
761
+		$counts = array();
762
+		while ($data = $result->fetch_object()) {
763
+			$counts[$data->pokemon_id] = $data->spawns_last_day;
764
+		}
765
+
766
+		return $counts;
767
+	}
768
+
769
+	public function getCaptchaCount()
770
+	{
771
+		$req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker';
772
+		$result = $this->mysqli->query($req);
773
+		$data = $result->fetch_object();
774
+
775
+		return $data;
776
+	}
777
+
778
+	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
779
+	{
780
+		$pokemon_exclude_sql = '';
781
+		if (!empty(self::$config->system->nest_exclude_pokemon)) {
782
+			$pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
783
+		}
784
+		$req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon,
785 785
 				MAX(UNIX_TIMESTAMP(disappear_time)) as latest_seen
786 786
 				FROM pokemon
787 787
 				WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL '.$time.' HOUR)
@@ -790,23 +790,23 @@  discard block
 block discarded – undo
790 790
 				GROUP BY spawnpoint_id, pokemon_id 
791 791
 				HAVING COUNT(pokemon_id) >= '.($time / 4).'
792 792
 				ORDER BY pokemon_id';
793
-        $result = $this->mysqli->query($req);
794
-        $nests = array();
795
-        while ($data = $result->fetch_object()) {
796
-            $nests[] = $data;
797
-        }
798
-
799
-        return $nests;
800
-    }
801
-
802
-    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
803
-    {
804
-        $req = 'SELECT COUNT(*) as total 
793
+		$result = $this->mysqli->query($req);
794
+		$nests = array();
795
+		while ($data = $result->fetch_object()) {
796
+			$nests[] = $data;
797
+		}
798
+
799
+		return $nests;
800
+	}
801
+
802
+	public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
803
+	{
804
+		$req = 'SELECT COUNT(*) as total 
805 805
 				FROM spawnpoint
806 806
 				WHERE latitude >= '.$minLatitude.' AND latitude < '.$maxLatitude.' AND longitude >= '.$minLongitude.' AND longitude < '.$maxLongitude;
807
-        $result = $this->mysqli->query($req);
808
-        $data = $result->fetch_object();
807
+		$result = $this->mysqli->query($req);
808
+		$data = $result->fetch_object();
809 809
 
810
-        return $data;
811
-    }
810
+		return $data;
811
+	}
812 812
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerPostgresqlMonocleAlternate.php 1 patch
Indentation   +648 added lines, -648 removed lines patch added patch discarded remove patch
@@ -2,602 +2,602 @@  discard block
 block discarded – undo
2 2
 
3 3
 class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql
4 4
 {
5
-    public function __construct()
6
-    {
7
-        parent::__construct();
8
-    }
9
-
10
-    public function __destruct()
11
-    {
12
-        parent::__destruct();
13
-    }
14
-
15
-    ///////////
16
-    // Tester
17
-    ///////////
18
-
19
-    public function testTotalPokemon()
20
-    {
21
-        $req = 'SELECT COUNT(*) as total FROM sightings';
22
-        $result = pg_query($this->db, $req);
23
-        if (false === $result) {
24
-            return 1;
25
-        } else {
26
-            $data = pg_fetch_object($result);
27
-            $total = $data->total;
28
-
29
-            if (0 == $total) {
30
-                return 2;
31
-            }
32
-        }
33
-
34
-        return 0;
35
-    }
36
-
37
-    public function testTotalGyms()
38
-    {
39
-        $req = 'SELECT COUNT(*) as total FROM forts';
40
-        $result = pg_query($this->db, $req);
41
-        if (false === $result) {
42
-            return 1;
43
-        } else {
44
-            $data = pg_fetch_object($result);
45
-            $total = $data->total;
46
-
47
-            if (0 == $total) {
48
-                return 2;
49
-            }
50
-        }
51
-
52
-        return 0;
53
-    }
54
-
55
-    public function testTotalPokestops()
56
-    {
57
-        $req = 'SELECT COUNT(*) as total FROM pokestops';
58
-        $result = pg_query($this->db, $req);
59
-        if (false === $result) {
60
-            return 1;
61
-        } else {
62
-            $data = pg_fetch_object($result);
63
-            $total = $data->total;
64
-
65
-            if (0 == $total) {
66
-                return 2;
67
-            }
68
-        }
69
-
70
-        return 0;
71
-    }
72
-
73
-    /////////////
74
-    // Homepage
75
-    /////////////
76
-
77
-    public function getTotalPokemon()
78
-    {
79
-        $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())';
80
-        $result = pg_query($this->db, $req);
81
-        $data = pg_fetch_object($result);
82
-
83
-        return $data;
84
-    }
85
-
86
-    public function getTotalLures()
87
-    {
88
-        $data = (object) array('total' => 0);
89
-
90
-        return $data;
91
-    }
92
-
93
-    public function getTotalGyms()
94
-    {
95
-        $req = 'SELECT COUNT(*) AS total FROM forts';
96
-        $result = pg_query($this->db, $req);
97
-        $data = pg_fetch_object($result);
98
-
99
-        return $data;
100
-    }
101
-
102
-    public function getTotalRaids()
103
-    {
104
-        $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())';
105
-        $result = pg_query($this->db, $req);
106
-        $data = pg_fetch_object($result);
107
-
108
-        return $data;
109
-    }
110
-
111
-    public function getTotalGymsForTeam($team_id)
112
-    {
113
-        $req = "SELECT COUNT(*) AS total
5
+	public function __construct()
6
+	{
7
+		parent::__construct();
8
+	}
9
+
10
+	public function __destruct()
11
+	{
12
+		parent::__destruct();
13
+	}
14
+
15
+	///////////
16
+	// Tester
17
+	///////////
18
+
19
+	public function testTotalPokemon()
20
+	{
21
+		$req = 'SELECT COUNT(*) as total FROM sightings';
22
+		$result = pg_query($this->db, $req);
23
+		if (false === $result) {
24
+			return 1;
25
+		} else {
26
+			$data = pg_fetch_object($result);
27
+			$total = $data->total;
28
+
29
+			if (0 == $total) {
30
+				return 2;
31
+			}
32
+		}
33
+
34
+		return 0;
35
+	}
36
+
37
+	public function testTotalGyms()
38
+	{
39
+		$req = 'SELECT COUNT(*) as total FROM forts';
40
+		$result = pg_query($this->db, $req);
41
+		if (false === $result) {
42
+			return 1;
43
+		} else {
44
+			$data = pg_fetch_object($result);
45
+			$total = $data->total;
46
+
47
+			if (0 == $total) {
48
+				return 2;
49
+			}
50
+		}
51
+
52
+		return 0;
53
+	}
54
+
55
+	public function testTotalPokestops()
56
+	{
57
+		$req = 'SELECT COUNT(*) as total FROM pokestops';
58
+		$result = pg_query($this->db, $req);
59
+		if (false === $result) {
60
+			return 1;
61
+		} else {
62
+			$data = pg_fetch_object($result);
63
+			$total = $data->total;
64
+
65
+			if (0 == $total) {
66
+				return 2;
67
+			}
68
+		}
69
+
70
+		return 0;
71
+	}
72
+
73
+	/////////////
74
+	// Homepage
75
+	/////////////
76
+
77
+	public function getTotalPokemon()
78
+	{
79
+		$req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())';
80
+		$result = pg_query($this->db, $req);
81
+		$data = pg_fetch_object($result);
82
+
83
+		return $data;
84
+	}
85
+
86
+	public function getTotalLures()
87
+	{
88
+		$data = (object) array('total' => 0);
89
+
90
+		return $data;
91
+	}
92
+
93
+	public function getTotalGyms()
94
+	{
95
+		$req = 'SELECT COUNT(*) AS total FROM forts';
96
+		$result = pg_query($this->db, $req);
97
+		$data = pg_fetch_object($result);
98
+
99
+		return $data;
100
+	}
101
+
102
+	public function getTotalRaids()
103
+	{
104
+		$req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())';
105
+		$result = pg_query($this->db, $req);
106
+		$data = pg_fetch_object($result);
107
+
108
+		return $data;
109
+	}
110
+
111
+	public function getTotalGymsForTeam($team_id)
112
+	{
113
+		$req = "SELECT COUNT(*) AS total
114 114
 					FROM forts f
115 115
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
116 116
 					WHERE team = '$team_id'";
117
-        $result = pg_query($this->db, $req);
118
-        $data = pg_fetch_object($result);
117
+		$result = pg_query($this->db, $req);
118
+		$data = pg_fetch_object($result);
119 119
 
120
-        return $data;
121
-    }
120
+		return $data;
121
+	}
122 122
 
123
-    public function getRecentAll()
124
-    {
125
-        $req = 'SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
123
+	public function getRecentAll()
124
+	{
125
+		$req = 'SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
126 126
               lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
127 127
               FROM sightings
128 128
               ORDER BY updated DESC
129 129
               LIMIT 12 OFFSET 0';
130
-        $result = pg_query($this->db, $req);
131
-        $data = array();
132
-        if ($result->num_rows > 0) {
133
-            while ($row = pg_fetch_object($result)) {
134
-                $data[] = $row;
135
-            }
136
-        }
137
-
138
-        return $data;
139
-    }
140
-
141
-    public function getRecentMythic($mythic_pokemon)
142
-    {
143
-        $req = 'SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
130
+		$result = pg_query($this->db, $req);
131
+		$data = array();
132
+		if ($result->num_rows > 0) {
133
+			while ($row = pg_fetch_object($result)) {
134
+				$data[] = $row;
135
+			}
136
+		}
137
+
138
+		return $data;
139
+	}
140
+
141
+	public function getRecentMythic($mythic_pokemon)
142
+	{
143
+		$req = 'SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
144 144
                 lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
145 145
                 FROM sightings
146 146
                 WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).')
147 147
                 ORDER BY updated DESC
148 148
                 LIMIT 12 OFFSET 0';
149
-        $result = pg_query($this->db, $req);
150
-        $data = array();
151
-        if ($result->num_rows > 0) {
152
-            while ($row = pg_fetch_object($result)) {
153
-                $data[] = $row;
154
-            }
155
-        }
156
-
157
-        return $data;
158
-    }
159
-
160
-    ///////////////////
161
-    // Single Pokemon
162
-    ///////////////////
163
-
164
-    public function getGymsProtectedByPokemon($pokemon_id)
165
-    {
166
-        $req = "SELECT COUNT(f.id) AS total
149
+		$result = pg_query($this->db, $req);
150
+		$data = array();
151
+		if ($result->num_rows > 0) {
152
+			while ($row = pg_fetch_object($result)) {
153
+				$data[] = $row;
154
+			}
155
+		}
156
+
157
+		return $data;
158
+	}
159
+
160
+	///////////////////
161
+	// Single Pokemon
162
+	///////////////////
163
+
164
+	public function getGymsProtectedByPokemon($pokemon_id)
165
+	{
166
+		$req = "SELECT COUNT(f.id) AS total
167 167
 					FROM forts f
168 168
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
169 169
 					WHERE guard_pokemon_id = '".$pokemon_id."'";
170
-        $result = pg_query($this->db, $req);
171
-        $data = pg_fetch_object($result);
170
+		$result = pg_query($this->db, $req);
171
+		$data = pg_fetch_object($result);
172 172
 
173
-        return $data;
174
-    }
173
+		return $data;
174
+	}
175 175
 
176
-    public function getPokemonLastSeen($pokemon_id)
177
-    {
178
-        $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
176
+	public function getPokemonLastSeen($pokemon_id)
177
+	{
178
+		$req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
179 179
                 FROM sightings
180 180
                 WHERE pokemon_id = '".$pokemon_id."'
181 181
                 ORDER BY expire_timestamp DESC
182 182
                 LIMIT 1 OFFSET 0";
183
-        $result = pg_query($this->db, $req);
184
-        $data = pg_fetch_object($result);
183
+		$result = pg_query($this->db, $req);
184
+		$data = pg_fetch_object($result);
185 185
 
186
-        return $data;
187
-    }
186
+		return $data;
187
+	}
188 188
 
189
-    public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
-    {
191
-        $req = "SELECT expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS distime, pokemon_id as pokemon_id, TO_TIMESTAMP(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
189
+	public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
+	{
191
+		$req = "SELECT expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS distime, pokemon_id as pokemon_id, TO_TIMESTAMP(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
192 192
                 cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina,
193 193
                 ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form
194 194
                 FROM sightings
195 195
 	            WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0'
196 196
 	            ORDER BY $top_order_by $top_direction, expire_timestamp DESC
197 197
 	            LIMIT 50 OFFSET 0";
198
-        $result = pg_query($this->db, $req);
199
-        $top = array();
200
-        while ($data = pg_fetch_object($result)) {
201
-            $top[] = $data;
202
-        }
203
-
204
-        return $top;
205
-    }
206
-
207
-    public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
208
-    {
209
-        $trainer_blacklist = '';
210
-        if (!empty(self::$config->system->trainer_blacklist)) {
211
-            $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
212
-        }
213
-
214
-        $req = "SELECT owner_name as trainer_name, ROUND((100.0*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS \"IV\", move_1, move_2, cp as cp,
198
+		$result = pg_query($this->db, $req);
199
+		$top = array();
200
+		while ($data = pg_fetch_object($result)) {
201
+			$top[] = $data;
202
+		}
203
+
204
+		return $top;
205
+	}
206
+
207
+	public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
208
+	{
209
+		$trainer_blacklist = '';
210
+		if (!empty(self::$config->system->trainer_blacklist)) {
211
+			$trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
212
+		}
213
+
214
+		$req = "SELECT owner_name as trainer_name, ROUND((100.0*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS \"IV\", move_1, move_2, cp as cp,
215 215
                 TO_TIMESTAMP(last_modified) AS lasttime, last_modified as last_seen
216 216
                 FROM gym_defenders
217 217
 				WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
218 218
 				ORDER BY $best_order_by $best_direction, owner_name ASC
219 219
 				LIMIT 50 OFFSET 0";
220 220
 
221
-        $result = pg_query($this->db, $req);
222
-        $toptrainer = array();
223
-        while ($data = pg_fetch_object($result)) {
224
-            $toptrainer[] = $data;
225
-        }
226
-
227
-        return $toptrainer;
228
-    }
229
-
230
-    public function getPokemonHeatmap($pokemon_id, $start, $end)
231
-    {
232
-        $where = ' WHERE pokemon_id = '.$pokemon_id.' '
233
-            ."AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
234
-        $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000';
235
-        $result = pg_query($this->db, $req);
236
-        $points = array();
237
-        while ($data = pg_fetch_object($result)) {
238
-            $points[] = $data;
239
-        }
240
-
241
-        return $points;
242
-    }
243
-
244
-    public function getPokemonGraph($pokemon_id)
245
-    {
246
-        $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour
221
+		$result = pg_query($this->db, $req);
222
+		$toptrainer = array();
223
+		while ($data = pg_fetch_object($result)) {
224
+			$toptrainer[] = $data;
225
+		}
226
+
227
+		return $toptrainer;
228
+	}
229
+
230
+	public function getPokemonHeatmap($pokemon_id, $start, $end)
231
+	{
232
+		$where = ' WHERE pokemon_id = '.$pokemon_id.' '
233
+			."AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
234
+		$req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000';
235
+		$result = pg_query($this->db, $req);
236
+		$points = array();
237
+		while ($data = pg_fetch_object($result)) {
238
+			$points[] = $data;
239
+		}
240
+
241
+		return $points;
242
+	}
243
+
244
+	public function getPokemonGraph($pokemon_id)
245
+	{
246
+		$req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour
247 247
 					FROM (SELECT TO_TIMESTAMP(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
248 248
 				GROUP BY disappear_hour
249 249
 				ORDER BY disappear_hour";
250
-        $result = pg_query($this->db, $req);
251
-        $array = array_fill(0, 24, 0);
252
-        while ($result && $data = pg_fetch_object($result)) {
253
-            $array[$data->disappear_hour] = $data->total;
254
-        }
255
-        // shift array because AM/PM starts at 1AM not 0:00
256
-        $array[] = $array[0];
257
-        array_shift($array);
258
-
259
-        return $array;
260
-    }
261
-
262
-    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
263
-    {
264
-        $inmap_pkms_filter = '';
265
-        $where = ' WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = '.$pokemon_id;
266
-
267
-        $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where;
268
-        $resultTestIv = pg_query($this->db, $reqTestIv);
269
-        $testIv = pg_fetch_object($resultTestIv);
270
-        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
271
-            foreach ($inmap_pokemons as $inmap) {
272
-                $inmap_pkms_filter .= "'".$inmap."',";
273
-            }
274
-            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
275
-            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
276
-        }
277
-        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
278
-            $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') ';
279
-        }
280
-        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
281
-            $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') ';
282
-        }
283
-        $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude,
250
+		$result = pg_query($this->db, $req);
251
+		$array = array_fill(0, 24, 0);
252
+		while ($result && $data = pg_fetch_object($result)) {
253
+			$array[$data->disappear_hour] = $data->total;
254
+		}
255
+		// shift array because AM/PM starts at 1AM not 0:00
256
+		$array[] = $array[0];
257
+		array_shift($array);
258
+
259
+		return $array;
260
+	}
261
+
262
+	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
263
+	{
264
+		$inmap_pkms_filter = '';
265
+		$where = ' WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = '.$pokemon_id;
266
+
267
+		$reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where;
268
+		$resultTestIv = pg_query($this->db, $reqTestIv);
269
+		$testIv = pg_fetch_object($resultTestIv);
270
+		if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
271
+			foreach ($inmap_pokemons as $inmap) {
272
+				$inmap_pkms_filter .= "'".$inmap."',";
273
+			}
274
+			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
275
+			$where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
276
+		}
277
+		if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
278
+			$where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') ';
279
+		}
280
+		if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
281
+			$where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') ';
282
+		}
283
+		$req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude,
284 284
     					TO_TIMESTAMP(expire_timestamp) AS disappear_time,
285 285
     					TO_TIMESTAMP(expire_timestamp) AS disappear_time_real,
286 286
     					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
287 287
    						move_1, move_2
288 288
 					FROM sightings '.$where.'
289 289
 					LIMIT 5000';
290
-        $result = pg_query($this->db, $req);
291
-        $spawns = array();
292
-        while ($data = pg_fetch_object($result)) {
293
-            $spawns[] = $data;
294
-        }
295
-
296
-        return $spawns;
297
-    }
298
-
299
-    public function getPokemonSliderMinMax()
300
-    {
301
-        $req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings';
302
-        $result = pg_query($this->db, $req);
303
-        $data = pg_fetch_object($result);
304
-
305
-        return $data;
306
-    }
307
-
308
-    public function getMapsCoords()
309
-    {
310
-        $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
311
-        $result = pg_query($this->db, $req);
312
-        $data = pg_fetch_object($result);
313
-
314
-        return $data;
315
-    }
316
-
317
-    public function getPokemonCount($pokemon_id)
318
-    {
319
-        $req = 'SELECT count, last_seen, latitude, longitude
290
+		$result = pg_query($this->db, $req);
291
+		$spawns = array();
292
+		while ($data = pg_fetch_object($result)) {
293
+			$spawns[] = $data;
294
+		}
295
+
296
+		return $spawns;
297
+	}
298
+
299
+	public function getPokemonSliderMinMax()
300
+	{
301
+		$req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings';
302
+		$result = pg_query($this->db, $req);
303
+		$data = pg_fetch_object($result);
304
+
305
+		return $data;
306
+	}
307
+
308
+	public function getMapsCoords()
309
+	{
310
+		$req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
311
+		$result = pg_query($this->db, $req);
312
+		$data = pg_fetch_object($result);
313
+
314
+		return $data;
315
+	}
316
+
317
+	public function getPokemonCount($pokemon_id)
318
+	{
319
+		$req = 'SELECT count, last_seen, latitude, longitude
320 320
 					FROM pokemon_stats
321 321
 					WHERE pid = '.$pokemon_id;
322
-        $result = pg_query($this->db, $req);
323
-        $data = pg_fetch_object($result);
322
+		$result = pg_query($this->db, $req);
323
+		$data = pg_fetch_object($result);
324 324
 
325
-        return $data;
326
-    }
325
+		return $data;
326
+	}
327 327
 
328
-    public function getRaidCount($pokemon_id)
329
-    {
330
-        $req = 'SELECT count, last_seen, latitude, longitude
328
+	public function getRaidCount($pokemon_id)
329
+	{
330
+		$req = 'SELECT count, last_seen, latitude, longitude
331 331
 					FROM raid_stats
332 332
 					WHERE pid = '.$pokemon_id;
333
-        $result = pg_query($this->db, $req);
334
-        $data = pg_fetch_object($result);
335
-
336
-        return $data;
337
-    }
338
-
339
-    ///////////////
340
-    // Pokestops
341
-    //////////////
342
-
343
-    public function getTotalPokestops()
344
-    {
345
-        $req = 'SELECT COUNT(*) as total FROM pokestops';
346
-        $result = pg_query($this->db, $req);
347
-        $data = pg_fetch_object($result);
348
-
349
-        return $data;
350
-    }
351
-
352
-    public function getAllPokestops()
353
-    {
354
-        $req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, EXTRACT(EPOCH FROM NOW()) AS now, null AS lure_expiration_real FROM pokestops';
355
-        $result = pg_query($this->db, $req);
356
-        $pokestops = array();
357
-        while ($data = pg_fetch_object($result)) {
358
-            $pokestops[] = $data;
359
-        }
360
-
361
-        return $pokestops;
362
-    }
363
-
364
-    /////////
365
-    // Gyms
366
-    /////////
367
-
368
-    public function getTeamGuardians($team_id)
369
-    {
370
-        $req = "SELECT COUNT(*) AS total, guard_pokemon_id
333
+		$result = pg_query($this->db, $req);
334
+		$data = pg_fetch_object($result);
335
+
336
+		return $data;
337
+	}
338
+
339
+	///////////////
340
+	// Pokestops
341
+	//////////////
342
+
343
+	public function getTotalPokestops()
344
+	{
345
+		$req = 'SELECT COUNT(*) as total FROM pokestops';
346
+		$result = pg_query($this->db, $req);
347
+		$data = pg_fetch_object($result);
348
+
349
+		return $data;
350
+	}
351
+
352
+	public function getAllPokestops()
353
+	{
354
+		$req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, EXTRACT(EPOCH FROM NOW()) AS now, null AS lure_expiration_real FROM pokestops';
355
+		$result = pg_query($this->db, $req);
356
+		$pokestops = array();
357
+		while ($data = pg_fetch_object($result)) {
358
+			$pokestops[] = $data;
359
+		}
360
+
361
+		return $pokestops;
362
+	}
363
+
364
+	/////////
365
+	// Gyms
366
+	/////////
367
+
368
+	public function getTeamGuardians($team_id)
369
+	{
370
+		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
371 371
 					FROM forts f
372 372
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
373 373
 					WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 3 OFFSET 0";
374
-        $result = pg_query($this->db, $req);
374
+		$result = pg_query($this->db, $req);
375 375
 
376
-        $datas = array();
377
-        while ($data = pg_fetch_object($result)) {
378
-            $datas[] = $data;
379
-        }
376
+		$datas = array();
377
+		while ($data = pg_fetch_object($result)) {
378
+			$datas[] = $data;
379
+		}
380 380
 
381
-        return $datas;
382
-    }
381
+		return $datas;
382
+	}
383 383
 
384
-    public function getOwnedAndPoints($team_id)
385
-    {
386
-        $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
384
+	public function getOwnedAndPoints($team_id)
385
+	{
386
+		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points
387 387
         			FROM forts f
388 388
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
389 389
         			WHERE fs.team = '".$team_id."'";
390
-        $result = pg_query($this->db, $req);
391
-        $data = pg_fetch_object($result);
390
+		$result = pg_query($this->db, $req);
391
+		$data = pg_fetch_object($result);
392 392
 
393
-        return $data;
394
-    }
393
+		return $data;
394
+	}
395 395
 
396
-    public function getAllGyms()
397
-    {
398
-        $req = 'SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level
396
+	public function getAllGyms()
397
+	{
398
+		$req = 'SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level
399 399
 					FROM forts f
400 400
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))';
401
-        $result = pg_query($this->db, $req);
402
-        $gyms = array();
403
-        while ($data = pg_fetch_object($result)) {
404
-            $gyms[] = $data;
405
-        }
406
-
407
-        return $gyms;
408
-    }
409
-
410
-    public function getGymData($gym_id)
411
-    {
412
-        $req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, TO_TIMESTAMP(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp
401
+		$result = pg_query($this->db, $req);
402
+		$gyms = array();
403
+		while ($data = pg_fetch_object($result)) {
404
+			$gyms[] = $data;
405
+		}
406
+
407
+		return $gyms;
408
+	}
409
+
410
+	public function getGymData($gym_id)
411
+	{
412
+		$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, TO_TIMESTAMP(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp
413 413
 			FROM forts f
414 414
 			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
415 415
 			WHERE f.id ='".$gym_id."'
416 416
 			GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp";
417
-        $result = pg_query($this->db, $req);
418
-        $data = pg_fetch_object($result);
417
+		$result = pg_query($this->db, $req);
418
+		$data = pg_fetch_object($result);
419 419
 
420
-        return $data;
421
-    }
420
+		return $data;
421
+	}
422 422
 
423
-    public function getGymDefenders($gym_id)
424
-    {
425
-        $req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
423
+	public function getGymDefenders($gym_id)
424
+	{
425
+		$req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
426 426
 			FROM gym_defenders
427 427
 			WHERE fort_id='".$gym_id."'
428 428
 			ORDER BY deployment_time";
429
-        $result = pg_query($this->db, $req);
430
-        $defenders = array();
431
-        while ($data = pg_fetch_object($result)) {
432
-            $defenders[] = $data;
433
-        }
434
-
435
-        return $defenders;
436
-    }
437
-
438
-    ////////////////
439
-    // Gym History
440
-    ////////////////
441
-
442
-    public function getGymHistories($gym_name, $team, $page, $ranking)
443
-    {
444
-        $where = '';
445
-        if (isset($gym_name) && '' != $gym_name) {
446
-            $where = " WHERE name LIKE '%".$gym_name."%'";
447
-        }
448
-        if (isset($team) && '' != $team) {
449
-            $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team;
450
-        }
451
-        switch ($ranking) {
452
-            case 1:
453
-                $order = ' ORDER BY name, last_modified DESC';
454
-                break;
455
-            case 2:
456
-                $order = ' ORDER BY total_cp DESC, last_modified DESC';
457
-                break;
458
-            default:
459
-                $order = ' ORDER BY last_modified DESC, name';
460
-        }
461
-
462
-        $limit = ' LIMIT 10 OFFSET '.($page * 10);
463
-
464
-        $req = 'SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, TO_TIMESTAMP(last_modified) AS last_modified
429
+		$result = pg_query($this->db, $req);
430
+		$defenders = array();
431
+		while ($data = pg_fetch_object($result)) {
432
+			$defenders[] = $data;
433
+		}
434
+
435
+		return $defenders;
436
+	}
437
+
438
+	////////////////
439
+	// Gym History
440
+	////////////////
441
+
442
+	public function getGymHistories($gym_name, $team, $page, $ranking)
443
+	{
444
+		$where = '';
445
+		if (isset($gym_name) && '' != $gym_name) {
446
+			$where = " WHERE name LIKE '%".$gym_name."%'";
447
+		}
448
+		if (isset($team) && '' != $team) {
449
+			$where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team;
450
+		}
451
+		switch ($ranking) {
452
+			case 1:
453
+				$order = ' ORDER BY name, last_modified DESC';
454
+				break;
455
+			case 2:
456
+				$order = ' ORDER BY total_cp DESC, last_modified DESC';
457
+				break;
458
+			default:
459
+				$order = ' ORDER BY last_modified DESC, name';
460
+		}
461
+
462
+		$limit = ' LIMIT 10 OFFSET '.($page * 10);
463
+
464
+		$req = 'SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, TO_TIMESTAMP(last_modified) AS last_modified
465 465
 			FROM forts f
466 466
 			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
467 467
 			'.$where.$order.$limit;
468 468
 
469
-        $result = pg_query($this->db, $req);
470
-        $gym_history = array();
471
-        while ($data = pg_fetch_object($result)) {
472
-            $gym_history[] = $data;
473
-        }
469
+		$result = pg_query($this->db, $req);
470
+		$gym_history = array();
471
+		while ($data = pg_fetch_object($result)) {
472
+			$gym_history[] = $data;
473
+		}
474 474
 
475
-        return $gym_history;
476
-    }
475
+		return $gym_history;
476
+	}
477 477
 
478
-    public function getGymHistoriesPokemon($gym_id)
479
-    {
480
-        $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
478
+	public function getGymHistoriesPokemon($gym_id)
479
+	{
480
+		$req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
481 481
 					FROM gym_defenders
482 482
 					WHERE fort_id = '".$gym_id."'
483 483
 					ORDER BY deployment_time";
484
-        $result = pg_query($this->db, $req);
485
-        $pokemons = array();
486
-        while ($data = pg_fetch_object($result)) {
487
-            $pokemons[] = $data;
488
-        }
489
-
490
-        return $pokemons;
491
-    }
492
-
493
-    public function getHistoryForGym($page, $gym_id)
494
-    {
495
-        if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
496
-            $pageSize = 25;
497
-        } else {
498
-            $pageSize = 10;
499
-        }
500
-        $req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, TO_TIMESTAMP(fs.last_modified) as last_modified, last_modified as last_modified_real
484
+		$result = pg_query($this->db, $req);
485
+		$pokemons = array();
486
+		while ($data = pg_fetch_object($result)) {
487
+			$pokemons[] = $data;
488
+		}
489
+
490
+		return $pokemons;
491
+	}
492
+
493
+	public function getHistoryForGym($page, $gym_id)
494
+	{
495
+		if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
496
+			$pageSize = 25;
497
+		} else {
498
+			$pageSize = 10;
499
+		}
500
+		$req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, TO_TIMESTAMP(fs.last_modified) as last_modified, last_modified as last_modified_real
501 501
 					FROM fort_sightings fs
502 502
 					LEFT JOIN forts f ON f.id = fs.fort_id
503 503
 					WHERE f.id = '".$gym_id."'
504 504
 					ORDER BY fs.last_modified DESC
505 505
 					LIMIT ".($pageSize + 1).' OFFSET '.($page * $pageSize);
506
-        $result = pg_query($this->db, $req);
507
-        $history = array();
508
-        $count = 0;
509
-        while ($data = pg_fetch_object($result)) {
510
-            ++$count;
511
-            if (0 == $data->total_cp) {
512
-                $data->pokemon = array();
513
-                $data->pokemon_count = 0;
514
-                $data->pokemon_uids = '';
515
-            } else {
516
-                $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
517
-                $data->pokemon_count = count($data->pokemon);
518
-                $data->pokemon_uids = implode(',', array_keys($data->pokemon));
519
-            }
520
-            if (0 === $data->total_cp || 0 !== $data->pokemon_count) {
521
-                $history[] = $data;
522
-            }
523
-        }
524
-        if ($count !== ($pageSize + 1)) {
525
-            $last_page = true;
526
-        } else {
527
-            $last_page = false;
528
-        }
529
-
530
-        return array('last_page' => $last_page, 'data' => $history);
531
-    }
532
-
533
-    private function getHistoryForGymPokemon($gym_id, $last_modified)
534
-    {
535
-        $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
506
+		$result = pg_query($this->db, $req);
507
+		$history = array();
508
+		$count = 0;
509
+		while ($data = pg_fetch_object($result)) {
510
+			++$count;
511
+			if (0 == $data->total_cp) {
512
+				$data->pokemon = array();
513
+				$data->pokemon_count = 0;
514
+				$data->pokemon_uids = '';
515
+			} else {
516
+				$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
517
+				$data->pokemon_count = count($data->pokemon);
518
+				$data->pokemon_uids = implode(',', array_keys($data->pokemon));
519
+			}
520
+			if (0 === $data->total_cp || 0 !== $data->pokemon_count) {
521
+				$history[] = $data;
522
+			}
523
+		}
524
+		if ($count !== ($pageSize + 1)) {
525
+			$last_page = true;
526
+		} else {
527
+			$last_page = false;
528
+		}
529
+
530
+		return array('last_page' => $last_page, 'data' => $history);
531
+	}
532
+
533
+	private function getHistoryForGymPokemon($gym_id, $last_modified)
534
+	{
535
+		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
536 536
 					FROM gym_history_defenders ghd
537 537
 					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
538 538
 					WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."'
539 539
 					ORDER BY gd.deployment_time";
540
-        $result = pg_query($this->db, $req);
541
-        $pokemons = array();
542
-        while ($data = pg_fetch_object($result)) {
543
-            $pokemons[$data->defender_id] = $data;
544
-        }
545
-
546
-        return $pokemons;
547
-    }
548
-
549
-    ///////////
550
-    // Raids
551
-    ///////////
552
-
553
-    public function getAllRaids($page)
554
-    {
555
-        $limit = ' LIMIT 10 OFFSET '.($page * 10);
556
-        $req = 'SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude
540
+		$result = pg_query($this->db, $req);
541
+		$pokemons = array();
542
+		while ($data = pg_fetch_object($result)) {
543
+			$pokemons[$data->defender_id] = $data;
544
+		}
545
+
546
+		return $pokemons;
547
+	}
548
+
549
+	///////////
550
+	// Raids
551
+	///////////
552
+
553
+	public function getAllRaids($page)
554
+	{
555
+		$limit = ' LIMIT 10 OFFSET '.($page * 10);
556
+		$req = 'SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, TO_TIMESTAMP(r.time_spawn) AS spawn, TO_TIMESTAMP(r.time_battle) AS start, TO_TIMESTAMP(r.time_end) AS end, TO_TIMESTAMP(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude
557 557
 					FROM forts f
558 558
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
559 559
 				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
560 560
 					WHERE r.time_end > EXTRACT(EPOCH FROM NOW())
561 561
 					ORDER BY r.level DESC, r.time_battle'.$limit;
562
-        $result = pg_query($this->db, $req);
563
-        $raids = array();
564
-        while ($data = pg_fetch_object($result)) {
565
-            $raids[] = $data;
566
-        }
567
-
568
-        return $raids;
569
-    }
570
-
571
-    //////////////
572
-    // Trainers
573
-    //////////////
574
-
575
-    public function getTrainers($trainer_name, $team, $page, $rankingNumber)
576
-    {
577
-        $ranking = $this->getTrainerLevelRanking();
578
-        $where = '';
579
-        if (!empty(self::$config->system->trainer_blacklist)) {
580
-            $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
581
-        }
582
-        if ('' != $trainer_name) {
583
-            $where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
584
-        }
585
-        if (0 != $team) {
586
-            $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
587
-        }
588
-        switch ($rankingNumber) {
589
-            case 1:
590
-                $order = ' ORDER BY active DESC, level DESC';
591
-                break;
592
-            case 2:
593
-                $order = ' ORDER BY maxCp DESC, level DESC';
594
-                break;
595
-            default:
596
-                $order = ' ORDER BY level DESC, active DESC';
597
-        }
598
-        $order .= ', last_seen DESC, name ';
599
-        $limit = ' LIMIT 10 OFFSET '.($page * 10);
600
-        $req = 'SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, TO_TIMESTAMP(MAX(last_modified)) as last_seen
562
+		$result = pg_query($this->db, $req);
563
+		$raids = array();
564
+		while ($data = pg_fetch_object($result)) {
565
+			$raids[] = $data;
566
+		}
567
+
568
+		return $raids;
569
+	}
570
+
571
+	//////////////
572
+	// Trainers
573
+	//////////////
574
+
575
+	public function getTrainers($trainer_name, $team, $page, $rankingNumber)
576
+	{
577
+		$ranking = $this->getTrainerLevelRanking();
578
+		$where = '';
579
+		if (!empty(self::$config->system->trainer_blacklist)) {
580
+			$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
581
+		}
582
+		if ('' != $trainer_name) {
583
+			$where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
584
+		}
585
+		if (0 != $team) {
586
+			$where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
587
+		}
588
+		switch ($rankingNumber) {
589
+			case 1:
590
+				$order = ' ORDER BY active DESC, level DESC';
591
+				break;
592
+			case 2:
593
+				$order = ' ORDER BY maxCp DESC, level DESC';
594
+				break;
595
+			default:
596
+				$order = ' ORDER BY level DESC, active DESC';
597
+		}
598
+		$order .= ', last_seen DESC, name ';
599
+		$limit = ' LIMIT 10 OFFSET '.($page * 10);
600
+		$req = 'SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, TO_TIMESTAMP(MAX(last_modified)) as last_seen
601 601
 				  	FROM gym_defenders gd
602 602
 				  	LEFT JOIN (
603 603
 				  		SELECT owner_name, COUNT(*) as active
@@ -607,149 +607,149 @@  discard block
 block discarded – undo
607 607
 				  	) active ON active.owner_name = gd.owner_name
608 608
 				  	WHERE level IS NOT NULL '.$where.'
609 609
 				  	GROUP BY gd.owner_name'.$order.$limit;
610
-        $result = pg_query($this->db, $req);
611
-        $trainers = array();
612
-        while ($data = pg_fetch_object($result)) {
613
-            $data->last_seen = date('Y-m-d', strtotime($data->last_seen));
614
-            if (is_null($data->active)) {
615
-                $data->active = 0;
616
-            }
617
-            $trainers[$data->name] = $data;
618
-
619
-            $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name));
620
-
621
-            $trainers[$data->name]->gyms = $data->active;
622
-            $trainers[$data->name]->pokemons = $pokemon;
623
-            $trainers[$data->name]->rank = $ranking[$data->level];
624
-        }
625
-
626
-        return $trainers;
627
-    }
628
-
629
-    public function getTrainerLevelRanking()
630
-    {
631
-        $exclue = '';
632
-        if (!empty(self::$config->system->trainer_blacklist)) {
633
-            $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
634
-        }
635
-        $req = 'SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL '.$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
636
-        $result = pg_query($this->db, $req);
637
-        $levelData = array();
638
-        while ($data = pg_fetch_object($result)) {
639
-            $levelData[$data->level] = $data->count;
640
-        }
641
-        for ($i = 5; $i <= 40; ++$i) {
642
-            if (!isset($levelData[$i])) {
643
-                $levelData[$i] = 0;
644
-            }
645
-        }
646
-        // sort array again
647
-        ksort($levelData);
648
-
649
-        return $levelData;
650
-    }
651
-
652
-    public function getActivePokemon($trainer_name)
653
-    {
654
-        $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, TO_TIMESTAMP(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
610
+		$result = pg_query($this->db, $req);
611
+		$trainers = array();
612
+		while ($data = pg_fetch_object($result)) {
613
+			$data->last_seen = date('Y-m-d', strtotime($data->last_seen));
614
+			if (is_null($data->active)) {
615
+				$data->active = 0;
616
+			}
617
+			$trainers[$data->name] = $data;
618
+
619
+			$pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name));
620
+
621
+			$trainers[$data->name]->gyms = $data->active;
622
+			$trainers[$data->name]->pokemons = $pokemon;
623
+			$trainers[$data->name]->rank = $ranking[$data->level];
624
+		}
625
+
626
+		return $trainers;
627
+	}
628
+
629
+	public function getTrainerLevelRanking()
630
+	{
631
+		$exclue = '';
632
+		if (!empty(self::$config->system->trainer_blacklist)) {
633
+			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
634
+		}
635
+		$req = 'SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL '.$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
636
+		$result = pg_query($this->db, $req);
637
+		$levelData = array();
638
+		while ($data = pg_fetch_object($result)) {
639
+			$levelData[$data->level] = $data->count;
640
+		}
641
+		for ($i = 5; $i <= 40; ++$i) {
642
+			if (!isset($levelData[$i])) {
643
+				$levelData[$i] = 0;
644
+			}
645
+		}
646
+		// sort array again
647
+		ksort($levelData);
648
+
649
+		return $levelData;
650
+	}
651
+
652
+	public function getActivePokemon($trainer_name)
653
+	{
654
+		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, TO_TIMESTAMP(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
655 655
 						FROM gym_defenders
656 656
 						WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL
657 657
 						ORDER BY deployment_time";
658
-        $result = pg_query($this->db, $req);
659
-        $pokemon = array();
660
-        while ($data = pg_fetch_object($result)) {
661
-            $pokemon[] = $data;
662
-        }
663
-
664
-        return $pokemon;
665
-    }
666
-
667
-    public function getInactivePokemon($trainer_name)
668
-    {
669
-        $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
658
+		$result = pg_query($this->db, $req);
659
+		$pokemon = array();
660
+		while ($data = pg_fetch_object($result)) {
661
+			$pokemon[] = $data;
662
+		}
663
+
664
+		return $pokemon;
665
+	}
666
+
667
+	public function getInactivePokemon($trainer_name)
668
+	{
669
+		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
670 670
 					FROM gym_defenders
671 671
 					WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL
672 672
 					ORDER BY last_scanned";
673
-        $result = pg_query($this->db, $req);
674
-        $pokemon = array();
675
-        while ($data = pg_fetch_object($result)) {
676
-            $pokemon[] = $data;
677
-        }
678
-
679
-        return $pokemon;
680
-    }
681
-
682
-    public function getTrainerLevelCount($team_id)
683
-    {
684
-        $exclue = '';
685
-        if (!empty(self::$config->system->trainer_blacklist)) {
686
-            $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
687
-        }
688
-        $req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
689
-        $result = pg_query($this->db, $req);
690
-        $levelData = array();
691
-        while ($data = pg_fetch_object($result)) {
692
-            $levelData[$data->level] = $data->count;
693
-        }
694
-        for ($i = 5; $i <= 40; ++$i) {
695
-            if (!isset($levelData[$i])) {
696
-                $levelData[$i] = 0;
697
-            }
698
-        }
699
-        // sort array again
700
-        ksort($levelData);
701
-
702
-        return $levelData;
703
-    }
704
-
705
-    /////////
706
-    // Cron
707
-    /////////
708
-
709
-    public function getPokemonCountsActive()
710
-    {
711
-        $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id';
712
-        $result = pg_query($this->db, $req);
713
-        $counts = array();
714
-        while ($data = pg_fetch_object($result)) {
715
-            $counts[$data->pokemon_id] = $data->total;
716
-        }
717
-
718
-        return $counts;
719
-    }
720
-
721
-    public function getPokemonCountsLastDay()
722
-    {
723
-        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
673
+		$result = pg_query($this->db, $req);
674
+		$pokemon = array();
675
+		while ($data = pg_fetch_object($result)) {
676
+			$pokemon[] = $data;
677
+		}
678
+
679
+		return $pokemon;
680
+	}
681
+
682
+	public function getTrainerLevelCount($team_id)
683
+	{
684
+		$exclue = '';
685
+		if (!empty(self::$config->system->trainer_blacklist)) {
686
+			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
687
+		}
688
+		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
689
+		$result = pg_query($this->db, $req);
690
+		$levelData = array();
691
+		while ($data = pg_fetch_object($result)) {
692
+			$levelData[$data->level] = $data->count;
693
+		}
694
+		for ($i = 5; $i <= 40; ++$i) {
695
+			if (!isset($levelData[$i])) {
696
+				$levelData[$i] = 0;
697
+			}
698
+		}
699
+		// sort array again
700
+		ksort($levelData);
701
+
702
+		return $levelData;
703
+	}
704
+
705
+	/////////
706
+	// Cron
707
+	/////////
708
+
709
+	public function getPokemonCountsActive()
710
+	{
711
+		$req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id';
712
+		$result = pg_query($this->db, $req);
713
+		$counts = array();
714
+		while ($data = pg_fetch_object($result)) {
715
+			$counts[$data->pokemon_id] = $data->total;
716
+		}
717
+
718
+		return $counts;
719
+	}
720
+
721
+	public function getPokemonCountsLastDay()
722
+	{
723
+		$req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
724 724
 					FROM sightings
725 725
 					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings)
726 726
 					GROUP BY pokemon_id
727 727
 				  	ORDER BY pokemon_id ASC';
728
-        $result = pg_query($this->db, $req);
729
-        $counts = array();
730
-        while ($data = pg_fetch_object($result)) {
731
-            $counts[$data->pokemon_id] = $data->spawns_last_day;
732
-        }
733
-
734
-        return $counts;
735
-    }
736
-
737
-    public function getCaptchaCount()
738
-    {
739
-        $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL';
740
-        $result = pg_query($this->db, $req);
741
-        $data = pg_fetch_object($result);
742
-
743
-        return $data;
744
-    }
745
-
746
-    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
747
-    {
748
-        $pokemon_exclude_sql = '';
749
-        if (!empty(self::$config->system->nest_exclude_pokemon)) {
750
-            $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
751
-        }
752
-        $req = 'SELECT p.spawn_id, p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
728
+		$result = pg_query($this->db, $req);
729
+		$counts = array();
730
+		while ($data = pg_fetch_object($result)) {
731
+			$counts[$data->pokemon_id] = $data->spawns_last_day;
732
+		}
733
+
734
+		return $counts;
735
+	}
736
+
737
+	public function getCaptchaCount()
738
+	{
739
+		$req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL';
740
+		$result = pg_query($this->db, $req);
741
+		$data = pg_fetch_object($result);
742
+
743
+		return $data;
744
+	}
745
+
746
+	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
747
+	{
748
+		$pokemon_exclude_sql = '';
749
+		if (!empty(self::$config->system->nest_exclude_pokemon)) {
750
+			$pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
751
+		}
752
+		$req = 'SELECT p.spawn_id, p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
753 753
 			          FROM sightings p
754 754
 			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
755 755
 			          WHERE p.expire_timestamp > EXTRACT(EPOCH FROM NOW()) - '.($time * 3600).'
@@ -758,23 +758,23 @@  discard block
 block discarded – undo
758 758
 			          GROUP BY p.spawn_id, p.pokemon_id
759 759
 			          HAVING COUNT(p.pokemon_id) >= '.($time / 4).'
760 760
 			          ORDER BY p.pokemon_id';
761
-        $result = pg_query($this->db, $req);
762
-        $nests = array();
763
-        while ($data = pg_fetch_object($result)) {
764
-            $nests[] = $data;
765
-        }
766
-
767
-        return $nests;
768
-    }
769
-
770
-    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
771
-    {
772
-        $req = 'SELECT COUNT(*) as total 
761
+		$result = pg_query($this->db, $req);
762
+		$nests = array();
763
+		while ($data = pg_fetch_object($result)) {
764
+			$nests[] = $data;
765
+		}
766
+
767
+		return $nests;
768
+	}
769
+
770
+	public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
771
+	{
772
+		$req = 'SELECT COUNT(*) as total 
773 773
 					FROM spawnpoints 
774 774
  					WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude;
775
-        $result = pg_query($this->db, $req);
776
-        $data = pg_fetch_object($result);
775
+		$result = pg_query($this->db, $req);
776
+		$data = pg_fetch_object($result);
777 777
 
778
-        return $data;
779
-    }
778
+		return $data;
779
+	}
780 780
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManager.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -6,130 +6,130 @@
 block discarded – undo
6 6
 
7 7
 abstract class QueryManager
8 8
 {
9
-    protected static $time_offset;
10
-    protected static $config;
9
+	protected static $time_offset;
10
+	protected static $config;
11 11
 
12
-    private static $current;
12
+	private static $current;
13 13
 
14
-    public static function current()
15
-    {
16
-        global $time_offset;
14
+	public static function current()
15
+	{
16
+		global $time_offset;
17 17
 
18
-        if (null == self::$current) {
19
-            $variables = realpath(dirname(__FILE__)).'/../../json/variables.json';
20
-            self::$config = json_decode(file_get_contents($variables));
18
+		if (null == self::$current) {
19
+			$variables = realpath(dirname(__FILE__)).'/../../json/variables.json';
20
+			self::$config = json_decode(file_get_contents($variables));
21 21
 
22
-            include_once SYS_PATH.'/core/process/timezone.loader.php';
23
-            self::$time_offset = $time_offset;
22
+			include_once SYS_PATH.'/core/process/timezone.loader.php';
23
+			self::$time_offset = $time_offset;
24 24
 
25
-            switch (strtolower(SYS_DB_TYPE)) {
26
-                case 'monocle-alt':
27
-                case 'monocle-alt-mysql':
28
-                    self::$current = new QueryManagerMysqlMonocleAlternate();
29
-                    break;
30
-                case 'monocle-alt-pgsql':
31
-                    self::$current = new QueryManagerPostgresqlMonocleAlternate();
32
-                    break;
33
-                default: //rocketmap
34
-                    self::$current = new QueryManagerMysqlRocketmap();
35
-                    break;
36
-            }
37
-        }
25
+			switch (strtolower(SYS_DB_TYPE)) {
26
+				case 'monocle-alt':
27
+				case 'monocle-alt-mysql':
28
+					self::$current = new QueryManagerMysqlMonocleAlternate();
29
+					break;
30
+				case 'monocle-alt-pgsql':
31
+					self::$current = new QueryManagerPostgresqlMonocleAlternate();
32
+					break;
33
+				default: //rocketmap
34
+					self::$current = new QueryManagerMysqlRocketmap();
35
+					break;
36
+			}
37
+		}
38 38
 
39
-        return self::$current;
40
-    }
39
+		return self::$current;
40
+	}
41 41
 
42
-    private function __construct()
43
-    {
44
-    }
42
+	private function __construct()
43
+	{
44
+	}
45 45
 
46
-    // Misc
47
-    abstract public function getEcapedString($string);
46
+	// Misc
47
+	abstract public function getEcapedString($string);
48 48
 
49
-    // Tester
50
-    abstract public function testTotalPokemon();
49
+	// Tester
50
+	abstract public function testTotalPokemon();
51 51
 
52
-    abstract public function testTotalGyms();
52
+	abstract public function testTotalGyms();
53 53
 
54
-    abstract public function testTotalPokestops();
54
+	abstract public function testTotalPokestops();
55 55
 
56
-    // Homepage
57
-    abstract public function getTotalPokemon();
56
+	// Homepage
57
+	abstract public function getTotalPokemon();
58 58
 
59
-    abstract public function getTotalLures();
59
+	abstract public function getTotalLures();
60 60
 
61
-    abstract public function getTotalGyms();
61
+	abstract public function getTotalGyms();
62 62
 
63
-    abstract public function getTotalRaids();
63
+	abstract public function getTotalRaids();
64 64
 
65
-    abstract public function getTotalGymsForTeam($team_id);
65
+	abstract public function getTotalGymsForTeam($team_id);
66 66
 
67
-    abstract public function getRecentAll();
67
+	abstract public function getRecentAll();
68 68
 
69
-    abstract public function getRecentMythic($mythic_pokemon);
69
+	abstract public function getRecentMythic($mythic_pokemon);
70 70
 
71
-    // Single Pokemon
72
-    abstract public function getGymsProtectedByPokemon($pokemon_id);
71
+	// Single Pokemon
72
+	abstract public function getGymsProtectedByPokemon($pokemon_id);
73 73
 
74
-    abstract public function getPokemonLastSeen($pokemon_id);
74
+	abstract public function getPokemonLastSeen($pokemon_id);
75 75
 
76
-    abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
76
+	abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction);
77 77
 
78
-    abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
78
+	abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction);
79 79
 
80
-    abstract public function getPokemonHeatmap($pokemon_id, $start, $end);
80
+	abstract public function getPokemonHeatmap($pokemon_id, $start, $end);
81 81
 
82
-    abstract public function getPokemonGraph($pokemon_id);
82
+	abstract public function getPokemonGraph($pokemon_id);
83 83
 
84
-    abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
84
+	abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons);
85 85
 
86
-    abstract public function getPokemonSliderMinMax();
86
+	abstract public function getPokemonSliderMinMax();
87 87
 
88
-    abstract public function getMapsCoords();
88
+	abstract public function getMapsCoords();
89 89
 
90
-    abstract public function getPokemonCount($pokemon_id);
90
+	abstract public function getPokemonCount($pokemon_id);
91 91
 
92
-    abstract public function getRaidCount($pokemon_id);
92
+	abstract public function getRaidCount($pokemon_id);
93 93
 
94
-    // Pokestops
95
-    abstract public function getTotalPokestops();
94
+	// Pokestops
95
+	abstract public function getTotalPokestops();
96 96
 
97
-    abstract public function getAllPokestops();
97
+	abstract public function getAllPokestops();
98 98
 
99
-    // Gyms
100
-    abstract public function getTeamGuardians($team_id);
99
+	// Gyms
100
+	abstract public function getTeamGuardians($team_id);
101 101
 
102
-    abstract public function getOwnedAndPoints($team_id);
102
+	abstract public function getOwnedAndPoints($team_id);
103 103
 
104
-    abstract public function getAllGyms();
104
+	abstract public function getAllGyms();
105 105
 
106
-    abstract public function getGymData($gym_id);
106
+	abstract public function getGymData($gym_id);
107 107
 
108
-    abstract public function getGymDefenders($gym_id);
108
+	abstract public function getGymDefenders($gym_id);
109 109
 
110
-    // Gym History
111
-    abstract public function getGymHistories($gym_name, $team, $page, $ranking);
110
+	// Gym History
111
+	abstract public function getGymHistories($gym_name, $team, $page, $ranking);
112 112
 
113
-    abstract public function getGymHistoriesPokemon($gym_id);
113
+	abstract public function getGymHistoriesPokemon($gym_id);
114 114
 
115
-    abstract public function getHistoryForGym($page, $gym_id);
115
+	abstract public function getHistoryForGym($page, $gym_id);
116 116
 
117
-    // Raids
118
-    abstract public function getAllRaids($page);
117
+	// Raids
118
+	abstract public function getAllRaids($page);
119 119
 
120
-    // Trainers
121
-    abstract public function getTrainers($trainer_name, $team, $page, $ranking);
120
+	// Trainers
121
+	abstract public function getTrainers($trainer_name, $team, $page, $ranking);
122 122
 
123
-    abstract public function getTrainerLevelCount($team_id);
123
+	abstract public function getTrainerLevelCount($team_id);
124 124
 
125
-    // Cron
126
-    abstract public function getPokemonCountsActive();
125
+	// Cron
126
+	abstract public function getPokemonCountsActive();
127 127
 
128
-    abstract public function getPokemonCountsLastDay();
128
+	abstract public function getPokemonCountsLastDay();
129 129
 
130
-    abstract public function getCaptchaCount();
130
+	abstract public function getCaptchaCount();
131 131
 
132
-    abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
132
+	abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
133 133
 
134
-    abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
134
+	abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
135 135
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerMysql.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -5,34 +5,34 @@
 block discarded – undo
5 5
 
6 6
 abstract class QueryManagerMysql extends QueryManager
7 7
 {
8
-    protected $mysqli;
8
+	protected $mysqli;
9 9
 
10
-    protected function __construct()
11
-    {
12
-        $this->mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT);
13
-        if ('' != $this->mysqli->connect_error) {
14
-            header('Location:'.HOST_URL.'offline.html');
15
-            exit();
16
-        }
17
-        $this->mysqli->set_charset('utf8');
10
+	protected function __construct()
11
+	{
12
+		$this->mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT);
13
+		if ('' != $this->mysqli->connect_error) {
14
+			header('Location:'.HOST_URL.'offline.html');
15
+			exit();
16
+		}
17
+		$this->mysqli->set_charset('utf8');
18 18
 
19
-        if ('' != $this->mysqli->connect_error) {
20
-            header('Location:'.HOST_URL.'offline.html');
21
-            exit();
22
-        }
23
-    }
19
+		if ('' != $this->mysqli->connect_error) {
20
+			header('Location:'.HOST_URL.'offline.html');
21
+			exit();
22
+		}
23
+	}
24 24
 
25
-    public function __destruct()
26
-    {
27
-        $this->mysqli->close();
28
-    }
25
+	public function __destruct()
26
+	{
27
+		$this->mysqli->close();
28
+	}
29 29
 
30
-    /////////
31
-    // Misc
32
-    /////////
30
+	/////////
31
+	// Misc
32
+	/////////
33 33
 
34
-    public function getEcapedString($string)
35
-    {
36
-        return mysqli_real_escape_string($this->mysqli, $string);
37
-    }
34
+	public function getEcapedString($string)
35
+	{
36
+		return mysqli_real_escape_string($this->mysqli, $string);
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerPostgresql.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
 
5 5
 abstract class QueryManagerPostgresql extends QueryManager
6 6
 {
7
-    protected $db;
7
+	protected $db;
8 8
 
9
-    protected function __construct()
10
-    {
11
-        $this->db = pg_connect('host='.SYS_DB_HOST.' port='.SYS_DB_PORT.' dbname='.SYS_DB_NAME.' user='.SYS_DB_USER.' password='.SYS_DB_PSWD);
9
+	protected function __construct()
10
+	{
11
+		$this->db = pg_connect('host='.SYS_DB_HOST.' port='.SYS_DB_PORT.' dbname='.SYS_DB_NAME.' user='.SYS_DB_USER.' password='.SYS_DB_PSWD);
12 12
 
13
-        if (false === $this->db) {
14
-            header('Location:'.HOST_URL.'offline.html');
15
-            exit();
16
-        }
17
-    }
13
+		if (false === $this->db) {
14
+			header('Location:'.HOST_URL.'offline.html');
15
+			exit();
16
+		}
17
+	}
18 18
 
19
-    public function __destruct()
20
-    {
21
-        pg_close($this->db);
22
-    }
19
+	public function __destruct()
20
+	{
21
+		pg_close($this->db);
22
+	}
23 23
 
24
-    /////////
25
-    // Misc
26
-    /////////
24
+	/////////
25
+	// Misc
26
+	/////////
27 27
 
28
-    public function getEcapedString($string)
29
-    {
30
-        return pg_escape_string($this->db, $string);
31
-    }
28
+	public function getEcapedString($string)
29
+	{
30
+		return pg_escape_string($this->db, $string);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/process/queries/QueryManagerMysqlMonocleAlternate.php 1 patch
Indentation   +647 added lines, -647 removed lines patch added patch discarded remove patch
@@ -2,193 +2,193 @@  discard block
 block discarded – undo
2 2
 
3 3
 class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql
4 4
 {
5
-    public function __construct()
6
-    {
7
-        parent::__construct();
8
-    }
9
-
10
-    public function __destruct()
11
-    {
12
-        parent::__destruct();
13
-    }
14
-
15
-    ///////////
16
-    // Tester
17
-    ///////////
18
-
19
-    public function testTotalPokemon()
20
-    {
21
-        $req = 'SELECT COUNT(*) as total FROM sightings';
22
-        $result = $this->mysqli->query($req);
23
-        if (!is_object($result)) {
24
-            return 1;
25
-        } else {
26
-            $data = $result->fetch_object();
27
-            $total = $data->total;
28
-
29
-            if (0 == $total) {
30
-                return 2;
31
-            }
32
-        }
33
-
34
-        return 0;
35
-    }
36
-
37
-    public function testTotalGyms()
38
-    {
39
-        $req = 'SELECT COUNT(*) as total FROM forts';
40
-        $result = $this->mysqli->query($req);
41
-        if (!is_object($result)) {
42
-            return 1;
43
-        } else {
44
-            $data = $result->fetch_object();
45
-            $total = $data->total;
46
-
47
-            if (0 == $total) {
48
-                return 2;
49
-            }
50
-        }
51
-
52
-        return 0;
53
-    }
54
-
55
-    public function testTotalPokestops()
56
-    {
57
-        $req = 'SELECT COUNT(*) as total FROM pokestops';
58
-        $result = $this->mysqli->query($req);
59
-        if (!is_object($result)) {
60
-            return 1;
61
-        } else {
62
-            $data = $result->fetch_object();
63
-            $total = $data->total;
64
-
65
-            if (0 == $total) {
66
-                return 2;
67
-            }
68
-        }
69
-
70
-        return 0;
71
-    }
72
-
73
-    /////////////
74
-    // Homepage
75
-    /////////////
76
-
77
-    public function getTotalPokemon()
78
-    {
79
-        $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()';
80
-        $result = $this->mysqli->query($req);
81
-        $data = $result->fetch_object();
82
-
83
-        return $data;
84
-    }
85
-
86
-    public function getTotalLures()
87
-    {
88
-        $data = (object) array('total' => 0);
89
-
90
-        return $data;
91
-    }
92
-
93
-    public function getTotalGyms()
94
-    {
95
-        $req = 'SELECT COUNT(*) AS total FROM forts';
96
-        $result = $this->mysqli->query($req);
97
-        $data = $result->fetch_object();
98
-
99
-        return $data;
100
-    }
101
-
102
-    public function getTotalRaids()
103
-    {
104
-        $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()';
105
-        $result = $this->mysqli->query($req);
106
-        $data = $result->fetch_object();
107
-
108
-        return $data;
109
-    }
110
-
111
-    public function getTotalGymsForTeam($team_id)
112
-    {
113
-        $req = "SELECT COUNT(*) AS total
5
+	public function __construct()
6
+	{
7
+		parent::__construct();
8
+	}
9
+
10
+	public function __destruct()
11
+	{
12
+		parent::__destruct();
13
+	}
14
+
15
+	///////////
16
+	// Tester
17
+	///////////
18
+
19
+	public function testTotalPokemon()
20
+	{
21
+		$req = 'SELECT COUNT(*) as total FROM sightings';
22
+		$result = $this->mysqli->query($req);
23
+		if (!is_object($result)) {
24
+			return 1;
25
+		} else {
26
+			$data = $result->fetch_object();
27
+			$total = $data->total;
28
+
29
+			if (0 == $total) {
30
+				return 2;
31
+			}
32
+		}
33
+
34
+		return 0;
35
+	}
36
+
37
+	public function testTotalGyms()
38
+	{
39
+		$req = 'SELECT COUNT(*) as total FROM forts';
40
+		$result = $this->mysqli->query($req);
41
+		if (!is_object($result)) {
42
+			return 1;
43
+		} else {
44
+			$data = $result->fetch_object();
45
+			$total = $data->total;
46
+
47
+			if (0 == $total) {
48
+				return 2;
49
+			}
50
+		}
51
+
52
+		return 0;
53
+	}
54
+
55
+	public function testTotalPokestops()
56
+	{
57
+		$req = 'SELECT COUNT(*) as total FROM pokestops';
58
+		$result = $this->mysqli->query($req);
59
+		if (!is_object($result)) {
60
+			return 1;
61
+		} else {
62
+			$data = $result->fetch_object();
63
+			$total = $data->total;
64
+
65
+			if (0 == $total) {
66
+				return 2;
67
+			}
68
+		}
69
+
70
+		return 0;
71
+	}
72
+
73
+	/////////////
74
+	// Homepage
75
+	/////////////
76
+
77
+	public function getTotalPokemon()
78
+	{
79
+		$req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()';
80
+		$result = $this->mysqli->query($req);
81
+		$data = $result->fetch_object();
82
+
83
+		return $data;
84
+	}
85
+
86
+	public function getTotalLures()
87
+	{
88
+		$data = (object) array('total' => 0);
89
+
90
+		return $data;
91
+	}
92
+
93
+	public function getTotalGyms()
94
+	{
95
+		$req = 'SELECT COUNT(*) AS total FROM forts';
96
+		$result = $this->mysqli->query($req);
97
+		$data = $result->fetch_object();
98
+
99
+		return $data;
100
+	}
101
+
102
+	public function getTotalRaids()
103
+	{
104
+		$req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP()';
105
+		$result = $this->mysqli->query($req);
106
+		$data = $result->fetch_object();
107
+
108
+		return $data;
109
+	}
110
+
111
+	public function getTotalGymsForTeam($team_id)
112
+	{
113
+		$req = "SELECT COUNT(*) AS total
114 114
 					FROM forts f
115 115
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
116 116
 					WHERE team = '$team_id'";
117
-        $result = $this->mysqli->query($req);
118
-        $data = $result->fetch_object();
117
+		$result = $this->mysqli->query($req);
118
+		$data = $result->fetch_object();
119 119
 
120
-        return $data;
121
-    }
120
+		return $data;
121
+	}
122 122
 
123
-    public function getRecentAll()
124
-    {
125
-        $req = 'SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
123
+	public function getRecentAll()
124
+	{
125
+		$req = 'SELECT DISTINCT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
126 126
               lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
127 127
               FROM sightings
128 128
               ORDER BY updated DESC
129 129
               LIMIT 0,12';
130
-        $result = $this->mysqli->query($req);
131
-        $data = array();
132
-        if ($result->num_rows > 0) {
133
-            while ($row = $result->fetch_object()) {
134
-                $data[] = $row;
135
-            }
136
-        }
137
-
138
-        return $data;
139
-    }
140
-
141
-    public function getRecentMythic($mythic_pokemon)
142
-    {
143
-        $req = 'SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
130
+		$result = $this->mysqli->query($req);
131
+		$data = array();
132
+		if ($result->num_rows > 0) {
133
+			while ($row = $result->fetch_object()) {
134
+				$data[] = $row;
135
+			}
136
+		}
137
+
138
+		return $data;
139
+	}
140
+
141
+	public function getRecentMythic($mythic_pokemon)
142
+	{
143
+		$req = 'SELECT pokemon_id, encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
144 144
                 lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina
145 145
                 FROM sightings
146 146
                 WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).')
147 147
                 ORDER BY updated DESC
148 148
                 LIMIT 0,12';
149
-        $result = $this->mysqli->query($req);
150
-        $data = array();
151
-        if ($result->num_rows > 0) {
152
-            while ($row = $result->fetch_object()) {
153
-                $data[] = $row;
154
-            }
155
-        }
156
-
157
-        return $data;
158
-    }
159
-
160
-    ///////////////////
161
-    // Single Pokemon
162
-    ///////////////////
163
-
164
-    public function getGymsProtectedByPokemon($pokemon_id)
165
-    {
166
-        $req = "SELECT COUNT(f.id) AS total
149
+		$result = $this->mysqli->query($req);
150
+		$data = array();
151
+		if ($result->num_rows > 0) {
152
+			while ($row = $result->fetch_object()) {
153
+				$data[] = $row;
154
+			}
155
+		}
156
+
157
+		return $data;
158
+	}
159
+
160
+	///////////////////
161
+	// Single Pokemon
162
+	///////////////////
163
+
164
+	public function getGymsProtectedByPokemon($pokemon_id)
165
+	{
166
+		$req = "SELECT COUNT(f.id) AS total
167 167
 					FROM forts f
168 168
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
169 169
 					WHERE guard_pokemon_id = '".$pokemon_id."'";
170
-        $result = $this->mysqli->query($req);
171
-        $data = $result->fetch_object();
170
+		$result = $this->mysqli->query($req);
171
+		$data = $result->fetch_object();
172 172
 
173
-        return $data;
174
-    }
173
+		return $data;
174
+	}
175 175
 
176
-    public function getPokemonLastSeen($pokemon_id)
177
-    {
178
-        $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
176
+	public function getPokemonLastSeen($pokemon_id)
177
+	{
178
+		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude
179 179
                 FROM sightings
180 180
                 WHERE pokemon_id = '".$pokemon_id."'
181 181
                 ORDER BY expire_timestamp DESC
182 182
                 LIMIT 0,1";
183
-        $result = $this->mysqli->query($req);
184
-        $data = $result->fetch_object();
183
+		$result = $this->mysqli->query($req);
184
+		$data = $result->fetch_object();
185 185
 
186
-        return $data;
187
-    }
186
+		return $data;
187
+	}
188 188
 
189
-    public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
-    {
191
-        $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
189
+	public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction)
190
+	{
191
+		$req = "SELECT FROM_UNIXTIME(expire_timestamp) AS distime, pokemon_id as pokemon_id, FROM_UNIXTIME(expire_timestamp) as disappear_time, lat as latitude, lon as longitude,
192 192
                 cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina,
193 193
                 ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form
194 194
                 FROM sightings
@@ -196,407 +196,407 @@  discard block
 block discarded – undo
196 196
 	            ORDER BY $top_order_by $top_direction, expire_timestamp DESC
197 197
 	            LIMIT 0,50";
198 198
 
199
-        $result = $this->mysqli->query($req);
200
-        $top = array();
201
-        while ($data = $result->fetch_object()) {
202
-            $top[] = $data;
203
-        }
199
+		$result = $this->mysqli->query($req);
200
+		$top = array();
201
+		while ($data = $result->fetch_object()) {
202
+			$top[] = $data;
203
+		}
204 204
 
205
-        return $top;
206
-    }
205
+		return $top;
206
+	}
207 207
 
208
-    public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
209
-    {
210
-        $trainer_blacklist = '';
211
-        if (!empty(self::$config->system->trainer_blacklist)) {
212
-            $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
213
-        }
208
+	public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction)
209
+	{
210
+		$trainer_blacklist = '';
211
+		if (!empty(self::$config->system->trainer_blacklist)) {
212
+			$trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
213
+		}
214 214
 
215
-        $req = "SELECT owner_name as trainer_name, ROUND((100*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS IV, move_1, move_2, cp as cp,
215
+		$req = "SELECT owner_name as trainer_name, ROUND((100*((atk_iv)+(def_iv)+(sta_iv))/45),1) AS IV, move_1, move_2, cp as cp,
216 216
                 FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen
217 217
                 FROM gym_defenders
218 218
 				WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist."
219 219
 				ORDER BY $best_order_by $best_direction, owner_name ASC
220 220
 				LIMIT 0,50";
221 221
 
222
-        $result = $this->mysqli->query($req);
223
-        $toptrainer = array();
224
-        while ($data = $result->fetch_object()) {
225
-            $toptrainer[] = $data;
226
-        }
227
-
228
-        return $toptrainer;
229
-    }
230
-
231
-    public function getPokemonHeatmap($pokemon_id, $start, $end)
232
-    {
233
-        $where = ' WHERE pokemon_id = '.$pokemon_id.' '
234
-            ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
235
-        $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000';
236
-        $result = $this->mysqli->query($req);
237
-        $points = array();
238
-        while ($data = $result->fetch_object()) {
239
-            $points[] = $data;
240
-        }
241
-
242
-        return $points;
243
-    }
244
-
245
-    public function getPokemonGraph($pokemon_id)
246
-    {
247
-        $req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
222
+		$result = $this->mysqli->query($req);
223
+		$toptrainer = array();
224
+		while ($data = $result->fetch_object()) {
225
+			$toptrainer[] = $data;
226
+		}
227
+
228
+		return $toptrainer;
229
+	}
230
+
231
+	public function getPokemonHeatmap($pokemon_id, $start, $end)
232
+	{
233
+		$where = ' WHERE pokemon_id = '.$pokemon_id.' '
234
+			."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'";
235
+		$req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000';
236
+		$result = $this->mysqli->query($req);
237
+		$points = array();
238
+		while ($data = $result->fetch_object()) {
239
+			$points[] = $data;
240
+		}
241
+
242
+		return $points;
243
+	}
244
+
245
+	public function getPokemonGraph($pokemon_id)
246
+	{
247
+		$req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour
248 248
 					FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered
249 249
 				GROUP BY disappear_hour
250 250
 				ORDER BY disappear_hour";
251
-        $result = $this->mysqli->query($req);
252
-        $array = array_fill(0, 24, 0);
253
-        while ($result && $data = $result->fetch_object()) {
254
-            $array[$data->disappear_hour] = $data->total;
255
-        }
256
-        // shift array because AM/PM starts at 1AM not 0:00
257
-        $array[] = $array[0];
258
-        array_shift($array);
259
-
260
-        return $array;
261
-    }
262
-
263
-    public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
264
-    {
265
-        $inmap_pkms_filter = '';
266
-        $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
267
-
268
-        $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where;
269
-        $resultTestIv = $this->mysqli->query($reqTestIv);
270
-        $testIv = $resultTestIv->fetch_object();
271
-        if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
272
-            foreach ($inmap_pokemons as $inmap) {
273
-                $inmap_pkms_filter .= "'".$inmap."',";
274
-            }
275
-            $inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
276
-            $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
277
-        }
278
-        if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
279
-            $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') ';
280
-        }
281
-        if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
282
-            $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') ';
283
-        }
284
-        $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude,
251
+		$result = $this->mysqli->query($req);
252
+		$array = array_fill(0, 24, 0);
253
+		while ($result && $data = $result->fetch_object()) {
254
+			$array[$data->disappear_hour] = $data->total;
255
+		}
256
+		// shift array because AM/PM starts at 1AM not 0:00
257
+		$array[] = $array[0];
258
+		array_shift($array);
259
+
260
+		return $array;
261
+	}
262
+
263
+	public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons)
264
+	{
265
+		$inmap_pkms_filter = '';
266
+		$where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id;
267
+
268
+		$reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where;
269
+		$resultTestIv = $this->mysqli->query($reqTestIv);
270
+		$testIv = $resultTestIv->fetch_object();
271
+		if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) {
272
+			foreach ($inmap_pokemons as $inmap) {
273
+				$inmap_pkms_filter .= "'".$inmap."',";
274
+			}
275
+			$inmap_pkms_filter = rtrim($inmap_pkms_filter, ',');
276
+			$where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') ';
277
+		}
278
+		if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) {
279
+			$where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') ';
280
+		}
281
+		if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) {
282
+			$where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') ';
283
+		}
284
+		$req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude,
285 285
     					FROM_UNIXTIME(expire_timestamp) AS disappear_time,
286 286
     					FROM_UNIXTIME(expire_timestamp) AS disappear_time_real,
287 287
     					atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina,
288 288
    						move_1, move_2
289 289
 					FROM sightings '.$where.'
290 290
 					LIMIT 5000';
291
-        $result = $this->mysqli->query($req);
292
-        $spawns = array();
293
-        while ($data = $result->fetch_object()) {
294
-            $spawns[] = $data;
295
-        }
296
-
297
-        return $spawns;
298
-    }
299
-
300
-    public function getPokemonSliderMinMax()
301
-    {
302
-        $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings';
303
-        $result = $this->mysqli->query($req);
304
-        $data = $result->fetch_object();
305
-
306
-        return $data;
307
-    }
308
-
309
-    public function getMapsCoords()
310
-    {
311
-        $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
312
-        $result = $this->mysqli->query($req);
313
-        $data = $result->fetch_object();
314
-
315
-        return $data;
316
-    }
317
-
318
-    public function getPokemonCount($pokemon_id)
319
-    {
320
-        $req = 'SELECT count, last_seen, latitude, longitude
291
+		$result = $this->mysqli->query($req);
292
+		$spawns = array();
293
+		while ($data = $result->fetch_object()) {
294
+			$spawns[] = $data;
295
+		}
296
+
297
+		return $spawns;
298
+	}
299
+
300
+	public function getPokemonSliderMinMax()
301
+	{
302
+		$req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings';
303
+		$result = $this->mysqli->query($req);
304
+		$data = $result->fetch_object();
305
+
306
+		return $data;
307
+	}
308
+
309
+	public function getMapsCoords()
310
+	{
311
+		$req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints';
312
+		$result = $this->mysqli->query($req);
313
+		$data = $result->fetch_object();
314
+
315
+		return $data;
316
+	}
317
+
318
+	public function getPokemonCount($pokemon_id)
319
+	{
320
+		$req = 'SELECT count, last_seen, latitude, longitude
321 321
 					FROM pokemon_stats
322 322
 					WHERE pid = '.$pokemon_id;
323
-        $result = $this->mysqli->query($req);
324
-        $data = $result->fetch_object();
323
+		$result = $this->mysqli->query($req);
324
+		$data = $result->fetch_object();
325 325
 
326
-        return $data;
327
-    }
326
+		return $data;
327
+	}
328 328
 
329
-    public function getRaidCount($pokemon_id)
330
-    {
331
-        $req = 'SELECT count, last_seen, latitude, longitude
329
+	public function getRaidCount($pokemon_id)
330
+	{
331
+		$req = 'SELECT count, last_seen, latitude, longitude
332 332
 					FROM raid_stats
333 333
 					WHERE pid = '.$pokemon_id;
334
-        $result = $this->mysqli->query($req);
335
-        $data = $result->fetch_object();
336
-
337
-        return $data;
338
-    }
339
-
340
-    ///////////////
341
-    // Pokestops
342
-    //////////////
343
-
344
-    public function getTotalPokestops()
345
-    {
346
-        $req = 'SELECT COUNT(*) as total FROM pokestops';
347
-        $result = $this->mysqli->query($req);
348
-        $data = $result->fetch_object();
349
-
350
-        return $data;
351
-    }
352
-
353
-    public function getAllPokestops()
354
-    {
355
-        $req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops';
356
-        $result = $this->mysqli->query($req);
357
-        $pokestops = array();
358
-        while ($data = $result->fetch_object()) {
359
-            $pokestops[] = $data;
360
-        }
361
-
362
-        return $pokestops;
363
-    }
364
-
365
-    /////////
366
-    // Gyms
367
-    /////////
368
-
369
-    public function getTeamGuardians($team_id)
370
-    {
371
-        $req = "SELECT COUNT(*) AS total, guard_pokemon_id
334
+		$result = $this->mysqli->query($req);
335
+		$data = $result->fetch_object();
336
+
337
+		return $data;
338
+	}
339
+
340
+	///////////////
341
+	// Pokestops
342
+	//////////////
343
+
344
+	public function getTotalPokestops()
345
+	{
346
+		$req = 'SELECT COUNT(*) as total FROM pokestops';
347
+		$result = $this->mysqli->query($req);
348
+		$data = $result->fetch_object();
349
+
350
+		return $data;
351
+	}
352
+
353
+	public function getAllPokestops()
354
+	{
355
+		$req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops';
356
+		$result = $this->mysqli->query($req);
357
+		$pokestops = array();
358
+		while ($data = $result->fetch_object()) {
359
+			$pokestops[] = $data;
360
+		}
361
+
362
+		return $pokestops;
363
+	}
364
+
365
+	/////////
366
+	// Gyms
367
+	/////////
368
+
369
+	public function getTeamGuardians($team_id)
370
+	{
371
+		$req = "SELECT COUNT(*) AS total, guard_pokemon_id
372 372
 					FROM forts f
373 373
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
374 374
 					WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3";
375
-        $result = $this->mysqli->query($req);
375
+		$result = $this->mysqli->query($req);
376 376
 
377
-        $datas = array();
378
-        while ($data = $result->fetch_object()) {
379
-            $datas[] = $data;
380
-        }
377
+		$datas = array();
378
+		while ($data = $result->fetch_object()) {
379
+			$datas[] = $data;
380
+		}
381 381
 
382
-        return $datas;
383
-    }
382
+		return $datas;
383
+	}
384 384
 
385
-    public function getOwnedAndPoints($team_id)
386
-    {
387
-        $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points
385
+	public function getOwnedAndPoints($team_id)
386
+	{
387
+		$req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points
388 388
         			FROM forts f
389 389
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
390 390
         			WHERE fs.team = '".$team_id."'";
391
-        $result = $this->mysqli->query($req);
392
-        $data = $result->fetch_object();
391
+		$result = $this->mysqli->query($req);
392
+		$data = $result->fetch_object();
393 393
 
394
-        return $data;
395
-    }
394
+		return $data;
395
+	}
396 396
 
397
-    public function getAllGyms()
398
-    {
399
-        $req = 'SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level
397
+	public function getAllGyms()
398
+	{
399
+		$req = 'SELECT f.id as gym_id, team as team_id, f.lat as latitude, f.lon as longitude, updated as last_scanned, (6 - fs.slots_available) AS level
400 400
 					FROM forts f
401 401
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id));';
402
-        $result = $this->mysqli->query($req);
403
-        $gyms = array();
404
-        while ($data = $result->fetch_object()) {
405
-            $gyms[] = $data;
406
-        }
407
-
408
-        return $gyms;
409
-    }
410
-
411
-    public function getGymData($gym_id)
412
-    {
413
-        $req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, FROM_UNIXTIME(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp
402
+		$result = $this->mysqli->query($req);
403
+		$gyms = array();
404
+		while ($data = $result->fetch_object()) {
405
+			$gyms[] = $data;
406
+		}
407
+
408
+		return $gyms;
409
+	}
410
+
411
+	public function getGymData($gym_id)
412
+	{
413
+		$req = "SELECT f.name AS name, null AS description, f.url AS url, fs.team AS team, FROM_UNIXTIME(fs.updated) AS last_scanned, fs.guard_pokemon_id AS guard_pokemon_id, (6 - fs.slots_available) AS level, fs.total_cp
414 414
 			FROM forts f
415 415
 			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
416 416
 			WHERE f.id ='".$gym_id."'";
417
-        $result = $this->mysqli->query($req);
418
-        $data = $result->fetch_object();
417
+		$result = $this->mysqli->query($req);
418
+		$data = $result->fetch_object();
419 419
 
420
-        return $data;
421
-    }
420
+		return $data;
421
+	}
422 422
 
423
-    public function getGymDefenders($gym_id)
424
-    {
425
-        $req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
423
+	public function getGymDefenders($gym_id)
424
+	{
425
+		$req = "SELECT external_id as pokemon_uid, pokemon_id, atk_iv as iv_attack, def_iv as iv_defense, sta_iv as iv_stamina, cp, fort_id as gym_id
426 426
 			FROM gym_defenders
427 427
 			WHERE fort_id='".$gym_id."'
428 428
 			ORDER BY deployment_time";
429
-        $result = $this->mysqli->query($req);
430
-        $defenders = array();
431
-        while ($data = $result->fetch_object()) {
432
-            $defenders[] = $data;
433
-        }
434
-
435
-        return $defenders;
436
-    }
437
-
438
-    ///////////
439
-    // Raids
440
-    ///////////
441
-
442
-    public function getAllRaids($page)
443
-    {
444
-        $limit = ' LIMIT '.($page * 10).',10';
445
-        $req = 'SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude
429
+		$result = $this->mysqli->query($req);
430
+		$defenders = array();
431
+		while ($data = $result->fetch_object()) {
432
+			$defenders[] = $data;
433
+		}
434
+
435
+		return $defenders;
436
+	}
437
+
438
+	///////////
439
+	// Raids
440
+	///////////
441
+
442
+	public function getAllRaids($page)
443
+	{
444
+		$limit = ' LIMIT '.($page * 10).',10';
445
+		$req = 'SELECT r.fort_id AS gym_id, r.level AS level, r.pokemon_id AS pokemon_id, r.cp AS cp, r.move_1 AS move_1, r.move_2 AS move_2, FROM_UNIXTIME(r.time_spawn) AS spawn, FROM_UNIXTIME(r.time_battle) AS start, FROM_UNIXTIME(r.time_end) AS end, FROM_UNIXTIME(fs.updated) AS last_scanned, f.name, f.lat AS latitude, f.lon as longitude
446 446
 					FROM forts f
447 447
 					LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
448 448
 				 	LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP())
449 449
 					WHERE r.time_end > UNIX_TIMESTAMP()
450 450
 					ORDER BY r.level DESC, r.time_battle'.$limit;
451
-        $result = $this->mysqli->query($req);
452
-        $raids = array();
453
-        while ($data = $result->fetch_object()) {
454
-            $raids[] = $data;
455
-        }
456
-
457
-        return $raids;
458
-    }
459
-
460
-    ////////////////
461
-    // Gym History
462
-    ////////////////
463
-
464
-    public function getGymHistories($gym_name, $team, $page, $ranking)
465
-    {
466
-        $where = '';
467
-        if (isset($gym_name) && '' != $gym_name) {
468
-            $where = " WHERE name LIKE '%".$gym_name."%'";
469
-        }
470
-        if (isset($team) && '' != $team) {
471
-            $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team;
472
-        }
473
-        switch ($ranking) {
474
-            case 1:
475
-                $order = ' ORDER BY name, last_modified DESC';
476
-                break;
477
-            case 2:
478
-                $order = ' ORDER BY total_cp DESC, last_modified DESC';
479
-                break;
480
-            default:
481
-                $order = ' ORDER BY last_modified DESC, name';
482
-        }
483
-
484
-        $limit = ' LIMIT '.($page * 10).',10';
485
-
486
-        $req = 'SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified
451
+		$result = $this->mysqli->query($req);
452
+		$raids = array();
453
+		while ($data = $result->fetch_object()) {
454
+			$raids[] = $data;
455
+		}
456
+
457
+		return $raids;
458
+	}
459
+
460
+	////////////////
461
+	// Gym History
462
+	////////////////
463
+
464
+	public function getGymHistories($gym_name, $team, $page, $ranking)
465
+	{
466
+		$where = '';
467
+		if (isset($gym_name) && '' != $gym_name) {
468
+			$where = " WHERE name LIKE '%".$gym_name."%'";
469
+		}
470
+		if (isset($team) && '' != $team) {
471
+			$where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team;
472
+		}
473
+		switch ($ranking) {
474
+			case 1:
475
+				$order = ' ORDER BY name, last_modified DESC';
476
+				break;
477
+			case 2:
478
+				$order = ' ORDER BY total_cp DESC, last_modified DESC';
479
+				break;
480
+			default:
481
+				$order = ' ORDER BY last_modified DESC, name';
482
+		}
483
+
484
+		$limit = ' LIMIT '.($page * 10).',10';
485
+
486
+		$req = 'SELECT f.id as gym_id, fs.total_cp, f.name, fs.team as team_id, (6 - slots_available) as pokemon_count, FROM_UNIXTIME(last_modified) AS last_modified
487 487
 			FROM forts f
488 488
 			LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))
489 489
 			'.$where.$order.$limit;
490
-        $result = $this->mysqli->query($req);
491
-        $gym_history = array();
492
-        while ($data = $result->fetch_object()) {
493
-            $gym_history[] = $data;
494
-        }
495
-
496
-        return $gym_history;
497
-    }
498
-
499
-    public function getGymHistoriesPokemon($gym_id)
500
-    {
501
-        $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
490
+		$result = $this->mysqli->query($req);
491
+		$gym_history = array();
492
+		while ($data = $result->fetch_object()) {
493
+			$gym_history[] = $data;
494
+		}
495
+
496
+		return $gym_history;
497
+	}
498
+
499
+	public function getGymHistoriesPokemon($gym_id)
500
+	{
501
+		$req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name
502 502
 					FROM gym_defenders
503 503
 					WHERE fort_id = '".$gym_id."'
504 504
 					ORDER BY deployment_time";
505
-        $result = $this->mysqli->query($req);
506
-        $pokemons = array();
507
-        while ($data = $result->fetch_object()) {
508
-            $pokemons[] = $data;
509
-        }
510
-
511
-        return $pokemons;
512
-    }
513
-
514
-    public function getHistoryForGym($page, $gym_id)
515
-    {
516
-        if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
517
-            $pageSize = 25;
518
-        } else {
519
-            $pageSize = 10;
520
-        }
521
-        $req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real
505
+		$result = $this->mysqli->query($req);
506
+		$pokemons = array();
507
+		while ($data = $result->fetch_object()) {
508
+			$pokemons[] = $data;
509
+		}
510
+
511
+		return $pokemons;
512
+	}
513
+
514
+	public function getHistoryForGym($page, $gym_id)
515
+	{
516
+		if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) {
517
+			$pageSize = 25;
518
+		} else {
519
+			$pageSize = 10;
520
+		}
521
+		$req = "SELECT f.id as gym_id, fs.team as team_id, total_cp, FROM_UNIXTIME(fs.last_modified) as last_modified, last_modified as last_modified_real
522 522
 					FROM fort_sightings fs
523 523
 					LEFT JOIN forts f ON f.id = fs.fort_id
524 524
 					WHERE f.id = '".$gym_id."'
525 525
 					ORDER BY fs.last_modified DESC
526 526
 					LIMIT ".($page * $pageSize).','.($pageSize + 1);
527
-        $result = $this->mysqli->query($req);
528
-        $history = array();
529
-        $count = 0;
530
-        while ($data = $result->fetch_object()) {
531
-            ++$count;
532
-            if (0 == $data->total_cp) {
533
-                $data->pokemon = array();
534
-                $data->pokemon_count = 0;
535
-                $data->pokemon_uids = '';
536
-            } else {
537
-                $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
538
-                $data->pokemon_count = count($data->pokemon);
539
-                $data->pokemon_uids = implode(',', array_keys($data->pokemon));
540
-            }
541
-            if (0 === $data->total_cp || 0 !== $data->pokemon_count) {
542
-                $history[] = $data;
543
-            }
544
-        }
545
-        if ($count !== ($pageSize + 1)) {
546
-            $last_page = true;
547
-        } else {
548
-            $last_page = false;
549
-        }
550
-
551
-        return array('last_page' => $last_page, 'data' => $history);
552
-    }
553
-
554
-    private function getHistoryForGymPokemon($gym_id, $last_modified)
555
-    {
556
-        $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
527
+		$result = $this->mysqli->query($req);
528
+		$history = array();
529
+		$count = 0;
530
+		while ($data = $result->fetch_object()) {
531
+			++$count;
532
+			if (0 == $data->total_cp) {
533
+				$data->pokemon = array();
534
+				$data->pokemon_count = 0;
535
+				$data->pokemon_uids = '';
536
+			} else {
537
+				$data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real);
538
+				$data->pokemon_count = count($data->pokemon);
539
+				$data->pokemon_uids = implode(',', array_keys($data->pokemon));
540
+			}
541
+			if (0 === $data->total_cp || 0 !== $data->pokemon_count) {
542
+				$history[] = $data;
543
+			}
544
+		}
545
+		if ($count !== ($pageSize + 1)) {
546
+			$last_page = true;
547
+		} else {
548
+			$last_page = false;
549
+		}
550
+
551
+		return array('last_page' => $last_page, 'data' => $history);
552
+	}
553
+
554
+	private function getHistoryForGymPokemon($gym_id, $last_modified)
555
+	{
556
+		$req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name
557 557
 					FROM gym_history_defenders ghd
558 558
 					JOIN gym_defenders gd ON ghd.defender_id = gd.external_id
559 559
 					WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."'
560 560
 					ORDER BY gd.deployment_time";
561
-        $result = $this->mysqli->query($req);
562
-        $pokemons = array();
563
-        while ($data = $result->fetch_object()) {
564
-            $pokemons[$data->defender_id] = $data;
565
-        }
566
-
567
-        return $pokemons;
568
-    }
569
-
570
-    //////////////
571
-    // Trainers
572
-    //////////////
573
-
574
-    public function getTrainers($trainer_name, $team, $page, $rankingNumber)
575
-    {
576
-        $ranking = $this->getTrainerLevelRanking();
577
-        $where = '';
578
-        if (!empty(self::$config->system->trainer_blacklist)) {
579
-            $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
580
-        }
581
-        if ('' != $trainer_name) {
582
-            $where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
583
-        }
584
-        if (0 != $team) {
585
-            $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
586
-        }
587
-        switch ($rankingNumber) {
588
-            case 1:
589
-                $order = ' ORDER BY active DESC, level DESC';
590
-                break;
591
-            case 2:
592
-                $order = ' ORDER BY maxCp DESC, level DESC';
593
-                break;
594
-            default:
595
-                $order = ' ORDER BY level DESC, active DESC';
596
-        }
597
-        $order .= ', last_seen DESC, name ';
598
-        $limit = ' LIMIT '.($page * 10).',10 ';
599
-        $req = 'SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, FROM_UNIXTIME(MAX(last_modified)) as last_seen
561
+		$result = $this->mysqli->query($req);
562
+		$pokemons = array();
563
+		while ($data = $result->fetch_object()) {
564
+			$pokemons[$data->defender_id] = $data;
565
+		}
566
+
567
+		return $pokemons;
568
+	}
569
+
570
+	//////////////
571
+	// Trainers
572
+	//////////////
573
+
574
+	public function getTrainers($trainer_name, $team, $page, $rankingNumber)
575
+	{
576
+		$ranking = $this->getTrainerLevelRanking();
577
+		$where = '';
578
+		if (!empty(self::$config->system->trainer_blacklist)) {
579
+			$where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
580
+		}
581
+		if ('' != $trainer_name) {
582
+			$where = " AND gd.owner_name LIKE '%".$trainer_name."%'";
583
+		}
584
+		if (0 != $team) {
585
+			$where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team;
586
+		}
587
+		switch ($rankingNumber) {
588
+			case 1:
589
+				$order = ' ORDER BY active DESC, level DESC';
590
+				break;
591
+			case 2:
592
+				$order = ' ORDER BY maxCp DESC, level DESC';
593
+				break;
594
+			default:
595
+				$order = ' ORDER BY level DESC, active DESC';
596
+		}
597
+		$order .= ', last_seen DESC, name ';
598
+		$limit = ' LIMIT '.($page * 10).',10 ';
599
+		$req = 'SELECT gd.owner_name AS name, MAX(owner_level) AS level, MAX(cp) AS maxCp, MAX(active) AS active, MAX(team) AS team, FROM_UNIXTIME(MAX(last_modified)) as last_seen
600 600
 				  	FROM gym_defenders gd
601 601
 				  	LEFT JOIN (
602 602
 				  		SELECT owner_name, COUNT(*) as active
@@ -606,149 +606,149 @@  discard block
 block discarded – undo
606 606
 				  	) active ON active.owner_name = gd.owner_name
607 607
 				  	WHERE gd.owner_level IS NOT NULL '.$where.'
608 608
 				  	GROUP BY gd.owner_name'.$order.$limit;
609
-        $result = $this->mysqli->query($req);
610
-        $trainers = array();
611
-        while ($data = $result->fetch_object()) {
612
-            $data->last_seen = date('Y-m-d', strtotime($data->last_seen));
613
-            if (is_null($data->active)) {
614
-                $data->active = 0;
615
-            }
616
-            $trainers[$data->name] = $data;
617
-
618
-            $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name));
619
-
620
-            $trainers[$data->name]->gyms = $data->active;
621
-            $trainers[$data->name]->pokemons = $pokemon;
622
-            $trainers[$data->name]->rank = $ranking[$data->level];
623
-        }
624
-
625
-        return $trainers;
626
-    }
627
-
628
-    public function getTrainerLevelRanking()
629
-    {
630
-        $exclue = '';
631
-        if (!empty(self::$config->system->trainer_blacklist)) {
632
-            $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
633
-        }
634
-        $req = 'SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL '.$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
635
-        $result = $this->mysqli->query($req);
636
-        $levelData = array();
637
-        while ($data = $result->fetch_object()) {
638
-            $levelData[$data->level] = $data->count;
639
-        }
640
-        for ($i = 5; $i <= 40; ++$i) {
641
-            if (!isset($levelData[$i])) {
642
-                $levelData[$i] = 0;
643
-            }
644
-        }
645
-        // sort array again
646
-        ksort($levelData);
647
-
648
-        return $levelData;
649
-    }
650
-
651
-    public function getActivePokemon($trainer_name)
652
-    {
653
-        $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
609
+		$result = $this->mysqli->query($req);
610
+		$trainers = array();
611
+		while ($data = $result->fetch_object()) {
612
+			$data->last_seen = date('Y-m-d', strtotime($data->last_seen));
613
+			if (is_null($data->active)) {
614
+				$data->active = 0;
615
+			}
616
+			$trainers[$data->name] = $data;
617
+
618
+			$pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name));
619
+
620
+			$trainers[$data->name]->gyms = $data->active;
621
+			$trainers[$data->name]->pokemons = $pokemon;
622
+			$trainers[$data->name]->rank = $ranking[$data->level];
623
+		}
624
+
625
+		return $trainers;
626
+	}
627
+
628
+	public function getTrainerLevelRanking()
629
+	{
630
+		$exclue = '';
631
+		if (!empty(self::$config->system->trainer_blacklist)) {
632
+			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
633
+		}
634
+		$req = 'SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL '.$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
635
+		$result = $this->mysqli->query($req);
636
+		$levelData = array();
637
+		while ($data = $result->fetch_object()) {
638
+			$levelData[$data->level] = $data->count;
639
+		}
640
+		for ($i = 5; $i <= 40; ++$i) {
641
+			if (!isset($levelData[$i])) {
642
+				$levelData[$i] = 0;
643
+			}
644
+		}
645
+		// sort array again
646
+		ksort($levelData);
647
+
648
+		return $levelData;
649
+	}
650
+
651
+	public function getActivePokemon($trainer_name)
652
+	{
653
+		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, FROM_UNIXTIME(deployment_time) AS deployment_time, '1' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
654 654
 						FROM gym_defenders
655 655
 						WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL
656 656
 						ORDER BY deployment_time";
657
-        $result = $this->mysqli->query($req);
658
-        $pokemon = array();
659
-        while ($data = $result->fetch_object()) {
660
-            $pokemon[] = $data;
661
-        }
662
-
663
-        return $pokemon;
664
-    }
665
-
666
-    public function getInactivePokemon($trainer_name)
667
-    {
668
-        $req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
657
+		$result = $this->mysqli->query($req);
658
+		$pokemon = array();
659
+		while ($data = $result->fetch_object()) {
660
+			$pokemon[] = $data;
661
+		}
662
+
663
+		return $pokemon;
664
+	}
665
+
666
+	public function getInactivePokemon($trainer_name)
667
+	{
668
+		$req = "SELECT pokemon_id, cp, atk_iv AS iv_attack, sta_iv AS iv_stamina, def_iv AS iv_defense, NULL AS deployment_time, '0' AS active, fort_id as gym_id, FLOOR((UNIX_TIMESTAMP() - created) / 86400) AS last_scanned
669 669
 					FROM gym_defenders
670 670
 					WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL
671 671
 					ORDER BY last_scanned";
672
-        $result = $this->mysqli->query($req);
673
-        $pokemon = array();
674
-        while ($data = $result->fetch_object()) {
675
-            $pokemon[] = $data;
676
-        }
677
-
678
-        return $pokemon;
679
-    }
680
-
681
-    public function getTrainerLevelCount($team_id)
682
-    {
683
-        $exclue = '';
684
-        if (!empty(self::$config->system->trainer_blacklist)) {
685
-            $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
686
-        }
687
-        $req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
688
-        $result = $this->mysqli->query($req);
689
-        $levelData = array();
690
-        while ($data = $result->fetch_object()) {
691
-            $levelData[$data->level] = $data->count;
692
-        }
693
-        for ($i = 5; $i <= 40; ++$i) {
694
-            if (!isset($levelData[$i])) {
695
-                $levelData[$i] = 0;
696
-            }
697
-        }
698
-        // sort array again
699
-        ksort($levelData);
700
-
701
-        return $levelData;
702
-    }
703
-
704
-    /////////
705
-    // Cron
706
-    /////////
707
-
708
-    public function getPokemonCountsActive()
709
-    {
710
-        $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id';
711
-        $result = $this->mysqli->query($req);
712
-        $counts = array();
713
-        while ($data = $result->fetch_object()) {
714
-            $counts[$data->pokemon_id] = $data->total;
715
-        }
716
-
717
-        return $counts;
718
-    }
719
-
720
-    public function getPokemonCountsLastDay()
721
-    {
722
-        $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
672
+		$result = $this->mysqli->query($req);
673
+		$pokemon = array();
674
+		while ($data = $result->fetch_object()) {
675
+			$pokemon[] = $data;
676
+		}
677
+
678
+		return $pokemon;
679
+	}
680
+
681
+	public function getTrainerLevelCount($team_id)
682
+	{
683
+		$exclue = '';
684
+		if (!empty(self::$config->system->trainer_blacklist)) {
685
+			$exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')";
686
+		}
687
+		$req = "SELECT COUNT(*) AS count, level FROM (SELECT MAX(owner_level) as level FROM gym_defenders WHERE owner_level IS NOT NULL AND team = '".$team_id."' ".$exclue.' GROUP BY owner_level, owner_name) x GROUP BY level';
688
+		$result = $this->mysqli->query($req);
689
+		$levelData = array();
690
+		while ($data = $result->fetch_object()) {
691
+			$levelData[$data->level] = $data->count;
692
+		}
693
+		for ($i = 5; $i <= 40; ++$i) {
694
+			if (!isset($levelData[$i])) {
695
+				$levelData[$i] = 0;
696
+			}
697
+		}
698
+		// sort array again
699
+		ksort($levelData);
700
+
701
+		return $levelData;
702
+	}
703
+
704
+	/////////
705
+	// Cron
706
+	/////////
707
+
708
+	public function getPokemonCountsActive()
709
+	{
710
+		$req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id';
711
+		$result = $this->mysqli->query($req);
712
+		$counts = array();
713
+		while ($data = $result->fetch_object()) {
714
+			$counts[$data->pokemon_id] = $data->total;
715
+		}
716
+
717
+		return $counts;
718
+	}
719
+
720
+	public function getPokemonCountsLastDay()
721
+	{
722
+		$req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day
723 723
 					FROM sightings
724 724
 					WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings)
725 725
 					GROUP BY pokemon_id
726 726
 				  	ORDER BY pokemon_id ASC';
727
-        $result = $this->mysqli->query($req);
728
-        $counts = array();
729
-        while ($data = $result->fetch_object()) {
730
-            $counts[$data->pokemon_id] = $data->spawns_last_day;
731
-        }
732
-
733
-        return $counts;
734
-    }
735
-
736
-    public function getCaptchaCount()
737
-    {
738
-        $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL';
739
-        $result = $this->mysqli->query($req);
740
-        $data = $result->fetch_object();
741
-
742
-        return $data;
743
-    }
744
-
745
-    public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
746
-    {
747
-        $pokemon_exclude_sql = '';
748
-        if (!empty(self::$config->system->nest_exclude_pokemon)) {
749
-            $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
750
-        }
751
-        $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
727
+		$result = $this->mysqli->query($req);
728
+		$counts = array();
729
+		while ($data = $result->fetch_object()) {
730
+			$counts[$data->pokemon_id] = $data->spawns_last_day;
731
+		}
732
+
733
+		return $counts;
734
+	}
735
+
736
+	public function getCaptchaCount()
737
+	{
738
+		$req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL';
739
+		$result = $this->mysqli->query($req);
740
+		$data = $result->fetch_object();
741
+
742
+		return $data;
743
+	}
744
+
745
+	public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
746
+	{
747
+		$pokemon_exclude_sql = '';
748
+		if (!empty(self::$config->system->nest_exclude_pokemon)) {
749
+			$pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')';
750
+		}
751
+		$req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(s.updated) as latest_seen, coalesce(CASE WHEN MAX(duration) = 0 THEN NULL ELSE MAX(duration) END ,30)*60 as duration
752 752
 			          FROM sightings p
753 753
 			          INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id)
754 754
 			          WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).'
@@ -757,23 +757,23 @@  discard block
 block discarded – undo
757 757
 			          GROUP BY p.spawn_id, p.pokemon_id
758 758
 			          HAVING COUNT(p.pokemon_id) >= '.($time / 4).'
759 759
 			          ORDER BY p.pokemon_id';
760
-        $result = $this->mysqli->query($req);
761
-        $nests = array();
762
-        while ($data = $result->fetch_object()) {
763
-            $nests[] = $data;
764
-        }
765
-
766
-        return $nests;
767
-    }
768
-
769
-    public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
770
-    {
771
-        $req = 'SELECT COUNT(*) as total 
760
+		$result = $this->mysqli->query($req);
761
+		$nests = array();
762
+		while ($data = $result->fetch_object()) {
763
+			$nests[] = $data;
764
+		}
765
+
766
+		return $nests;
767
+	}
768
+
769
+	public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)
770
+	{
771
+		$req = 'SELECT COUNT(*) as total 
772 772
 					FROM spawnpoints 
773 773
  					WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude;
774
-        $result = $this->mysqli->query($req);
775
-        $data = $result->fetch_object();
774
+		$result = $this->mysqli->query($req);
775
+		$data = $result->fetch_object();
776 776
 
777
-        return $data;
778
-    }
777
+		return $data;
778
+	}
779 779
 }
Please login to merge, or discard this patch.