Failed Conditions
Pull Request — master (#374)
by
unknown
01:56
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   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -10,70 +10,70 @@  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
 function time_ago_day($timestamp, $locales) {
64
-    $spawn = new DateTime($timestamp);
65
-    $now = new DateTime();
66
-
67
-    $days = $now->diff($spawn)->format("%a");
68
-    if ($days == 0) {
69
-        return $locales->TODAY;
70
-    } elseif ($days == 1) {
71
-        return $locales->YESTERDAY;
72
-    } else {
73
-        return sprintf($locales->TIME_AGO, $days.' '.$locales->DAYS);
74
-    }
75
-
76
-    return $days;
64
+	$spawn = new DateTime($timestamp);
65
+	$now = new DateTime();
66
+
67
+	$days = $now->diff($spawn)->format("%a");
68
+	if ($days == 0) {
69
+		return $locales->TODAY;
70
+	} elseif ($days == 1) {
71
+		return $locales->YESTERDAY;
72
+	} else {
73
+		return sprintf($locales->TIME_AGO, $days.' '.$locales->DAYS);
74
+	}
75
+
76
+	return $days;
77 77
 }
78 78
 
79 79
 //#######################################################################
@@ -86,12 +86,12 @@  discard block
 block discarded – undo
86 86
 
87 87
 function percent($val, $val_total)
88 88
 {
89
-    $count1 = $val_total / $val;
90
-    $count2 = $count1 * 100;
89
+	$count1 = $val_total / $val;
90
+	$count2 = $count1 * 100;
91 91
 
92
-    $count = number_format($count2, 0);
92
+	$count = number_format($count2, 0);
93 93
 
94
-    return $count;
94
+	return $count;
95 95
 }
96 96
 
97 97
 //#######################################################################
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 
104 104
 function auto_ver($url)
105 105
 {
106
-    if (is_file(SYS_PATH.'/'.$url)) {
107
-        $path = pathinfo($url);
108
-        $ver = '.'.filemtime(SYS_PATH.'/'.$url).'.';
109
-        echo $path['dirname'].'/'.preg_replace('/\.(css|js|json)$/', $ver.'$1', $path['basename']);
110
-    } else {
111
-        echo $url;
112
-    }
106
+	if (is_file(SYS_PATH.'/'.$url)) {
107
+		$path = pathinfo($url);
108
+		$ver = '.'.filemtime(SYS_PATH.'/'.$url).'.';
109
+		echo $path['dirname'].'/'.preg_replace('/\.(css|js|json)$/', $ver.'$1', $path['basename']);
110
+	} else {
111
+		echo $url;
112
+	}
113 113
 }
114 114
 
115 115
 //#######################################################################
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 
122 122
 function file_update_ago($filepath)
123 123
 {
124
-    if (is_file($filepath)) {
125
-        $filemtime = filemtime($filepath);
126
-        $now = time();
127
-        $diff = $now - $filemtime;
128
-
129
-        return $diff;
130
-    }
131
-    // file doesn't exist yet!
132
-    return PHP_INT_MAX;
124
+	if (is_file($filepath)) {
125
+		$filemtime = filemtime($filepath);
126
+		$now = time();
127
+		$diff = $now - $filemtime;
128
+
129
+		return $diff;
130
+	}
131
+	// file doesn't exist yet!
132
+	return PHP_INT_MAX;
133 133
 }
134 134
 
135 135
 //#######################################################################
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 
143 143
 function trim_stats_json($array, $timestamp)
144 144
 {
145
-    foreach ($array as $key => $value) {
146
-        if ($value['timestamp'] < $timestamp) {
147
-            unset($array[$key]);
148
-        }
149
-    }
145
+	foreach ($array as $key => $value) {
146
+		if ($value['timestamp'] < $timestamp) {
147
+			unset($array[$key]);
148
+		}
149
+	}
150 150
 
151
-    return $array;
151
+	return $array;
152 152
 }
153 153
 
154 154
 //#######################################################################
@@ -160,31 +160,31 @@  discard block
 block discarded – undo
160 160
 
161 161
 function gym_level($prestige)
162 162
 {
163
-    if (0 == $prestige) {
164
-        $gym_level = 0;
165
-    } elseif ($prestige < 2000) {
166
-        $gym_level = 1;
167
-    } elseif ($prestige < 4000) {
168
-        $gym_level = 2;
169
-    } elseif ($prestige < 8000) {
170
-        $gym_level = 3;
171
-    } elseif ($prestige < 12000) {
172
-        $gym_level = 4;
173
-    } elseif ($prestige < 16000) {
174
-        $gym_level = 5;
175
-    } elseif ($prestige < 20000) {
176
-        $gym_level = 6;
177
-    } elseif ($prestige < 30000) {
178
-        $gym_level = 7;
179
-    } elseif ($prestige < 40000) {
180
-        $gym_level = 8;
181
-    } elseif ($prestige < 50000) {
182
-        $gym_level = 9;
183
-    } else {
184
-        $gym_level = 10;
185
-    }
186
-
187
-    return $gym_level;
163
+	if (0 == $prestige) {
164
+		$gym_level = 0;
165
+	} elseif ($prestige < 2000) {
166
+		$gym_level = 1;
167
+	} elseif ($prestige < 4000) {
168
+		$gym_level = 2;
169
+	} elseif ($prestige < 8000) {
170
+		$gym_level = 3;
171
+	} elseif ($prestige < 12000) {
172
+		$gym_level = 4;
173
+	} elseif ($prestige < 16000) {
174
+		$gym_level = 5;
175
+	} elseif ($prestige < 20000) {
176
+		$gym_level = 6;
177
+	} elseif ($prestige < 30000) {
178
+		$gym_level = 7;
179
+	} elseif ($prestige < 40000) {
180
+		$gym_level = 8;
181
+	} elseif ($prestige < 50000) {
182
+		$gym_level = 9;
183
+	} else {
184
+		$gym_level = 10;
185
+	}
186
+
187
+	return $gym_level;
188 188
 }
189 189
 
190 190
 //#######################################################################
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 //#######################################################################
196 196
 function get_depth($arr)
197 197
 {
198
-    $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
199
-    $depth = 0;
200
-    foreach ($it as $v) {
201
-        $it->getDepth() > $depth && $depth = $it->getDepth();
202
-    }
198
+	$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
199
+	$depth = 0;
200
+	foreach ($it as $v) {
201
+		$it->getDepth() > $depth && $depth = $it->getDepth();
202
+	}
203 203
 
204
-    return $depth;
204
+	return $depth;
205 205
 }
206 206
 
207 207
 //#######################################################################
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
 //#######################################################################
216 216
 function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0)
217 217
 {
218
-    if ($depth == $currentDepth) { // Found depth
219
-        return tree_remove_bellow($trees, $max_pokemon);
220
-    } else { // Go deeper
221
-        $arr = array();
222
-        foreach ($trees as $temp) { // Go into all trees
223
-            $tree = $temp->evolutions;
224
-            $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
225
-            $arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
226
-        }
227
-
228
-        return $arr;
229
-    }
218
+	if ($depth == $currentDepth) { // Found depth
219
+		return tree_remove_bellow($trees, $max_pokemon);
220
+	} else { // Go deeper
221
+		$arr = array();
222
+		foreach ($trees as $temp) { // Go into all trees
223
+			$tree = $temp->evolutions;
224
+			$results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
225
+			$arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
226
+		}
227
+
228
+		return $arr;
229
+	}
230 230
 }
231 231
 
232 232
 //#######################################################################
@@ -234,28 +234,28 @@  discard block
 block discarded – undo
234 234
 //#######################################################################
235 235
 function tree_check_array($array_check, $array_add, $correct_arrow)
236 236
 {
237
-    $count = count($array_check);
238
-    $i = 0;
239
-    if (!is_null($array_check)) { // check if exists
240
-        foreach ($array_check as $res) { // Check if above, equal or bellow center
241
-            if (1 != $count && $correct_arrow) { // only add arrow once
242
-                $num = $i / ($count - 1);
243
-                if ($num < 0.5) {
244
-                    $res->array_sufix = '_up';
245
-                } elseif ($num > 0.5) {
246
-                    $res->array_sufix = '_down';
247
-                } else {
248
-                    $res->array_sufix = '';
249
-                }
250
-            } elseif (!isset($res->array_sufix)) {
251
-                $res->array_sufix = '';
252
-            }
253
-            $array_add[] = $res;
254
-            ++$i;
255
-        }
256
-    }
257
-
258
-    return $array_add;
237
+	$count = count($array_check);
238
+	$i = 0;
239
+	if (!is_null($array_check)) { // check if exists
240
+		foreach ($array_check as $res) { // Check if above, equal or bellow center
241
+			if (1 != $count && $correct_arrow) { // only add arrow once
242
+				$num = $i / ($count - 1);
243
+				if ($num < 0.5) {
244
+					$res->array_sufix = '_up';
245
+				} elseif ($num > 0.5) {
246
+					$res->array_sufix = '_down';
247
+				} else {
248
+					$res->array_sufix = '';
249
+				}
250
+			} elseif (!isset($res->array_sufix)) {
251
+				$res->array_sufix = '';
252
+			}
253
+			$array_add[] = $res;
254
+			++$i;
255
+		}
256
+	}
257
+
258
+	return $array_add;
259 259
 }
260 260
 
261 261
 //#######################################################################
@@ -263,17 +263,17 @@  discard block
 block discarded – undo
263 263
 //#######################################################################
264 264
 function tree_remove_bellow($tree, $max_pokemon)
265 265
 {
266
-    if (is_null($tree)) {
267
-        return null;
268
-    }
269
-    $arr = array();
270
-    foreach ($tree as $item) { // Check if above, equal or bellow center
271
-        if ($item->id <= $max_pokemon) {
272
-            $arr[] = $item;
273
-        }
274
-    }
275
-
276
-    return $arr;
266
+	if (is_null($tree)) {
267
+		return null;
268
+	}
269
+	$arr = array();
270
+	foreach ($tree as $item) { // Check if above, equal or bellow center
271
+		if ($item->id <= $max_pokemon) {
272
+			$arr[] = $item;
273
+		}
274
+	}
275
+
276
+	return $arr;
277 277
 }
278 278
 
279 279
 //#######################################################################
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
 //#######################################################################
282 282
 function generation($id)
283 283
 {
284
-    switch ($id) {
285
-        case $id >= 1 && $id <= 151:
286
-            return [1, 'Kanto'];
287
-        case $id >= 152 && $id <= 251:
288
-            return [2, 'Johto'];
289
-        case $id >= 252 && $id <= 386:
290
-            return [3, 'Hoenn'];
291
-        case $id >= 387 && $id <= 493:
292
-            return [4, 'Sinnoh'];
293
-        case $id >= 494 && $id <= 649:
294
-            return [5, 'Teselia'];
295
-        case $id >= 650 && $id <= 721:
296
-            return [6, 'Kalos'];
297
-        case $id >= 722 && $id <= 802:
298
-            return [7, 'Alola'];
299
-    }
284
+	switch ($id) {
285
+		case $id >= 1 && $id <= 151:
286
+			return [1, 'Kanto'];
287
+		case $id >= 152 && $id <= 251:
288
+			return [2, 'Johto'];
289
+		case $id >= 252 && $id <= 386:
290
+			return [3, 'Hoenn'];
291
+		case $id >= 387 && $id <= 493:
292
+			return [4, 'Sinnoh'];
293
+		case $id >= 494 && $id <= 649:
294
+			return [5, 'Teselia'];
295
+		case $id >= 650 && $id <= 721:
296
+			return [6, 'Kalos'];
297
+		case $id >= 722 && $id <= 802:
298
+			return [7, 'Alola'];
299
+	}
300 300
 }
301 301
 
302 302
 //#######################################################################
@@ -304,34 +304,34 @@  discard block
 block discarded – undo
304 304
 //#######################################################################
305 305
 function pointIsInsidePolygon($lat, $lng, $geos, $bounds)
306 306
 {
307
-    if ($lat >= $bounds['minlat'] && $lat <= $bounds['maxlat'] && $lng >= $bounds['minlon'] && $lng <= $bounds['maxlon']) {
308
-        $intersections = 0;
309
-        $geos_count = count($geos);
310
-
311
-        for ($i = 1; $i < $geos_count; ++$i) {
312
-            $geo1 = $geos[$i - 1];
313
-            $geo2 = $geos[$i];
314
-            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
315
-                return true;
316
-            }
317
-            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
318
-                return true;
319
-            }
320
-            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']) {
321
-                $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
322
-                if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
323
-                    return true;
324
-                }
325
-                if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
326
-                    ++$intersections;
327
-                }
328
-            }
329
-        }
330
-        // If the number of edges we passed through is odd, then it's in the polygon.
331
-        return 0 != $intersections % 2;
332
-    } else {
333
-        return false; // outside bounds
334
-    }
307
+	if ($lat >= $bounds['minlat'] && $lat <= $bounds['maxlat'] && $lng >= $bounds['minlon'] && $lng <= $bounds['maxlon']) {
308
+		$intersections = 0;
309
+		$geos_count = count($geos);
310
+
311
+		for ($i = 1; $i < $geos_count; ++$i) {
312
+			$geo1 = $geos[$i - 1];
313
+			$geo2 = $geos[$i];
314
+			if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
315
+				return true;
316
+			}
317
+			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
318
+				return true;
319
+			}
320
+			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']) {
321
+				$xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
322
+				if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
323
+					return true;
324
+				}
325
+				if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
326
+					++$intersections;
327
+				}
328
+			}
329
+		}
330
+		// If the number of edges we passed through is odd, then it's in the polygon.
331
+		return 0 != $intersections % 2;
332
+	} else {
333
+		return false; // outside bounds
334
+	}
335 335
 }
336 336
 
337 337
 //#######################################################################
@@ -339,18 +339,18 @@  discard block
 block discarded – undo
339 339
 //#######################################################################
340 340
 function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut)
341 341
 {
342
-    if ($boundsIn['minlat'] >= $boundsOut['minlat'] && $boundsIn['maxlat'] <= $boundsOut['maxlat'] && $boundsIn['minlon'] >= $boundsOut['minlon'] && $boundsIn['maxlon'] <= $boundsOut['maxlon']) {
343
-        $insideCount = 0;
344
-        foreach ($geoIn as $coord) {
345
-            if (pointIsInsidePolygon($coord['lat'], $coord['lng'], $geoOut, $boundsOut)) {
346
-                ++$insideCount;
347
-            }
348
-        }
349
-
350
-        return $insideCount / count($geoIn) >= 0.95;
351
-    } else {
352
-        return false; // bounds outside
353
-    }
342
+	if ($boundsIn['minlat'] >= $boundsOut['minlat'] && $boundsIn['maxlat'] <= $boundsOut['maxlat'] && $boundsIn['minlon'] >= $boundsOut['minlon'] && $boundsIn['maxlon'] <= $boundsOut['maxlon']) {
343
+		$insideCount = 0;
344
+		foreach ($geoIn as $coord) {
345
+			if (pointIsInsidePolygon($coord['lat'], $coord['lng'], $geoOut, $boundsOut)) {
346
+				++$insideCount;
347
+			}
348
+		}
349
+
350
+		return $insideCount / count($geoIn) >= 0.95;
351
+	} else {
352
+		return false; // bounds outside
353
+	}
354 354
 }
355 355
 
356 356
 //#######################################################################
@@ -358,45 +358,45 @@  discard block
 block discarded – undo
358 358
 //#######################################################################
359 359
 function combineOuter($outers)
360 360
 {
361
-    $polygons = array();
362
-    $index = 0;
363
-    $count = 0;
364
-    $maxCount = count($outers);
365
-    while (0 != count($outers) && $count <= $maxCount) {
366
-        ++$count;
367
-        foreach ($outers as $key => $outer) {
368
-            if (!isset($polygons[$index])) {
369
-                $polygons[$index] = $outer;
370
-                unset($outers[$key]);
371
-            } else {
372
-                $firstEle = $outer[0];
373
-                $lastEle = $outer[count($outer) - 1];
374
-                $firstElePoly = $polygons[$index][0];
375
-                $lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
376
-                if ($firstEle == $lastElePoly) {
377
-                    $polygons[$index] = array_merge($polygons[$index], $outer);
378
-                    unset($outers[$key]);
379
-                } elseif ($lastEle == $lastElePoly) {
380
-                    $polygons[$index] = array_merge($polygons[$index], array_reverse($outer));
381
-                    unset($outers[$key]);
382
-                } elseif ($firstEle == $firstElePoly) {
383
-                    $polygons[$index] = array_merge(array_reverse($outer), $polygons[$index]);
384
-                    unset($outers[$key]);
385
-                } elseif ($lastEle == $firstElePoly) {
386
-                    $polygons[$index] = array_merge($outer, $polygons[$index]);
387
-                    unset($outers[$key]);
388
-                }
389
-            }
390
-
391
-            $firstElePoly = $polygons[$index][0];
392
-            $lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
393
-            if ($firstElePoly == $lastElePoly) {
394
-                ++$index;
395
-            }
396
-        }
397
-    }
398
-
399
-    return $polygons;
361
+	$polygons = array();
362
+	$index = 0;
363
+	$count = 0;
364
+	$maxCount = count($outers);
365
+	while (0 != count($outers) && $count <= $maxCount) {
366
+		++$count;
367
+		foreach ($outers as $key => $outer) {
368
+			if (!isset($polygons[$index])) {
369
+				$polygons[$index] = $outer;
370
+				unset($outers[$key]);
371
+			} else {
372
+				$firstEle = $outer[0];
373
+				$lastEle = $outer[count($outer) - 1];
374
+				$firstElePoly = $polygons[$index][0];
375
+				$lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
376
+				if ($firstEle == $lastElePoly) {
377
+					$polygons[$index] = array_merge($polygons[$index], $outer);
378
+					unset($outers[$key]);
379
+				} elseif ($lastEle == $lastElePoly) {
380
+					$polygons[$index] = array_merge($polygons[$index], array_reverse($outer));
381
+					unset($outers[$key]);
382
+				} elseif ($firstEle == $firstElePoly) {
383
+					$polygons[$index] = array_merge(array_reverse($outer), $polygons[$index]);
384
+					unset($outers[$key]);
385
+				} elseif ($lastEle == $firstElePoly) {
386
+					$polygons[$index] = array_merge($outer, $polygons[$index]);
387
+					unset($outers[$key]);
388
+				}
389
+			}
390
+
391
+			$firstElePoly = $polygons[$index][0];
392
+			$lastElePoly = $polygons[$index][count($polygons[$index]) - 1];
393
+			if ($firstElePoly == $lastElePoly) {
394
+				++$index;
395
+			}
396
+		}
397
+	}
398
+
399
+	return $polygons;
400 400
 }
401 401
 
402 402
 //#######################################################################
@@ -404,63 +404,63 @@  discard block
 block discarded – undo
404 404
 //#######################################################################
405 405
 function printMenuitems($menu, $level, $locales)
406 406
 {
407
-    if (isset($menu->locale)) {
408
-        $locale = $menu->locale;
409
-        $text = $locales->$locale;
410
-    } elseif (isset($menu->text)) {
411
-        $text = $menu->text;
412
-    } else {
413
-        $text = '';
414
-    }
415
-
416
-    switch ($menu->type) {
417
-        case 'group':
418
-            ?>
407
+	if (isset($menu->locale)) {
408
+		$locale = $menu->locale;
409
+		$text = $locales->$locale;
410
+	} elseif (isset($menu->text)) {
411
+		$text = $menu->text;
412
+	} else {
413
+		$text = '';
414
+	}
415
+
416
+	switch ($menu->type) {
417
+		case 'group':
418
+			?>
419 419
 			
420 420
 			<li>
421 421
 			<a class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $text; ?></a>
422 422
 			<ul class="dropdown">
423 423
 			
424 424
 			<?php
425
-            foreach ($menu->members as $childmenu) {
426
-                printMenuitems($childmenu, $level + 1, $locales);
427
-            }
428
-            ?>
425
+			foreach ($menu->members as $childmenu) {
426
+				printMenuitems($childmenu, $level + 1, $locales);
427
+			}
428
+			?>
429 429
 			
430 430
 			</ul>
431 431
 			</li>
432 432
 
433 433
 			<?php
434
-            break;
434
+			break;
435 435
 
436
-        case 'link':
437
-            ?>
436
+		case 'link':
437
+			?>
438 438
 
439 439
 			<li>
440 440
 				<a href="<?= $menu->href; ?>" class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $text; ?></a>
441 441
 			</li>
442 442
 
443 443
 			<?php
444
-            break;
444
+			break;
445 445
 
446
-        case 'link_external':
447
-            ?>
446
+		case 'link_external':
447
+			?>
448 448
 
449 449
 			<li>
450 450
 				<a href="<?= $menu->href; ?>" target="_blank" class="menu-label"><i class="fa <?= $menu->icon; ?>" aria-hidden="true"></i> <?= $menu->text; ?></a>
451 451
 			</li>
452 452
 
453 453
 			<?php
454
-            break;
454
+			break;
455 455
 
456
-        case 'html':
457
-            ?>
456
+		case 'html':
457
+			?>
458 458
 
459 459
 			<li> <?= $menu->value; ?> </li>
460 460
 
461 461
 			<?php
462
-            break;
463
-    }
462
+			break;
463
+	}
464 464
 }
465 465
 
466 466
 ?>
Please login to merge, or discard this patch.
Braces   +22 added lines, -11 removed lines patch added patch discarded remove patch
@@ -60,7 +60,8 @@  discard block
 block discarded – undo
60 60
     }
61 61
 }
62 62
 
63
-function time_ago_day($timestamp, $locales) {
63
+function time_ago_day($timestamp, $locales)
64
+{
64 65
     $spawn = new DateTime($timestamp);
65 66
     $now = new DateTime();
66 67
 
@@ -215,11 +216,14 @@  discard block
 block discarded – undo
215 216
 //#######################################################################
216 217
 function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0)
217 218
 {
218
-    if ($depth == $currentDepth) { // Found depth
219
+    if ($depth == $currentDepth) {
220
+// Found depth
219 221
         return tree_remove_bellow($trees, $max_pokemon);
220
-    } else { // Go deeper
222
+    } else {
223
+// Go deeper
221 224
         $arr = array();
222
-        foreach ($trees as $temp) { // Go into all trees
225
+        foreach ($trees as $temp) {
226
+// Go into all trees
223 227
             $tree = $temp->evolutions;
224 228
             $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon);
225 229
             $arr = tree_check_array($results, $arr, 1 == $depth - $currentDepth);
@@ -236,9 +240,12 @@  discard block
 block discarded – undo
236 240
 {
237 241
     $count = count($array_check);
238 242
     $i = 0;
239
-    if (!is_null($array_check)) { // check if exists
240
-        foreach ($array_check as $res) { // Check if above, equal or bellow center
241
-            if (1 != $count && $correct_arrow) { // only add arrow once
243
+    if (!is_null($array_check)) {
244
+// check if exists
245
+        foreach ($array_check as $res) {
246
+// Check if above, equal or bellow center
247
+            if (1 != $count && $correct_arrow) {
248
+// only add arrow once
242 249
                 $num = $i / ($count - 1);
243 250
                 if ($num < 0.5) {
244 251
                     $res->array_sufix = '_up';
@@ -267,7 +274,8 @@  discard block
 block discarded – undo
267 274
         return null;
268 275
     }
269 276
     $arr = array();
270
-    foreach ($tree as $item) { // Check if above, equal or bellow center
277
+    foreach ($tree as $item) {
278
+// Check if above, equal or bellow center
271 279
         if ($item->id <= $max_pokemon) {
272 280
             $arr[] = $item;
273 281
         }
@@ -311,15 +319,18 @@  discard block
 block discarded – undo
311 319
         for ($i = 1; $i < $geos_count; ++$i) {
312 320
             $geo1 = $geos[$i - 1];
313 321
             $geo2 = $geos[$i];
314
-            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords
322
+            if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) {
323
+// On one of the coords
315 324
                 return true;
316 325
             }
317
-            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
326
+            if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) {
327
+// Check if point is on an horizontal polygon boundary
318 328
                 return true;
319 329
             }
320 330
             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']) {
321 331
                 $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat'];
322
-                if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal)
332
+                if ($xinters == $lat) {
333
+// Check if point is on the polygon boundary (other than horizontal)
323 334
                     return true;
324 335
                 }
325 336
                 if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) {
Please login to merge, or discard this patch.
core/process/timezone.loader.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 
6 6
 // Include and load variables if not set
7 7
 if (!isset($config)) {
8
-    $variables = realpath(dirname(__FILE__)).'/../json/variables.json';
9
-    $config = json_decode(file_get_contents($variables));
8
+	$variables = realpath(dirname(__FILE__)).'/../json/variables.json';
9
+	$config = json_decode(file_get_contents($variables));
10 10
 }
11 11
 
12 12
 // Set default timezone
Please login to merge, or discard this patch.
core/process/locales.loader.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * @return array Sorted list of "accept" options
27 27
  */
28
-$sortAccept = function ($header) {
28
+$sortAccept = function($header) {
29 29
     $matches = array();
30 30
     foreach (explode(',', $header) as $option) {
31 31
         $option = array_map('trim', explode(';', $option));
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
  *
60 60
  * @return string|null a matched option, or NULL if no match
61 61
  */
62
-$matchAccept = function ($header, $supported) use ($sortAccept) {
62
+$matchAccept = function($header, $supported) use ($sortAccept) {
63 63
     $matches = $sortAccept($header);
64 64
     foreach ($matches as $key => $q) {
65 65
         if (isset($supported[$key])) {
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
  *
92 92
  * @return string the negotiated language result or the supplied default
93 93
  */
94
-$negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept) {
94
+$negotiateLanguage = function($supported, $default = 'en-US') use ($matchAccept) {
95 95
     $supp = array();
96 96
     foreach ($supported as $lang => $isSupported) {
97 97
         if ($isSupported) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,8 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * @return array Sorted list of "accept" options
27 27
  */
28
-$sortAccept = function ($header) {
28
+$sortAccept = function ($header)
29
+{
29 30
     $matches = array();
30 31
     foreach (explode(',', $header) as $option) {
31 32
         $option = array_map('trim', explode(';', $option));
@@ -59,7 +60,8 @@  discard block
 block discarded – undo
59 60
  *
60 61
  * @return string|null a matched option, or NULL if no match
61 62
  */
62
-$matchAccept = function ($header, $supported) use ($sortAccept) {
63
+$matchAccept = function ($header, $supported) use ($sortAccept)
64
+{
63 65
     $matches = $sortAccept($header);
64 66
     foreach ($matches as $key => $q) {
65 67
         if (isset($supported[$key])) {
@@ -91,7 +93,8 @@  discard block
 block discarded – undo
91 93
  *
92 94
  * @return string the negotiated language result or the supplied default
93 95
  */
94
-$negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept) {
96
+$negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept)
97
+{
95 98
     $supp = array();
96 99
     foreach ($supported as $lang => $isSupported) {
97 100
         if ($isSupported) {
Please login to merge, or discard this patch.
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -26,28 +26,28 @@  discard block
 block discarded – undo
26 26
  * @return array Sorted list of "accept" options
27 27
  */
28 28
 $sortAccept = function ($header) {
29
-    $matches = array();
30
-    foreach (explode(',', $header) as $option) {
31
-        $option = array_map('trim', explode(';', $option));
32
-        $l = strtolower($option[0]);
33
-        if (isset($option[1])) {
34
-            $q = (float) str_replace('q=', '', $option[1]);
35
-        } else {
36
-            $q = null;
37
-            // Assign default low weight for generic values
38
-            if ('*/*' == $l) {
39
-                $q = 0.01;
40
-            } elseif ('*' == substr($l, -1)) {
41
-                $q = 0.02;
42
-            }
43
-        }
44
-        // Unweighted values, get high weight by their position in the
45
-        // list
46
-        $matches[$l] = isset($q) ? $q : 1000 - count($matches);
47
-    }
48
-    arsort($matches, SORT_NUMERIC);
49
-
50
-    return $matches;
29
+	$matches = array();
30
+	foreach (explode(',', $header) as $option) {
31
+		$option = array_map('trim', explode(';', $option));
32
+		$l = strtolower($option[0]);
33
+		if (isset($option[1])) {
34
+			$q = (float) str_replace('q=', '', $option[1]);
35
+		} else {
36
+			$q = null;
37
+			// Assign default low weight for generic values
38
+			if ('*/*' == $l) {
39
+				$q = 0.01;
40
+			} elseif ('*' == substr($l, -1)) {
41
+				$q = 0.02;
42
+			}
43
+		}
44
+		// Unweighted values, get high weight by their position in the
45
+		// list
46
+		$matches[$l] = isset($q) ? $q : 1000 - count($matches);
47
+	}
48
+	arsort($matches, SORT_NUMERIC);
49
+
50
+	return $matches;
51 51
 };
52 52
 
53 53
 /**
@@ -60,18 +60,18 @@  discard block
 block discarded – undo
60 60
  * @return string|null a matched option, or NULL if no match
61 61
  */
62 62
 $matchAccept = function ($header, $supported) use ($sortAccept) {
63
-    $matches = $sortAccept($header);
64
-    foreach ($matches as $key => $q) {
65
-        if (isset($supported[$key])) {
66
-            return $supported[$key];
67
-        }
68
-    }
69
-    // If any (i.e. "*") is acceptable, return the first supported format
70
-    if (isset($matches['*'])) {
71
-        return array_shift($supported);
72
-    }
73
-
74
-    return null;
63
+	$matches = $sortAccept($header);
64
+	foreach ($matches as $key => $q) {
65
+		if (isset($supported[$key])) {
66
+			return $supported[$key];
67
+		}
68
+	}
69
+	// If any (i.e. "*") is acceptable, return the first supported format
70
+	if (isset($matches['*'])) {
71
+		return array_shift($supported);
72
+	}
73
+
74
+	return null;
75 75
 };
76 76
 
77 77
 /**
@@ -92,46 +92,46 @@  discard block
 block discarded – undo
92 92
  * @return string the negotiated language result or the supplied default
93 93
  */
94 94
 $negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept) {
95
-    $supp = array();
96
-    foreach ($supported as $lang => $isSupported) {
97
-        if ($isSupported) {
98
-            $supp[strtolower($lang)] = $lang;
99
-        }
100
-    }
101
-    if (!count($supp)) {
102
-        return $default;
103
-    }
104
-    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
105
-        $match = $matchAccept(
106
-            $_SERVER['HTTP_ACCEPT_LANGUAGE'],
107
-            $supp
108
-        );
109
-        if (!is_null($match)) {
110
-            return $match;
111
-        }
112
-    }
113
-    if (isset($_SERVER['REMOTE_HOST'])) {
114
-        $domain = explode('.', $_SERVER['REMOTE_HOST']);
115
-        $lang = strtolower(end($domain));
116
-        if (isset($supp[$lang])) {
117
-            return $supp[$lang];
118
-        }
119
-    }
120
-
121
-    return $default;
95
+	$supp = array();
96
+	foreach ($supported as $lang => $isSupported) {
97
+		if ($isSupported) {
98
+			$supp[strtolower($lang)] = $lang;
99
+		}
100
+	}
101
+	if (!count($supp)) {
102
+		return $default;
103
+	}
104
+	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
105
+		$match = $matchAccept(
106
+			$_SERVER['HTTP_ACCEPT_LANGUAGE'],
107
+			$supp
108
+		);
109
+		if (!is_null($match)) {
110
+			return $match;
111
+		}
112
+	}
113
+	if (isset($_SERVER['REMOTE_HOST'])) {
114
+		$domain = explode('.', $_SERVER['REMOTE_HOST']);
115
+		$lang = strtolower(end($domain));
116
+		if (isset($supp[$lang])) {
117
+			return $supp[$lang];
118
+		}
119
+	}
120
+
121
+	return $default;
122 122
 };
123 123
 
124 124
 // Language setting
125 125
 //##################
126 126
 if (empty($config->system->forced_lang)) {
127
-    $directories = glob(SYS_PATH.'/core/json/locales/*', GLOB_ONLYDIR);
128
-    $directories = array_map('basename', $directories);
129
-    //print_r($directories);
130
-    $browser_lang = $negotiateLanguage(array_fill_keys($directories, true), $config->system->default_lang);
127
+	$directories = glob(SYS_PATH.'/core/json/locales/*', GLOB_ONLYDIR);
128
+	$directories = array_map('basename', $directories);
129
+	//print_r($directories);
130
+	$browser_lang = $negotiateLanguage(array_fill_keys($directories, true), $config->system->default_lang);
131 131
 //print_r($browser_lang);
132 132
 } else {
133
-    // Use forced language
134
-    $browser_lang = $config->system->forced_lang;
133
+	// Use forced language
134
+	$browser_lang = $config->system->forced_lang;
135 135
 }
136 136
 
137 137
 // Activate lang
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
 $translation_file = '{}';
141 141
 $pokemon_file = '{}';
142 142
 if (is_file($locale_dir.'/pokes.json')) {
143
-    $pokemon_file = file_get_contents($locale_dir.'/pokes.json');
143
+	$pokemon_file = file_get_contents($locale_dir.'/pokes.json');
144 144
 }
145 145
 if (is_file($locale_dir.'/translations.json')) {
146
-    $translation_file = file_get_contents($locale_dir.'/translations.json');
146
+	$translation_file = file_get_contents($locale_dir.'/translations.json');
147 147
 }
148 148
 if (is_file($locale_dir.'/moves.json')) {
149
-    $moves_file = json_decode(file_get_contents($locale_dir.'/moves.json'));
149
+	$moves_file = json_decode(file_get_contents($locale_dir.'/moves.json'));
150 150
 } else {
151
-    $moves_file = json_decode(file_get_contents(SYS_PATH.'/core/json/locales/EN/moves.json'));
151
+	$moves_file = json_decode(file_get_contents(SYS_PATH.'/core/json/locales/EN/moves.json'));
152 152
 }
153 153
 
154 154
 // Merge translation files
@@ -181,125 +181,125 @@  discard block
 block discarded – undo
181 181
 $data = $manager->getPokemonCountAll();
182 182
 $pokemon_counts = array();
183 183
 foreach ($data as $pokemon) {
184
-    $pokemon_counts[$pokemon->pokemon_id] = $pokemon;
184
+	$pokemon_counts[$pokemon->pokemon_id] = $pokemon;
185 185
 }
186 186
 
187 187
 $data = $manager->getRaidCountAll();
188 188
 $raid_counts = array();
189 189
 foreach ($data as $raid) {
190
-    $raid_counts[$raid->pokemon_id] = $raid;
190
+	$raid_counts[$raid->pokemon_id] = $raid;
191 191
 }
192 192
 
193 193
 $totalCountPoke = 0;
194 194
 $maxpid = $config->system->max_pokemon;
195 195
 for ($pokeid = 1; $pokeid <= $maxpid; ++$pokeid) {
196
-    if (!isset($pokemons_all->pokemon->$pokeid)) {
197
-        continue;
198
-    }
199
-    // Merge name and description from translation files
200
-    $pokemon = $pokemons_all->pokemon->$pokeid;
201
-    $pokemon->id = $pokeid;
202
-    $pokemon->name = $pokemon_trans->pokemon->$pokeid->name;
203
-    $pokemon->description = $pokemon_trans->pokemon->$pokeid->description;
204
-    $pokemon->img = 'core/pokemons/'.$pokeid.$config->system->pokeimg_suffix;
205
-
206
-    // Replace quick and charge move with translation
207
-    $quick_move = $pokemon->quick_move;
208
-    $pokemon->quick_move = $pokemon_trans->quick_moves->$quick_move;
209
-    $charge_move = $pokemon->charge_move;
210
-    $pokemon->charge_move = $pokemon_trans->charge_moves->$charge_move;
211
-
212
-    // Replace types with translation
213
-    foreach ($pokemon->types as &$type) {
214
-        $type = $pokemon_trans->types->$type;
215
-    }
216
-    unset($type);
217
-
218
-    // Convert move numbers to names
219
-    $move = new stdClass();
220
-    foreach ($moves_file as $move_id => $move_name) {
221
-        if (isset($move_name)) {
222
-            $move->$move_id = new stdClass();
223
-            $move->$move_id->name = $move_name->name;
224
-        }
225
-    }
226
-
227
-    // Add pokemon counts to array
228
-    if (array_key_exists($pokeid, $pokemon_counts)) {
229
-        $data = $pokemon_counts[$pokeid];
230
-        $pokemon->spawn_count = $data->count;
231
-        if (isset($data->last_seen)) {
232
-            $pokemon->last_seen = $data->last_seen;
233
-        } else {
234
-            $pokemon->last_seen = null;
235
-        }
236
-        if (isset($data->last_seen_day)) {
237
-            $pokemon->last_seen_day = $data->last_seen_day;
238
-        } else {
239
-            $pokemon->last_seen_day = null;
240
-        }
241
-        if (isset($data->latitude) && isset($data->longitude)) {
242
-            $pokemon->last_position = new stdClass();
243
-            $pokemon->last_position->latitude = $data->latitude;
244
-            $pokemon->last_position->longitude = $data->longitude;
245
-        }
246
-
247
-        $totalCountPoke += $data->count;
248
-    } else {
249
-        $pokemon->spawn_count = 0;
250
-        $pokemon->last_seen = null;
251
-        $pokemon->last_position = null;
252
-    }
253
-
254
-    // Add raid counts to array
255
-    if (array_key_exists($pokeid, $raid_counts)) {
256
-        $data = $raid_counts[$pokeid];
257
-        $pokemon->raid_count = $data->count;
258
-        if (isset($data->last_seen)) {
259
-            $pokemon->last_raid_seen = $data->last_seen;
260
-        } else {
261
-            $pokemon->last_raid_seen = null;
262
-        }
263
-        if (isset($data->last_seen_day)) {
264
-            $pokemon->last_raid_seen_day = $data->last_seen_day;
265
-        } else {
266
-            $pokemon->last_raid_seen_day = null;
267
-        }
268
-        if (isset($data->latitude) && isset($data->longitude)) {
269
-            $pokemon->last_raid_position = new stdClass();
270
-            $pokemon->last_raid_position->latitude = $data->latitude;
271
-            $pokemon->last_raid_position->longitude = $data->longitude;
272
-        }
273
-    } else {
274
-        $pokemon->raid_count = 0;
275
-        $pokemon->last_raid_seen = null;
276
-        $pokemon->last_raid_position = null;
277
-    }
278
-
279
-    // Calculate and add rarities to array
280
-    $spawn_rate = $pokemons_rarity->$pokeid->rate;
281
-    $pokemon->spawn_rate = $spawn_rate;
282
-    $pokemon->per_day = $pokemons_rarity->$pokeid->per_day;
283
-
284
-    // >= 1          = Very common
285
-    // 0.20 - 1      = Common
286
-    // 0.01 - 0.20   = Rare
287
-    // > 0  - 0.01   = Mythic
288
-    // Unseen
289
-    if ($spawn_rate >= 1) {
290
-        $pokemon->rarity = $locales->VERYCOMMON;
291
-    } elseif ($spawn_rate >= 0.20) {
292
-        $pokemon->rarity = $locales->COMMON;
293
-    } elseif ($spawn_rate >= 0.01) {
294
-        $pokemon->rarity = $locales->RARE;
295
-    } elseif ($spawn_rate > 0 || $pokemon->spawn_count > 0) {
296
-        // pokemon with at least 1 spawn in the past aren't unseen!
297
-        $pokemon->rarity = $locales->MYTHIC;
298
-    } else {
299
-        $pokemon->rarity = $locales->UNSEEN;
300
-    }
301
-
302
-    $pokemons->pokemon->$pokeid = $pokemon;
196
+	if (!isset($pokemons_all->pokemon->$pokeid)) {
197
+		continue;
198
+	}
199
+	// Merge name and description from translation files
200
+	$pokemon = $pokemons_all->pokemon->$pokeid;
201
+	$pokemon->id = $pokeid;
202
+	$pokemon->name = $pokemon_trans->pokemon->$pokeid->name;
203
+	$pokemon->description = $pokemon_trans->pokemon->$pokeid->description;
204
+	$pokemon->img = 'core/pokemons/'.$pokeid.$config->system->pokeimg_suffix;
205
+
206
+	// Replace quick and charge move with translation
207
+	$quick_move = $pokemon->quick_move;
208
+	$pokemon->quick_move = $pokemon_trans->quick_moves->$quick_move;
209
+	$charge_move = $pokemon->charge_move;
210
+	$pokemon->charge_move = $pokemon_trans->charge_moves->$charge_move;
211
+
212
+	// Replace types with translation
213
+	foreach ($pokemon->types as &$type) {
214
+		$type = $pokemon_trans->types->$type;
215
+	}
216
+	unset($type);
217
+
218
+	// Convert move numbers to names
219
+	$move = new stdClass();
220
+	foreach ($moves_file as $move_id => $move_name) {
221
+		if (isset($move_name)) {
222
+			$move->$move_id = new stdClass();
223
+			$move->$move_id->name = $move_name->name;
224
+		}
225
+	}
226
+
227
+	// Add pokemon counts to array
228
+	if (array_key_exists($pokeid, $pokemon_counts)) {
229
+		$data = $pokemon_counts[$pokeid];
230
+		$pokemon->spawn_count = $data->count;
231
+		if (isset($data->last_seen)) {
232
+			$pokemon->last_seen = $data->last_seen;
233
+		} else {
234
+			$pokemon->last_seen = null;
235
+		}
236
+		if (isset($data->last_seen_day)) {
237
+			$pokemon->last_seen_day = $data->last_seen_day;
238
+		} else {
239
+			$pokemon->last_seen_day = null;
240
+		}
241
+		if (isset($data->latitude) && isset($data->longitude)) {
242
+			$pokemon->last_position = new stdClass();
243
+			$pokemon->last_position->latitude = $data->latitude;
244
+			$pokemon->last_position->longitude = $data->longitude;
245
+		}
246
+
247
+		$totalCountPoke += $data->count;
248
+	} else {
249
+		$pokemon->spawn_count = 0;
250
+		$pokemon->last_seen = null;
251
+		$pokemon->last_position = null;
252
+	}
253
+
254
+	// Add raid counts to array
255
+	if (array_key_exists($pokeid, $raid_counts)) {
256
+		$data = $raid_counts[$pokeid];
257
+		$pokemon->raid_count = $data->count;
258
+		if (isset($data->last_seen)) {
259
+			$pokemon->last_raid_seen = $data->last_seen;
260
+		} else {
261
+			$pokemon->last_raid_seen = null;
262
+		}
263
+		if (isset($data->last_seen_day)) {
264
+			$pokemon->last_raid_seen_day = $data->last_seen_day;
265
+		} else {
266
+			$pokemon->last_raid_seen_day = null;
267
+		}
268
+		if (isset($data->latitude) && isset($data->longitude)) {
269
+			$pokemon->last_raid_position = new stdClass();
270
+			$pokemon->last_raid_position->latitude = $data->latitude;
271
+			$pokemon->last_raid_position->longitude = $data->longitude;
272
+		}
273
+	} else {
274
+		$pokemon->raid_count = 0;
275
+		$pokemon->last_raid_seen = null;
276
+		$pokemon->last_raid_position = null;
277
+	}
278
+
279
+	// Calculate and add rarities to array
280
+	$spawn_rate = $pokemons_rarity->$pokeid->rate;
281
+	$pokemon->spawn_rate = $spawn_rate;
282
+	$pokemon->per_day = $pokemons_rarity->$pokeid->per_day;
283
+
284
+	// >= 1          = Very common
285
+	// 0.20 - 1      = Common
286
+	// 0.01 - 0.20   = Rare
287
+	// > 0  - 0.01   = Mythic
288
+	// Unseen
289
+	if ($spawn_rate >= 1) {
290
+		$pokemon->rarity = $locales->VERYCOMMON;
291
+	} elseif ($spawn_rate >= 0.20) {
292
+		$pokemon->rarity = $locales->COMMON;
293
+	} elseif ($spawn_rate >= 0.01) {
294
+		$pokemon->rarity = $locales->RARE;
295
+	} elseif ($spawn_rate > 0 || $pokemon->spawn_count > 0) {
296
+		// pokemon with at least 1 spawn in the past aren't unseen!
297
+		$pokemon->rarity = $locales->MYTHIC;
298
+	} else {
299
+		$pokemon->rarity = $locales->UNSEEN;
300
+	}
301
+
302
+	$pokemons->pokemon->$pokeid = $pokemon;
303 303
 }
304 304
 
305 305
 $pokemons->total = $totalCountPoke;
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
 // Translate typecolors array keys as well
308 308
 $types_temp = new stdClass();
309 309
 foreach ($pokemons_all->typecolors as $type => $color) {
310
-    $type_trans = $pokemon_trans->types->$type;
311
-    $types_temp->$type_trans = $color;
310
+	$type_trans = $pokemon_trans->types->$type;
311
+	$types_temp->$type_trans = $color;
312 312
 }
313 313
 // Replace typecolors array with translated one
314 314
 $pokemons->typecolors = $types_temp;
Please login to merge, or discard this patch.
core/inc/meta.inc.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		<meta name="theme-color" content="#ffffff">
20 20
 
21 21
 <?php if (!isset($_GET['page'])) {
22
-    ?>
22
+	?>
23 23
 
24 24
 		<title><?= $config->infos->site_name; ?> | <?= strip_tags($config->infos->site_title); ?></title>
25 25
 
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
 <?php
48 48
 } else {
49
-        switch ($_GET['page']) {
50
-        case 'pokemon':
51
-        ?>
49
+		switch ($_GET['page']) {
50
+		case 'pokemon':
51
+		?>
52 52
 
53 53
 		<title><?= $config->infos->site_name; ?> | <?= $locales->FIND; ?> <?= $pokemon->name; ?> <?= sprintf($locales->INCITY, $config->infos->city); ?></title>
54 54
 
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 
72 72
 
73 73
 		<?php
74
-            break;
74
+			break;
75 75
 
76
-        case 'pokestops':
77
-        ?>
76
+		case 'pokestops':
77
+		?>
78 78
 
79 79
 
80 80
 		<title><?= $config->infos->site_name; ?> | <?= sprintf($locales->POKESTOPS_METATITLE, $config->infos->city); ?></title>
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 
98 98
 
99 99
 		<?php
100
-            break;
100
+			break;
101 101
 
102
-        case 'gym':
103
-        ?>
102
+		case 'gym':
103
+		?>
104 104
 
105 105
 		<title><?= $config->infos->site_name; ?> | <?= $locales->GYMS_METATITLE; ?></title>
106 106
 
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
123 123
 
124 124
 		<?php
125
-            break;
125
+			break;
126 126
 
127
-        case 'trainer':
128
-        ?>
127
+		case 'trainer':
128
+		?>
129 129
 
130 130
 		<title><?= $config->infos->site_name; ?> | <?= $locales->TRAINERS_METATITLE; ?></title>
131 131
 
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
147 147
 
148 148
 		<?php
149
-            break;
149
+			break;
150 150
 
151
-        case 'dashboard':
152
-        ?>
151
+		case 'dashboard':
152
+		?>
153 153
 
154 154
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_DASHBOARD; ?></title>
155 155
 
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 
172 172
 
173 173
 		<?php
174
-            break;
174
+			break;
175 175
 
176
-        case 'pokedex':
177
-        ?>
176
+		case 'pokedex':
177
+		?>
178 178
 
179 179
 		<title><?= $config->infos->site_name; ?> | <?= $locales->POKEDEX_METATITLE; ?></title>
180 180
 
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
196 196
 
197 197
 		<?php
198
-            break;
198
+			break;
199 199
 
200
-        case 'nests':
201
-        ?>
200
+		case 'nests':
201
+		?>
202 202
 
203 203
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_NESTS; ?></title>
204 204
 
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
220 220
 
221 221
 		<?php
222
-            break;
222
+			break;
223 223
 
224
-        case 'raids':
225
-        ?>
224
+		case 'raids':
225
+		?>
226 226
 
227 227
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_RAIDS; ?></title>
228 228
 
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
244 244
 
245 245
 		<?php
246
-            break;
246
+			break;
247 247
 
248
-        case 'gymhistory':
249
-        ?>
248
+		case 'gymhistory':
249
+		?>
250 250
 
251 251
 		<title><?= $config->infos->site_name; ?> | Gym History</title>
252 252
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
268 268
 
269 269
 		<?php
270
-            break;
271
-    }
272
-    }
270
+			break;
271
+	}
272
+	}
273 273
 
274 274
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 <?php
48 48
 } else {
49 49
         switch ($_GET['page']) {
50
-        case 'pokemon':
51
-        ?>
50
+        	case 'pokemon':
51
+        	?>
52 52
 
53 53
 		<title><?= $config->infos->site_name; ?> | <?= $locales->FIND; ?> <?= $pokemon->name; ?> <?= sprintf($locales->INCITY, $config->infos->city); ?></title>
54 54
 
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 
72 72
 
73 73
 		<?php
74
-            break;
74
+            	break;
75 75
 
76
-        case 'pokestops':
77
-        ?>
76
+        	case 'pokestops':
77
+        	?>
78 78
 
79 79
 
80 80
 		<title><?= $config->infos->site_name; ?> | <?= sprintf($locales->POKESTOPS_METATITLE, $config->infos->city); ?></title>
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 
98 98
 
99 99
 		<?php
100
-            break;
100
+            	break;
101 101
 
102
-        case 'gym':
103
-        ?>
102
+        	case 'gym':
103
+        	?>
104 104
 
105 105
 		<title><?= $config->infos->site_name; ?> | <?= $locales->GYMS_METATITLE; ?></title>
106 106
 
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
123 123
 
124 124
 		<?php
125
-            break;
125
+            	break;
126 126
 
127
-        case 'trainer':
128
-        ?>
127
+        	case 'trainer':
128
+        	?>
129 129
 
130 130
 		<title><?= $config->infos->site_name; ?> | <?= $locales->TRAINERS_METATITLE; ?></title>
131 131
 
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
147 147
 
148 148
 		<?php
149
-            break;
149
+            	break;
150 150
 
151
-        case 'dashboard':
152
-        ?>
151
+        	case 'dashboard':
152
+        	?>
153 153
 
154 154
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_DASHBOARD; ?></title>
155 155
 
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 
172 172
 
173 173
 		<?php
174
-            break;
174
+            	break;
175 175
 
176
-        case 'pokedex':
177
-        ?>
176
+        	case 'pokedex':
177
+        	?>
178 178
 
179 179
 		<title><?= $config->infos->site_name; ?> | <?= $locales->POKEDEX_METATITLE; ?></title>
180 180
 
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
196 196
 
197 197
 		<?php
198
-            break;
198
+            	break;
199 199
 
200
-        case 'nests':
201
-        ?>
200
+        	case 'nests':
201
+        	?>
202 202
 
203 203
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_NESTS; ?></title>
204 204
 
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
220 220
 
221 221
 		<?php
222
-            break;
222
+            	break;
223 223
 
224
-        case 'raids':
225
-        ?>
224
+        	case 'raids':
225
+        	?>
226 226
 
227 227
 		<title><?= $config->infos->site_name; ?> | <?= $locales->NAV_RAIDS; ?></title>
228 228
 
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
244 244
 
245 245
 		<?php
246
-            break;
246
+            	break;
247 247
 
248
-        case 'gymhistory':
249
-        ?>
248
+        	case 'gymhistory':
249
+        	?>
250 250
 
251 251
 		<title><?= $config->infos->site_name; ?> | Gym History</title>
252 252
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		<meta name="twitter:image" content="<?= HOST_URL; ?>core/img/logo.jpg" />
268 268
 
269 269
 		<?php
270
-            break;
270
+            	break;
271 271
     }
272 272
     }
273 273
 
Please login to merge, or discard this patch.
core/cron/nests.cron.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
 $allNestParks = array();
19 19
 
20 20
 for ($iLat = 0; $iLat < $countLat;) {
21
-    for ($iLng = 0; $iLng < $countLng;) {
22
-        $minLatitude = $totalMinLat + $iLat * 0.5;
23
-        $maxLatitude = min($minLatitude + 0.5, $totalMaxLat);
24
-        $minLongitude = $totalMinLon + $iLng * 0.5;
25
-        $maxLongitude = min($minLongitude + 0.5, $totalMaxLon);
26
-
27
-        if (0 == $manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total) { //Skip empty areas
28
-            ++$iLng;
29
-            continue;
30
-        }
31
-
32
-        // Get Parks from overpass
33
-        $req = '[timeout:600][out:json][date:"2017-01-22T00:00:00Z"][bbox:'.$minLatitude.','.$minLongitude.','.$maxLatitude.','.$maxLongitude.'];
21
+	for ($iLng = 0; $iLng < $countLng;) {
22
+		$minLatitude = $totalMinLat + $iLat * 0.5;
23
+		$maxLatitude = min($minLatitude + 0.5, $totalMaxLat);
24
+		$minLongitude = $totalMinLon + $iLng * 0.5;
25
+		$maxLongitude = min($minLongitude + 0.5, $totalMaxLon);
26
+
27
+		if (0 == $manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total) { //Skip empty areas
28
+			++$iLng;
29
+			continue;
30
+		}
31
+
32
+		// Get Parks from overpass
33
+		$req = '[timeout:600][out:json][date:"2017-01-22T00:00:00Z"][bbox:'.$minLatitude.','.$minLongitude.','.$maxLatitude.','.$maxLongitude.'];
34 34
 				(
35 35
 					way["leisure"="park"];
36 36
 					way["leisure"="garden"];
@@ -83,157 +83,157 @@  discard block
 block discarded – undo
83 83
 				out meta geom;
84 84
 				>;
85 85
 				out skel qt;';
86
-        $endpoint = 'https://overpass-api.de/api/interpreter';
87
-
88
-        $curl = curl_init($endpoint);
89
-
90
-        curl_setopt($curl, CURLOPT_POST, 1);
91
-        curl_setopt($curl, CURLOPT_POSTFIELDS, 'data='.urlencode($req));
92
-        curl_setopt($curl, CURLOPT_USERAGENT, 'Worldopole/NestUpdater '.$config->infos->site_name);
93
-        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
94
-        curl_setopt($curl, CURLOPT_TIMEOUT, 660);
95
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
96
-
97
-        $response = curl_exec($curl);
98
-        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
99
-        curl_close($curl);
100
-
101
-        if (200 == $status) {
102
-            $json = json_decode($response, true);
103
-
104
-            $parks = array();
105
-            foreach ($json['elements'] as $key => &$element) {
106
-                $tempGeos = array();
107
-                if (isset($element['type']) && 'way' == $element['type'] && isset($element['geometry'])) {
108
-                    $tempGeos = array($element['geometry']);
109
-                } elseif (isset($element['type']) && 'relation' == $element['type'] && isset($element['members'])) {
110
-                    $outers = array();
111
-                    $members = $element['members'];
112
-                    foreach ($members as $member) {
113
-                        if (isset($member['role']) && 'outer' == $member['role'] && isset($member['geometry'])) {
114
-                            $outers[] = $member['geometry'];
115
-                        }
116
-                    }
117
-                    $tempGeos = combineOuter($outers);
118
-                }
119
-                foreach ($tempGeos as $key => $tempGeo) {
120
-                    if (!is_null($tempGeo) && 0 != count($tempGeo)) {
121
-                        $data = array();
122
-                        $geo = array();
123
-                        foreach ($tempGeo as $ele) {
124
-                            $geo[] = array('lat' => $ele['lat'], 'lng' => $ele['lon']);
125
-                        }
126
-
127
-                        // Finish poly where we started
128
-                        $firstEle = $geo[0];
129
-                        $lastEle = $geo[count($geo) - 1];
130
-                        if ($firstEle != $lastEle) {
131
-                            $geo[] = $firstEle;
132
-                        }
133
-
134
-                        $data['geo'] = $geo;
135
-                        if (isset($element['tags']) && isset($element['tags']['name'])) {
136
-                            $data['name'] = $element['tags']['name'];
137
-                        } else {
138
-                            $data['name'] = null;
139
-                        }
140
-                        $data['id'] = $element['id'].'#'.$key;
141
-                        $data['bounds'] = $element['bounds'];
142
-                        $parks[] = $data;
143
-                    }
144
-                }
145
-                unset($json[$key]);
146
-            }
147
-
148
-            // Get frequent spawn points
149
-            $datas = $manager->getNestData($nestTime, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
150
-            $nestsdatas = array();
151
-            foreach ($datas as $key => &$data) {
152
-                $nests['pid'] = $data->pokemon_id;
153
-                $nests['c'] = $data->total_pokemon;
154
-                $nests['lat'] = $data->latitude;
155
-                $nests['lng'] = $data->longitude;
156
-                // $starttime = $data->latest_seen - $data->duration;
157
-
158
-                $nests['st'] = '00'; // date('i', $starttime);
159
-                $nests['et'] = '00'; // date('i', $data->latest_seen);
160
-
161
-                // Add the data to array
162
-                $nestsdatas[] = $nests;
163
-                $allNestSpawns[] = $nests;
164
-                unset($datas[$key]);
165
-            }
166
-
167
-            // Checking Parks for Spawnpoints.
168
-            foreach ($parks as $key => &$park) {
169
-                $spawns = array();
170
-
171
-                foreach ($nestsdatas as $spawnpoint) {
172
-                    $lat = $spawnpoint['lat'];
173
-                    $lng = $spawnpoint['lng'];
174
-                    $pid = $spawnpoint['pid'];
175
-
176
-                    if (pointIsInsidePolygon($lat, $lng, $park['geo'], $park['bounds'])) {
177
-                        if (!isset($spawns[$pid])) {
178
-                            $spawns[$pid] = 0;
179
-                        }
180
-                        ++$spawns[$pid];
181
-                    }
182
-                }
183
-
184
-                $mostPid = 0;
185
-                $mostPidCount = 0;
186
-                foreach ($spawns as $pid => $count) {
187
-                    if ($count > $mostPidCount) {
188
-                        $mostPidCount = $count;
189
-                        $mostPid = $pid;
190
-                    }
191
-                }
192
-                if (0 != $mostPidCount && (!isset($config->system->nest_min_count) || $mostPidCount >= $config->system->nest_min_count)) {
193
-                    $park['pid'] = $mostPid;
194
-                    $park['count'] = $mostPidCount;
195
-
196
-                    $parkId = $park['id'];
197
-                    if (!array_key_exists($parkId, $allNestParks)) {
198
-                        $allNestParks[$parkId] = $park;
199
-                        unset($park['id']);
200
-                    } else {
201
-                        $savedPark = $allNestParks[$parkId];
202
-                        if ($park['pid'] == $savedPark['pid']) {
203
-                            $savedPark['count'] += $park['count'];
204
-                        } elseif ($park['count'] > $savedPark['count']) {
205
-                            $savedPark['count'] = $park['count'];
206
-                            $savedPark['pid'] = $park['pid'];
207
-                        }
208
-                        $allNestParks[$parkId] = $savedPark;
209
-                    }
210
-                }
211
-                unset($parks[$key]);
212
-            }
213
-            ++$iLng;
214
-        } elseif (429 == $status) {
215
-            echo "Got Error 429: Trying again in 5 Minutes...\n";
216
-            sleep(300);
217
-        } else {
218
-            echo 'Error '.$status." while getting nests from overpass-turbo. Aborting Nest Update.\n";
219
-            touch($nests_parks_file, $prevNestTime);
220
-            exit();
221
-        }
222
-    }
223
-    ++$iLat;
86
+		$endpoint = 'https://overpass-api.de/api/interpreter';
87
+
88
+		$curl = curl_init($endpoint);
89
+
90
+		curl_setopt($curl, CURLOPT_POST, 1);
91
+		curl_setopt($curl, CURLOPT_POSTFIELDS, 'data='.urlencode($req));
92
+		curl_setopt($curl, CURLOPT_USERAGENT, 'Worldopole/NestUpdater '.$config->infos->site_name);
93
+		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
94
+		curl_setopt($curl, CURLOPT_TIMEOUT, 660);
95
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
96
+
97
+		$response = curl_exec($curl);
98
+		$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
99
+		curl_close($curl);
100
+
101
+		if (200 == $status) {
102
+			$json = json_decode($response, true);
103
+
104
+			$parks = array();
105
+			foreach ($json['elements'] as $key => &$element) {
106
+				$tempGeos = array();
107
+				if (isset($element['type']) && 'way' == $element['type'] && isset($element['geometry'])) {
108
+					$tempGeos = array($element['geometry']);
109
+				} elseif (isset($element['type']) && 'relation' == $element['type'] && isset($element['members'])) {
110
+					$outers = array();
111
+					$members = $element['members'];
112
+					foreach ($members as $member) {
113
+						if (isset($member['role']) && 'outer' == $member['role'] && isset($member['geometry'])) {
114
+							$outers[] = $member['geometry'];
115
+						}
116
+					}
117
+					$tempGeos = combineOuter($outers);
118
+				}
119
+				foreach ($tempGeos as $key => $tempGeo) {
120
+					if (!is_null($tempGeo) && 0 != count($tempGeo)) {
121
+						$data = array();
122
+						$geo = array();
123
+						foreach ($tempGeo as $ele) {
124
+							$geo[] = array('lat' => $ele['lat'], 'lng' => $ele['lon']);
125
+						}
126
+
127
+						// Finish poly where we started
128
+						$firstEle = $geo[0];
129
+						$lastEle = $geo[count($geo) - 1];
130
+						if ($firstEle != $lastEle) {
131
+							$geo[] = $firstEle;
132
+						}
133
+
134
+						$data['geo'] = $geo;
135
+						if (isset($element['tags']) && isset($element['tags']['name'])) {
136
+							$data['name'] = $element['tags']['name'];
137
+						} else {
138
+							$data['name'] = null;
139
+						}
140
+						$data['id'] = $element['id'].'#'.$key;
141
+						$data['bounds'] = $element['bounds'];
142
+						$parks[] = $data;
143
+					}
144
+				}
145
+				unset($json[$key]);
146
+			}
147
+
148
+			// Get frequent spawn points
149
+			$datas = $manager->getNestData($nestTime, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude);
150
+			$nestsdatas = array();
151
+			foreach ($datas as $key => &$data) {
152
+				$nests['pid'] = $data->pokemon_id;
153
+				$nests['c'] = $data->total_pokemon;
154
+				$nests['lat'] = $data->latitude;
155
+				$nests['lng'] = $data->longitude;
156
+				// $starttime = $data->latest_seen - $data->duration;
157
+
158
+				$nests['st'] = '00'; // date('i', $starttime);
159
+				$nests['et'] = '00'; // date('i', $data->latest_seen);
160
+
161
+				// Add the data to array
162
+				$nestsdatas[] = $nests;
163
+				$allNestSpawns[] = $nests;
164
+				unset($datas[$key]);
165
+			}
166
+
167
+			// Checking Parks for Spawnpoints.
168
+			foreach ($parks as $key => &$park) {
169
+				$spawns = array();
170
+
171
+				foreach ($nestsdatas as $spawnpoint) {
172
+					$lat = $spawnpoint['lat'];
173
+					$lng = $spawnpoint['lng'];
174
+					$pid = $spawnpoint['pid'];
175
+
176
+					if (pointIsInsidePolygon($lat, $lng, $park['geo'], $park['bounds'])) {
177
+						if (!isset($spawns[$pid])) {
178
+							$spawns[$pid] = 0;
179
+						}
180
+						++$spawns[$pid];
181
+					}
182
+				}
183
+
184
+				$mostPid = 0;
185
+				$mostPidCount = 0;
186
+				foreach ($spawns as $pid => $count) {
187
+					if ($count > $mostPidCount) {
188
+						$mostPidCount = $count;
189
+						$mostPid = $pid;
190
+					}
191
+				}
192
+				if (0 != $mostPidCount && (!isset($config->system->nest_min_count) || $mostPidCount >= $config->system->nest_min_count)) {
193
+					$park['pid'] = $mostPid;
194
+					$park['count'] = $mostPidCount;
195
+
196
+					$parkId = $park['id'];
197
+					if (!array_key_exists($parkId, $allNestParks)) {
198
+						$allNestParks[$parkId] = $park;
199
+						unset($park['id']);
200
+					} else {
201
+						$savedPark = $allNestParks[$parkId];
202
+						if ($park['pid'] == $savedPark['pid']) {
203
+							$savedPark['count'] += $park['count'];
204
+						} elseif ($park['count'] > $savedPark['count']) {
205
+							$savedPark['count'] = $park['count'];
206
+							$savedPark['pid'] = $park['pid'];
207
+						}
208
+						$allNestParks[$parkId] = $savedPark;
209
+					}
210
+				}
211
+				unset($parks[$key]);
212
+			}
213
+			++$iLng;
214
+		} elseif (429 == $status) {
215
+			echo "Got Error 429: Trying again in 5 Minutes...\n";
216
+			sleep(300);
217
+		} else {
218
+			echo 'Error '.$status." while getting nests from overpass-turbo. Aborting Nest Update.\n";
219
+			touch($nests_parks_file, $prevNestTime);
220
+			exit();
221
+		}
222
+	}
223
+	++$iLat;
224 224
 }
225 225
 
226 226
 // Check for nests in nests of same pokemon
227 227
 foreach ($allNestParks as $keyA => $parkA) {
228
-    foreach ($allNestParks as $keyB => $parkB) {
229
-        if ($keyA != $keyB && $parkA['pid'] == $parkB['pid']) {
230
-            if (polyIsInsidePolygon($parkA['geo'], $parkA['bounds'], $parkB['geo'], $parkB['bounds'])) {
231
-                unset($allNestParks[$keyA]);
232
-            } elseif (polyIsInsidePolygon($parkB['geo'], $parkB['bounds'], $parkA['geo'], $parkA['bounds'])) {
233
-                unset($allNestParks[$keyB]);
234
-            }
235
-        }
236
-    }
228
+	foreach ($allNestParks as $keyB => $parkB) {
229
+		if ($keyA != $keyB && $parkA['pid'] == $parkB['pid']) {
230
+			if (polyIsInsidePolygon($parkA['geo'], $parkA['bounds'], $parkB['geo'], $parkB['bounds'])) {
231
+				unset($allNestParks[$keyA]);
232
+			} elseif (polyIsInsidePolygon($parkB['geo'], $parkB['bounds'], $parkA['geo'], $parkA['bounds'])) {
233
+				unset($allNestParks[$keyB]);
234
+			}
235
+		}
236
+	}
237 237
 }
238 238
 
239 239
 // Write files
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@
 block discarded – undo
24 24
         $minLongitude = $totalMinLon + $iLng * 0.5;
25 25
         $maxLongitude = min($minLongitude + 0.5, $totalMaxLon);
26 26
 
27
-        if (0 == $manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total) { //Skip empty areas
27
+        if (0 == $manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total) {
28
+//Skip empty areas
28 29
             ++$iLng;
29 30
             continue;
30 31
         }
Please login to merge, or discard this patch.
core/cron/pokedex_rarity.cron.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -6,30 +6,30 @@  discard block
 block discarded – undo
6 6
 $total_pokemon_last_day = 0;
7 7
 $pokelist = array();
8 8
 foreach ($data as $pokemon_id => $total) {
9
-    $total_pokemon_last_day += $total;
10
-    $pokelist[$pokemon_id]['spawns_last_day'] = $total;
9
+	$total_pokemon_last_day += $total;
10
+	$pokelist[$pokemon_id]['spawns_last_day'] = $total;
11 11
 }
12 12
 
13 13
 // calc rarity for last 24h
14 14
 foreach ($pokelist as &$pokemon) {
15
-    $percent = $pokemon['spawns_last_day'] * 100 / $total_pokemon_last_day;
16
-    $pokemon['rate'] = round($percent, 4);
15
+	$percent = $pokemon['spawns_last_day'] * 100 / $total_pokemon_last_day;
16
+	$pokemon['rate'] = round($percent, 4);
17 17
 }
18 18
 
19 19
 // set values for all available pokemon
20 20
 $maxpid = $config->system->max_pokemon;
21 21
 $pokedex_rarity = new stdClass();
22 22
 for ($pid = 1; $pid <= $maxpid; ++$pid) {
23
-    $pokedex_rarity->$pid = new stdClass();
24
-    if (isset($pokelist[$pid])) {
25
-        // seen
26
-        $pokedex_rarity->$pid->rate = $pokelist[$pid]['rate'];
27
-        $pokedex_rarity->$pid->per_day = (int) $pokelist[$pid]['spawns_last_day'];
28
-    } else {
29
-        // unseen
30
-        $pokedex_rarity->$pid->rate = 0.0;
31
-        $pokedex_rarity->$pid->per_day = 0;
32
-    }
23
+	$pokedex_rarity->$pid = new stdClass();
24
+	if (isset($pokelist[$pid])) {
25
+		// seen
26
+		$pokedex_rarity->$pid->rate = $pokelist[$pid]['rate'];
27
+		$pokedex_rarity->$pid->per_day = (int) $pokelist[$pid]['spawns_last_day'];
28
+	} else {
29
+		// unseen
30
+		$pokedex_rarity->$pid->rate = 0.0;
31
+		$pokedex_rarity->$pid->per_day = 0;
32
+	}
33 33
 }
34 34
 
35 35
 // Write to file
@@ -37,23 +37,23 @@  discard block
 block discarded – undo
37 37
 
38 38
 $rm_pokemon_file = $config->system->rm_pokemon_file;
39 39
 if (!is_null($rm_pokemon_file)) {
40
-    $string = file_get_contents($rm_pokemon_file);
41
-    $json = json_decode($string, true);
42
-    foreach ($pokedex_rarity as $pid => $rarity) {
43
-        $rate = $rarity->rate;
44
-        if ($rate >= 1) {
45
-            $rarity_string = 'Common';
46
-        } elseif ($rate >= 0.20) {
47
-            $rarity_string = 'Uncommon';
48
-        } elseif ($rate >= 0.01) {
49
-            $rarity_string = 'Rare';
50
-        } elseif ($rate >= 0.0025) {
51
-            $rarity_string = 'Very Rare';
52
-        } else {
53
-            $rarity_string = 'Ultra Rare';
54
-        }
55
-        unset($json[$pid]['rarity']);
56
-        $json[$pid]['rarity'] = $rarity_string;
57
-    }
58
-    file_put_contents($rm_pokemon_file, json_encode($json));
40
+	$string = file_get_contents($rm_pokemon_file);
41
+	$json = json_decode($string, true);
42
+	foreach ($pokedex_rarity as $pid => $rarity) {
43
+		$rate = $rarity->rate;
44
+		if ($rate >= 1) {
45
+			$rarity_string = 'Common';
46
+		} elseif ($rate >= 0.20) {
47
+			$rarity_string = 'Uncommon';
48
+		} elseif ($rate >= 0.01) {
49
+			$rarity_string = 'Rare';
50
+		} elseif ($rate >= 0.0025) {
51
+			$rarity_string = 'Very Rare';
52
+		} else {
53
+			$rarity_string = 'Ultra Rare';
54
+		}
55
+		unset($json[$pid]['rarity']);
56
+		$json[$pid]['rarity'] = $rarity_string;
57
+	}
58
+	file_put_contents($rm_pokemon_file, json_encode($json));
59 59
 }
Please login to merge, or discard this patch.
core/cron/captcha.cron.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -8,73 +8,73 @@
 block discarded – undo
8 8
 
9 9
 $captcha_file = SYS_PATH.'/core/json/captcha.stats.json';
10 10
 if (is_file($captcha_file)) {
11
-    $capdatas = json_decode(file_get_contents($captcha_file), true);
12
-    // Trim json stats files to last 7 days of data
13
-    $capdatas = trim_stats_json($capdatas, $timestamp_lastweek);
11
+	$capdatas = json_decode(file_get_contents($captcha_file), true);
12
+	// Trim json stats files to last 7 days of data
13
+	$capdatas = trim_stats_json($capdatas, $timestamp_lastweek);
14 14
 }
15 15
 
16 16
 $variables_secret = SYS_PATH.'/core/json/variables.secret.json';
17 17
 $config_secret = json_decode(file_get_contents($variables_secret));
18 18
 
19 19
 if ('' == $config_secret->captcha_key) {
20
-    $captcha['timestamp'] = $timestamp;
21
-    // get amount of accounts requiring a captcha
22
-    $data = $manager->getCaptchaCount();
23
-    $captcha['captcha_accs'] = $data->total;
24
-    // Add the datas in file
25
-    $capdatas[] = $captcha;
20
+	$captcha['timestamp'] = $timestamp;
21
+	// get amount of accounts requiring a captcha
22
+	$data = $manager->getCaptchaCount();
23
+	$captcha['captcha_accs'] = $data->total;
24
+	// Add the datas in file
25
+	$capdatas[] = $captcha;
26 26
 } else {
27
-    if (!empty($capdatas)) {
28
-        $lastCaptcha = array_pop($capdatas);
29
-    } else {
30
-        $lastCaptcha['timestamp'] = strtotime('-7 days', strtotime(date('Y-m-d')));
31
-    }
32
-    $lastCaptchaDate = date('Y-m-d', $lastCaptcha['timestamp']);
33
-    $startTime = strtotime($lastCaptchaDate);
34
-    $endTime = strtotime(date('Y-m-d')) + date('Z');
35
-    $timeDiff = abs($endTime - $startTime);
36
-    $numberDays = intval($timeDiff / 86400); // 86400 seconds in one day
37
-    if ($numberDays > 7) {
38
-        $numberDays = 7;
39
-    }
40
-    while ($numberDays >= 0) {
41
-        $day = $endTime - ($numberDays * 86400);
42
-        $captchaUrl =
43
-                'http://2captcha.com/res.php?key='.
44
-                $config_secret->captcha_key.'&action=getstats&date='.date('Y-m-d', $day);
27
+	if (!empty($capdatas)) {
28
+		$lastCaptcha = array_pop($capdatas);
29
+	} else {
30
+		$lastCaptcha['timestamp'] = strtotime('-7 days', strtotime(date('Y-m-d')));
31
+	}
32
+	$lastCaptchaDate = date('Y-m-d', $lastCaptcha['timestamp']);
33
+	$startTime = strtotime($lastCaptchaDate);
34
+	$endTime = strtotime(date('Y-m-d')) + date('Z');
35
+	$timeDiff = abs($endTime - $startTime);
36
+	$numberDays = intval($timeDiff / 86400); // 86400 seconds in one day
37
+	if ($numberDays > 7) {
38
+		$numberDays = 7;
39
+	}
40
+	while ($numberDays >= 0) {
41
+		$day = $endTime - ($numberDays * 86400);
42
+		$captchaUrl =
43
+				'http://2captcha.com/res.php?key='.
44
+				$config_secret->captcha_key.'&action=getstats&date='.date('Y-m-d', $day);
45 45
 
46
-        $ch = curl_init();
47
-        curl_setopt($ch, CURLOPT_URL, $captchaUrl);
48
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
49
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50
-        $fileContents = curl_exec($ch);
51
-        if (curl_errno($ch)) {
52
-            echo curl_error($ch);
53
-            echo "\n<br />";
54
-            $fileContents = '';
55
-        } else {
56
-            curl_close($ch);
57
-        }
46
+		$ch = curl_init();
47
+		curl_setopt($ch, CURLOPT_URL, $captchaUrl);
48
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
49
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
50
+		$fileContents = curl_exec($ch);
51
+		if (curl_errno($ch)) {
52
+			echo curl_error($ch);
53
+			echo "\n<br />";
54
+			$fileContents = '';
55
+		} else {
56
+			curl_close($ch);
57
+		}
58 58
 
59
-        if (!is_string($fileContents) || !strlen($fileContents)) {
60
-            echo 'Failed to get contents.';
61
-            $fileContents = '';
62
-        }
63
-        $capXml = simplexml_load_string($fileContents);
59
+		if (!is_string($fileContents) || !strlen($fileContents)) {
60
+			echo 'Failed to get contents.';
61
+			$fileContents = '';
62
+		}
63
+		$capXml = simplexml_load_string($fileContents);
64 64
 
65
-        foreach ($capXml as $key => $value) {
66
-            if ((0 == $numberDays
67
-                && ((int) $value->Attributes()->hour >= (int) date('H', $lastCaptcha['timestamp'])
68
-                && ((int) $value->Attributes()->hour <= (int) date('H')))
69
-                ) || $numberDays > 0) {
70
-                $captcha['timestamp'] =
71
-                        strtotime(date('Y-m-d', $day).' '.$value->Attributes()->hour.':00') + date('Z');
72
-                $captcha['captcha_accs'] = (string) $value->volume;
73
-                $capdatas[] = $captcha;
74
-            }
75
-        }
76
-        --$numberDays;
77
-    }
65
+		foreach ($capXml as $key => $value) {
66
+			if ((0 == $numberDays
67
+				&& ((int) $value->Attributes()->hour >= (int) date('H', $lastCaptcha['timestamp'])
68
+				&& ((int) $value->Attributes()->hour <= (int) date('H')))
69
+				) || $numberDays > 0) {
70
+				$captcha['timestamp'] =
71
+						strtotime(date('Y-m-d', $day).' '.$value->Attributes()->hour.':00') + date('Z');
72
+				$captcha['captcha_accs'] = (string) $value->volume;
73
+				$capdatas[] = $captcha;
74
+			}
75
+		}
76
+		--$numberDays;
77
+	}
78 78
 }
79 79
 
80 80
 // Write to file
Please login to merge, or discard this patch.
core/cron/crontabs.include.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,8 @@
 block discarded – undo
90 90
     touch($pokedex_rarity_file);
91 91
     // update pokedex rarity
92 92
     include_once SYS_PATH.'/core/cron/pokedex_rarity.cron.php';
93
-} elseif ((file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400)) { // extra update 12h after migration
93
+} elseif ((file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400)) {
94
+// extra update 12h after migration
94 95
     if (is_file($nests_parks_file)) {
95 96
         $prevNestTime = filemtime($nests_parks_file);
96 97
     } else {
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
 $pokemonstats_file = SYS_PATH.'/core/json/pokemon.stats.json';
38 38
 
39 39
 if (is_file($gym_file)) {
40
-    $gymsdatas = json_decode(file_get_contents($gym_file), true);
40
+	$gymsdatas = json_decode(file_get_contents($gym_file), true);
41 41
 }
42 42
 if (is_file($pokestop_file)) {
43
-    $stopdatas = json_decode(file_get_contents($pokestop_file), true);
43
+	$stopdatas = json_decode(file_get_contents($pokestop_file), true);
44 44
 }
45 45
 if (is_file($pokemonstats_file)) {
46
-    $pokedatas = json_decode(file_get_contents($pokemonstats_file), true);
46
+	$pokedatas = json_decode(file_get_contents($pokemonstats_file), true);
47 47
 }
48 48
 
49 49
 $timestamp = time();
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 include_once SYS_PATH.'/core/cron/pokemon.cron.php';
60 60
 include_once SYS_PATH.'/core/cron/pokestop.cron.php';
61 61
 if ($config->system->captcha_support) {
62
-    include_once SYS_PATH.'/core/cron/captcha.cron.php';
62
+	include_once SYS_PATH.'/core/cron/captcha.cron.php';
63 63
 }
64 64
 
65 65
 // The following files are updated every 24h only because the queries are quite expensive
@@ -72,48 +72,48 @@  discard block
 block discarded – undo
72 72
 $migration->setTimezone(new DateTimeZone('UTC'));
73 73
 $migration->setTimestamp(1493856000);
74 74
 do {
75
-    $migrationPrev = clone $migration;
76
-    $migration->modify('+14 days');
75
+	$migrationPrev = clone $migration;
76
+	$migration->modify('+14 days');
77 77
 } while ($migration < new DateTime());
78 78
 $migration = $migrationPrev->getTimestamp();
79 79
 
80 80
 if (!is_file($nests_parks_file) || filemtime($nests_parks_file) - $migration <= 0) {
81
-    file_put_contents($nests_file, json_encode(array()));
82
-    file_put_contents($nests_parks_file, json_encode(array()));
83
-    touch($nests_parks_file, 1);
81
+	file_put_contents($nests_file, json_encode(array()));
82
+	file_put_contents($nests_parks_file, json_encode(array()));
83
+	touch($nests_parks_file, 1);
84 84
 }
85 85
 
86 86
 // Do not update both files at the same time to lower cpu load
87 87
 if (file_update_ago($pokedex_rarity_file) > 86400) {
88
-    // set file mtime to now before executing long running queries
89
-    // so we don't try to update the file twice
90
-    touch($pokedex_rarity_file);
91
-    // update pokedex rarity
92
-    include_once SYS_PATH.'/core/cron/pokedex_rarity.cron.php';
88
+	// set file mtime to now before executing long running queries
89
+	// so we don't try to update the file twice
90
+	touch($pokedex_rarity_file);
91
+	// update pokedex rarity
92
+	include_once SYS_PATH.'/core/cron/pokedex_rarity.cron.php';
93 93
 } elseif ((file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400)) { // extra update 12h after migration
94
-    if (is_file($nests_parks_file)) {
95
-        $prevNestTime = filemtime($nests_parks_file);
96
-    } else {
97
-        $prevNestTime = 1;
98
-    }
99
-
100
-    // set file mtime to now before executing long running queries
101
-    // so we don't try to update the file twice
102
-    touch($nests_parks_file);
103
-    // update nests
104
-    $nestTime = 12;
105
-    include_once SYS_PATH.'/core/cron/nests.cron.php';
94
+	if (is_file($nests_parks_file)) {
95
+		$prevNestTime = filemtime($nests_parks_file);
96
+	} else {
97
+		$prevNestTime = 1;
98
+	}
99
+
100
+	// set file mtime to now before executing long running queries
101
+	// so we don't try to update the file twice
102
+	touch($nests_parks_file);
103
+	// update nests
104
+	$nestTime = 12;
105
+	include_once SYS_PATH.'/core/cron/nests.cron.php';
106 106
 } elseif ((file_update_ago($nests_parks_file) >= 86400) && (time() - $migration >= 86400)) {
107
-    if (is_file($nests_parks_file)) {
108
-        $prevNestTime = filemtime($nests_parks_file);
109
-    } else {
110
-        $prevNestTime = 1;
111
-    }
112
-
113
-    // set file mtime to now before executing long running queries
114
-    // so we don't try to update the file twice
115
-    touch($nests_parks_file);
116
-    // update nests
117
-    $nestTime = 24;
118
-    include_once SYS_PATH.'/core/cron/nests.cron.php';
107
+	if (is_file($nests_parks_file)) {
108
+		$prevNestTime = filemtime($nests_parks_file);
109
+	} else {
110
+		$prevNestTime = 1;
111
+	}
112
+
113
+	// set file mtime to now before executing long running queries
114
+	// so we don't try to update the file twice
115
+	touch($nests_parks_file);
116
+	// update nests
117
+	$nestTime = 24;
118
+	include_once SYS_PATH.'/core/cron/nests.cron.php';
119 119
 }
Please login to merge, or discard this patch.
core/js/trainer.graph.js.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 $trainer_lvl = [];
28 28
 // For all 3 teams
29 29
 for ($teamid = 1; $teamid <= 3; ++$teamid) {
30
-    $data = $manager->getTrainerLevelCount($teamid);
31
-    $trainer_lvl[$teamid] = $data;
30
+	$data = $manager->getTrainerLevelCount($teamid);
31
+	$trainer_lvl[$teamid] = $data;
32 32
 }
33 33
 
34 34
 ?>
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			borderColor: 'rgba(59,129,255,1)',
69 69
 			borderWidth: 1,
70 70
 			data: [<?php if (isset($trainer_lvl[1])) {
71
-    echo implode(',', $trainer_lvl[1]);
71
+	echo implode(',', $trainer_lvl[1]);
72 72
 } ?>],
73 73
 		},
74 74
 		{
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 			borderColor: 'rgba(247,10,20,1)',
78 78
 			borderWidth: 1,
79 79
 			data: [<?php if (isset($trainer_lvl[2])) {
80
-    echo implode(',', $trainer_lvl[2]);
80
+	echo implode(',', $trainer_lvl[2]);
81 81
 } ?>],
82 82
 		},
83 83
 		{
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			borderColor: 'rgba(248,153,0,1)',
87 87
 			borderWidth: 1,
88 88
 			data: [<?php if (isset($trainer_lvl[3])) {
89
-    echo implode(',', $trainer_lvl[3]);
89
+	echo implode(',', $trainer_lvl[3]);
90 90
 } ?>],
91 91
 		}
92 92
 	]
Please login to merge, or discard this patch.