@@ -216,6 +216,9 @@ |
||
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); |
@@ -10,70 +10,70 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | ?> |
@@ -60,7 +60,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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) { |
@@ -19,8 +19,8 @@ |
||
19 | 19 | $counts = $manager->getPokemonCountsActive(); |
20 | 20 | $rarityarray = array(); |
21 | 21 | foreach ($counts as $poke_id => $total) { |
22 | - $rarity = $pokemons->pokemon->$poke_id->rarity; |
|
23 | - isset($rarityarray[$rarity]) ? $rarityarray[$rarity] += $total : $rarityarray[$rarity] = $total; |
|
22 | + $rarity = $pokemons->pokemon->$poke_id->rarity; |
|
23 | + isset($rarityarray[$rarity]) ? $rarityarray[$rarity] += $total : $rarityarray[$rarity] = $total; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // Set amount of Pokemon for each rarity to 0 if there weren't any at that time |
@@ -4,193 +4,193 @@ discard block |
||
4 | 4 | |
5 | 5 | final class QueryManagerMysqlRocketmap extends QueryManagerMysql |
6 | 6 | { |
7 | - public function __construct() |
|
8 | - { |
|
9 | - parent::__construct(); |
|
10 | - } |
|
11 | - |
|
12 | - public function __destruct() |
|
13 | - { |
|
14 | - parent::__destruct(); |
|
15 | - } |
|
16 | - |
|
17 | - /////////// |
|
18 | - // Tester |
|
19 | - /////////// |
|
20 | - |
|
21 | - public function testTotalPokemon() |
|
22 | - { |
|
23 | - $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
24 | - $result = $this->mysqli->query($req); |
|
25 | - if (!is_object($result)) { |
|
26 | - return 1; |
|
27 | - } else { |
|
28 | - $data = $result->fetch_object(); |
|
29 | - $total = $data->total; |
|
30 | - |
|
31 | - if (0 == $total) { |
|
32 | - return 2; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - return 0; |
|
37 | - } |
|
38 | - |
|
39 | - public function testTotalGyms() |
|
40 | - { |
|
41 | - $req = 'SELECT COUNT(*) as total FROM gym'; |
|
42 | - $result = $this->mysqli->query($req); |
|
43 | - if (!is_object($result)) { |
|
44 | - return 1; |
|
45 | - } else { |
|
46 | - $data = $result->fetch_object(); |
|
47 | - $total = $data->total; |
|
48 | - |
|
49 | - if (0 == $total) { |
|
50 | - return 2; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return 0; |
|
55 | - } |
|
56 | - |
|
57 | - public function testTotalPokestops() |
|
58 | - { |
|
59 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
60 | - $result = $this->mysqli->query($req); |
|
61 | - if (!is_object($result)) { |
|
62 | - return 1; |
|
63 | - } else { |
|
64 | - $data = $result->fetch_object(); |
|
65 | - $total = $data->total; |
|
66 | - |
|
67 | - if (0 == $total) { |
|
68 | - return 2; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return 0; |
|
73 | - } |
|
74 | - |
|
75 | - ///////////// |
|
76 | - // Homepage |
|
77 | - ///////////// |
|
78 | - |
|
79 | - public function getTotalPokemon() |
|
80 | - { |
|
81 | - $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()'; |
|
82 | - $result = $this->mysqli->query($req); |
|
83 | - $data = $result->fetch_object(); |
|
84 | - |
|
85 | - return $data; |
|
86 | - } |
|
87 | - |
|
88 | - public function getTotalLures() |
|
89 | - { |
|
90 | - $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()'; |
|
91 | - $result = $this->mysqli->query($req); |
|
92 | - $data = $result->fetch_object(); |
|
93 | - |
|
94 | - return $data; |
|
95 | - } |
|
96 | - |
|
97 | - public function getTotalGyms() |
|
98 | - { |
|
99 | - $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym'; |
|
100 | - $result = $this->mysqli->query($req); |
|
101 | - $data = $result->fetch_object(); |
|
102 | - |
|
103 | - return $data; |
|
104 | - } |
|
105 | - |
|
106 | - public function getTotalRaids() |
|
107 | - { |
|
108 | - $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()'; |
|
109 | - $result = $this->mysqli->query($req); |
|
110 | - $data = $result->fetch_object(); |
|
111 | - |
|
112 | - return $data; |
|
113 | - } |
|
114 | - |
|
115 | - public function getTotalGymsForTeam($team_id) |
|
116 | - { |
|
117 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'"; |
|
118 | - $result = $this->mysqli->query($req); |
|
119 | - $data = $result->fetch_object(); |
|
120 | - |
|
121 | - return $data; |
|
122 | - } |
|
123 | - |
|
124 | - public function getRecentAll() |
|
125 | - { |
|
126 | - $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
7 | + public function __construct() |
|
8 | + { |
|
9 | + parent::__construct(); |
|
10 | + } |
|
11 | + |
|
12 | + public function __destruct() |
|
13 | + { |
|
14 | + parent::__destruct(); |
|
15 | + } |
|
16 | + |
|
17 | + /////////// |
|
18 | + // Tester |
|
19 | + /////////// |
|
20 | + |
|
21 | + public function testTotalPokemon() |
|
22 | + { |
|
23 | + $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
24 | + $result = $this->mysqli->query($req); |
|
25 | + if (!is_object($result)) { |
|
26 | + return 1; |
|
27 | + } else { |
|
28 | + $data = $result->fetch_object(); |
|
29 | + $total = $data->total; |
|
30 | + |
|
31 | + if (0 == $total) { |
|
32 | + return 2; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + return 0; |
|
37 | + } |
|
38 | + |
|
39 | + public function testTotalGyms() |
|
40 | + { |
|
41 | + $req = 'SELECT COUNT(*) as total FROM gym'; |
|
42 | + $result = $this->mysqli->query($req); |
|
43 | + if (!is_object($result)) { |
|
44 | + return 1; |
|
45 | + } else { |
|
46 | + $data = $result->fetch_object(); |
|
47 | + $total = $data->total; |
|
48 | + |
|
49 | + if (0 == $total) { |
|
50 | + return 2; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return 0; |
|
55 | + } |
|
56 | + |
|
57 | + public function testTotalPokestops() |
|
58 | + { |
|
59 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
60 | + $result = $this->mysqli->query($req); |
|
61 | + if (!is_object($result)) { |
|
62 | + return 1; |
|
63 | + } else { |
|
64 | + $data = $result->fetch_object(); |
|
65 | + $total = $data->total; |
|
66 | + |
|
67 | + if (0 == $total) { |
|
68 | + return 2; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return 0; |
|
73 | + } |
|
74 | + |
|
75 | + ///////////// |
|
76 | + // Homepage |
|
77 | + ///////////// |
|
78 | + |
|
79 | + public function getTotalPokemon() |
|
80 | + { |
|
81 | + $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE disappear_time >= UTC_TIMESTAMP()'; |
|
82 | + $result = $this->mysqli->query($req); |
|
83 | + $data = $result->fetch_object(); |
|
84 | + |
|
85 | + return $data; |
|
86 | + } |
|
87 | + |
|
88 | + public function getTotalLures() |
|
89 | + { |
|
90 | + $req = 'SELECT COUNT(*) AS total FROM pokestop WHERE lure_expiration >= UTC_TIMESTAMP()'; |
|
91 | + $result = $this->mysqli->query($req); |
|
92 | + $data = $result->fetch_object(); |
|
93 | + |
|
94 | + return $data; |
|
95 | + } |
|
96 | + |
|
97 | + public function getTotalGyms() |
|
98 | + { |
|
99 | + $req = 'SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym'; |
|
100 | + $result = $this->mysqli->query($req); |
|
101 | + $data = $result->fetch_object(); |
|
102 | + |
|
103 | + return $data; |
|
104 | + } |
|
105 | + |
|
106 | + public function getTotalRaids() |
|
107 | + { |
|
108 | + $req = 'SELECT COUNT(*) AS total FROM raid WHERE start <= UTC_TIMESTAMP() AND end >= UTC_TIMESTAMP()'; |
|
109 | + $result = $this->mysqli->query($req); |
|
110 | + $data = $result->fetch_object(); |
|
111 | + |
|
112 | + return $data; |
|
113 | + } |
|
114 | + |
|
115 | + public function getTotalGymsForTeam($team_id) |
|
116 | + { |
|
117 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE team_id = '".$team_id."'"; |
|
118 | + $result = $this->mysqli->query($req); |
|
119 | + $data = $result->fetch_object(); |
|
120 | + |
|
121 | + return $data; |
|
122 | + } |
|
123 | + |
|
124 | + public function getRecentAll() |
|
125 | + { |
|
126 | + $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
127 | 127 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
128 | 128 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
129 | 129 | FROM pokemon |
130 | 130 | ORDER BY last_modified DESC |
131 | 131 | LIMIT 0,12"; |
132 | - $result = $this->mysqli->query($req); |
|
133 | - $data = array(); |
|
134 | - if ($result->num_rows > 0) { |
|
135 | - while ($row = $result->fetch_object()) { |
|
136 | - $data[] = $row; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $data; |
|
141 | - } |
|
142 | - |
|
143 | - public function getRecentMythic($mythic_pokemons) |
|
144 | - { |
|
145 | - $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
132 | + $result = $this->mysqli->query($req); |
|
133 | + $data = array(); |
|
134 | + if ($result->num_rows > 0) { |
|
135 | + while ($row = $result->fetch_object()) { |
|
136 | + $data[] = $row; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $data; |
|
141 | + } |
|
142 | + |
|
143 | + public function getRecentMythic($mythic_pokemons) |
|
144 | + { |
|
145 | + $req = "SELECT DISTINCT pokemon_id, encounter_id, disappear_time, last_modified, |
|
146 | 146 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
147 | 147 | latitude, longitude, cp, individual_attack, individual_defense, individual_stamina |
148 | 148 | FROM pokemon |
149 | 149 | WHERE pokemon_id IN (".implode(',', $mythic_pokemons).') |
150 | 150 | ORDER BY last_modified DESC |
151 | 151 | LIMIT 0,12'; |
152 | - $result = $this->mysqli->query($req); |
|
153 | - $data = array(); |
|
154 | - if ($result->num_rows > 0) { |
|
155 | - while ($row = $result->fetch_object()) { |
|
156 | - $data[] = $row; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - return $data; |
|
161 | - } |
|
162 | - |
|
163 | - /////////////////// |
|
164 | - // Single Pokemon |
|
165 | - /////////////////// |
|
166 | - |
|
167 | - public function getGymsProtectedByPokemon($pokemon_id) |
|
168 | - { |
|
169 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'"; |
|
170 | - $result = $this->mysqli->query($req); |
|
171 | - $data = $result->fetch_object(); |
|
172 | - |
|
173 | - return $data; |
|
174 | - } |
|
175 | - |
|
176 | - public function getPokemonLastSeen($pokemon_id) |
|
177 | - { |
|
178 | - $req = "SELECT disappear_time, |
|
152 | + $result = $this->mysqli->query($req); |
|
153 | + $data = array(); |
|
154 | + if ($result->num_rows > 0) { |
|
155 | + while ($row = $result->fetch_object()) { |
|
156 | + $data[] = $row; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + return $data; |
|
161 | + } |
|
162 | + |
|
163 | + /////////////////// |
|
164 | + // Single Pokemon |
|
165 | + /////////////////// |
|
166 | + |
|
167 | + public function getGymsProtectedByPokemon($pokemon_id) |
|
168 | + { |
|
169 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total FROM gym WHERE guard_pokemon_id = '".$pokemon_id."'"; |
|
170 | + $result = $this->mysqli->query($req); |
|
171 | + $data = $result->fetch_object(); |
|
172 | + |
|
173 | + return $data; |
|
174 | + } |
|
175 | + |
|
176 | + public function getPokemonLastSeen($pokemon_id) |
|
177 | + { |
|
178 | + $req = "SELECT disappear_time, |
|
179 | 179 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
180 | 180 | latitude, longitude |
181 | 181 | FROM pokemon |
182 | 182 | WHERE pokemon_id = '".$pokemon_id."' |
183 | 183 | ORDER BY disappear_time DESC |
184 | 184 | LIMIT 0,1"; |
185 | - $result = $this->mysqli->query($req); |
|
186 | - $data = $result->fetch_object(); |
|
185 | + $result = $this->mysqli->query($req); |
|
186 | + $data = $result->fetch_object(); |
|
187 | 187 | |
188 | - return $data; |
|
189 | - } |
|
188 | + return $data; |
|
189 | + } |
|
190 | 190 | |
191 | - public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | - { |
|
193 | - $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
191 | + public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | + { |
|
193 | + $req = "SELECT CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS distime, |
|
194 | 194 | pokemon_id, disappear_time, latitude, longitude, |
195 | 195 | cp, individual_attack, individual_defense, individual_stamina, |
196 | 196 | ROUND(100*(individual_attack+individual_defense+individual_stamina)/45,1) AS IV, |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | WHERE pokemon_id = '".$pokemon_id."' AND move_1 IS NOT NULL AND move_1 <> '0' |
200 | 200 | ORDER BY $top_order_by $top_direction, disappear_time DESC |
201 | 201 | LIMIT 0,50"; |
202 | - $result = $this->mysqli->query($req); |
|
203 | - $top = array(); |
|
204 | - while ($data = $result->fetch_object()) { |
|
205 | - $top[] = $data; |
|
206 | - } |
|
207 | - |
|
208 | - return $top; |
|
209 | - } |
|
210 | - |
|
211 | - public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
212 | - { |
|
213 | - $trainer_blacklist = ''; |
|
214 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
215 | - $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
216 | - } |
|
217 | - $req = "SELECT trainer_name, |
|
202 | + $result = $this->mysqli->query($req); |
|
203 | + $top = array(); |
|
204 | + while ($data = $result->fetch_object()) { |
|
205 | + $top[] = $data; |
|
206 | + } |
|
207 | + |
|
208 | + return $top; |
|
209 | + } |
|
210 | + |
|
211 | + public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
212 | + { |
|
213 | + $trainer_blacklist = ''; |
|
214 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
215 | + $trainer_blacklist = " AND trainer_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
216 | + } |
|
217 | + $req = "SELECT trainer_name, |
|
218 | 218 | ROUND((100*(iv_attack+iv_defense+iv_stamina)/45),1) AS IV, |
219 | 219 | move_1, move_2, cp, |
220 | 220 | DATE_FORMAT(last_seen, '%Y-%m-%d') AS lasttime, last_seen |
@@ -222,230 +222,230 @@ discard block |
||
222 | 222 | WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist." |
223 | 223 | ORDER BY $best_order_by $best_direction, trainer_name ASC |
224 | 224 | LIMIT 0,50"; |
225 | - $result = $this->mysqli->query($req); |
|
226 | - $toptrainer = array(); |
|
227 | - while ($data = $result->fetch_object()) { |
|
228 | - $toptrainer[] = $data; |
|
229 | - } |
|
225 | + $result = $this->mysqli->query($req); |
|
226 | + $toptrainer = array(); |
|
227 | + while ($data = $result->fetch_object()) { |
|
228 | + $toptrainer[] = $data; |
|
229 | + } |
|
230 | 230 | |
231 | - return $toptrainer; |
|
232 | - } |
|
231 | + return $toptrainer; |
|
232 | + } |
|
233 | 233 | |
234 | - public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
235 | - { |
|
234 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
235 | + { |
|
236 | 236 | $req = "SELECT latitude, longitude |
237 | 237 | FROM pokemon |
238 | 238 | WHERE pokemon_id = ".$pokemon_id." AND disappear_time BETWEEN '".$start."' AND '".$end."' |
239 | 239 | LIMIT 10000"; |
240 | - $result = $this->mysqli->query($req); |
|
241 | - $points = array(); |
|
242 | - while ($data = $result->fetch_object()) { |
|
243 | - $points[] = $data; |
|
244 | - } |
|
245 | - |
|
246 | - return $points; |
|
247 | - } |
|
248 | - |
|
249 | - public function getPokemonGraph($pokemon_id) |
|
250 | - { |
|
251 | - $req = "SELECT COUNT(*) AS total, |
|
240 | + $result = $this->mysqli->query($req); |
|
241 | + $points = array(); |
|
242 | + while ($data = $result->fetch_object()) { |
|
243 | + $points[] = $data; |
|
244 | + } |
|
245 | + |
|
246 | + return $points; |
|
247 | + } |
|
248 | + |
|
249 | + public function getPokemonGraph($pokemon_id) |
|
250 | + { |
|
251 | + $req = "SELECT COUNT(*) AS total, |
|
252 | 252 | HOUR(CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."')) AS disappear_hour |
253 | 253 | FROM (SELECT disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
254 | 254 | GROUP BY disappear_hour |
255 | 255 | ORDER BY disappear_hour"; |
256 | - $result = $this->mysqli->query($req); |
|
257 | - $array = array_fill(0, 24, 0); |
|
258 | - while ($result && $data = $result->fetch_object()) { |
|
259 | - $array[$data->disappear_hour] = $data->total; |
|
260 | - } |
|
261 | - // shift array because AM/PM starts at 1AM not 0:00 |
|
262 | - $array[] = $array[0]; |
|
263 | - array_shift($array); |
|
264 | - |
|
265 | - return $array; |
|
266 | - } |
|
267 | - |
|
268 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
269 | - { |
|
270 | - $inmap_pkms_filter = ''; |
|
271 | - $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
272 | - $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where; |
|
273 | - $resultTestIv = $this->mysqli->query($reqTestIv); |
|
274 | - $testIv = $resultTestIv->fetch_object(); |
|
275 | - if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
276 | - foreach ($inmap_pokemons as $inmap) { |
|
277 | - $inmap_pkms_filter .= "'".$inmap."',"; |
|
278 | - } |
|
279 | - $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
280 | - $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
281 | - } |
|
282 | - if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
283 | - $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') '; |
|
284 | - } |
|
285 | - if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
286 | - $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') '; |
|
287 | - } |
|
288 | - $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time, |
|
256 | + $result = $this->mysqli->query($req); |
|
257 | + $array = array_fill(0, 24, 0); |
|
258 | + while ($result && $data = $result->fetch_object()) { |
|
259 | + $array[$data->disappear_hour] = $data->total; |
|
260 | + } |
|
261 | + // shift array because AM/PM starts at 1AM not 0:00 |
|
262 | + $array[] = $array[0]; |
|
263 | + array_shift($array); |
|
264 | + |
|
265 | + return $array; |
|
266 | + } |
|
267 | + |
|
268 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
269 | + { |
|
270 | + $inmap_pkms_filter = ''; |
|
271 | + $where = ' WHERE disappear_time >= UTC_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
272 | + $reqTestIv = 'SELECT MAX(individual_attack) AS iv FROM pokemon '.$where; |
|
273 | + $resultTestIv = $this->mysqli->query($reqTestIv); |
|
274 | + $testIv = $resultTestIv->fetch_object(); |
|
275 | + if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
276 | + foreach ($inmap_pokemons as $inmap) { |
|
277 | + $inmap_pkms_filter .= "'".$inmap."',"; |
|
278 | + } |
|
279 | + $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
280 | + $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
281 | + } |
|
282 | + if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
283 | + $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) >= ('.$ivMin.') '; |
|
284 | + } |
|
285 | + if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
286 | + $where .= ' AND ((100/45)*(individual_attack+individual_defense+individual_stamina)) <= ('.$ivMax.') '; |
|
287 | + } |
|
288 | + $req = "SELECT pokemon_id, encounter_id, latitude, longitude, disappear_time, |
|
289 | 289 | CONVERT_TZ(disappear_time, '+00:00', '".self::$time_offset."') AS disappear_time_real, |
290 | 290 | individual_attack, individual_defense, individual_stamina, move_1, move_2 |
291 | 291 | FROM pokemon ".$where.' |
292 | 292 | LIMIT 5000'; |
293 | - $result = $this->mysqli->query($req); |
|
294 | - $spawns = array(); |
|
295 | - while ($data = $result->fetch_object()) { |
|
296 | - $spawns[] = $data; |
|
297 | - } |
|
298 | - |
|
299 | - return $spawns; |
|
300 | - } |
|
301 | - |
|
302 | - public function getPokemonSliderMinMax() |
|
303 | - { |
|
304 | - $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon'; |
|
305 | - $result = $this->mysqli->query($req); |
|
306 | - $data = $result->fetch_object(); |
|
307 | - |
|
308 | - return $data; |
|
309 | - } |
|
310 | - |
|
311 | - public function getMapsCoords() |
|
312 | - { |
|
313 | - $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, |
|
293 | + $result = $this->mysqli->query($req); |
|
294 | + $spawns = array(); |
|
295 | + while ($data = $result->fetch_object()) { |
|
296 | + $spawns[] = $data; |
|
297 | + } |
|
298 | + |
|
299 | + return $spawns; |
|
300 | + } |
|
301 | + |
|
302 | + public function getPokemonSliderMinMax() |
|
303 | + { |
|
304 | + $req = 'SELECT MIN(disappear_time) AS min, MAX(disappear_time) AS max FROM pokemon'; |
|
305 | + $result = $this->mysqli->query($req); |
|
306 | + $data = $result->fetch_object(); |
|
307 | + |
|
308 | + return $data; |
|
309 | + } |
|
310 | + |
|
311 | + public function getMapsCoords() |
|
312 | + { |
|
313 | + $req = 'SELECT MAX(latitude) AS max_latitude, MIN(latitude) AS min_latitude, |
|
314 | 314 | MAX(longitude) AS max_longitude, MIN(longitude) as min_longitude |
315 | 315 | FROM spawnpoint'; |
316 | - $result = $this->mysqli->query($req); |
|
317 | - $data = $result->fetch_object(); |
|
316 | + $result = $this->mysqli->query($req); |
|
317 | + $data = $result->fetch_object(); |
|
318 | 318 | |
319 | - return $data; |
|
320 | - } |
|
319 | + return $data; |
|
320 | + } |
|
321 | 321 | |
322 | - public function getPokemonCount($pokemon_id) |
|
323 | - { |
|
324 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
322 | + public function getPokemonCount($pokemon_id) |
|
323 | + { |
|
324 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
325 | 325 | FROM pokemon_stats |
326 | 326 | WHERE pid = '.$pokemon_id; |
327 | - $result = $this->mysqli->query($req); |
|
328 | - $data = $result->fetch_object(); |
|
327 | + $result = $this->mysqli->query($req); |
|
328 | + $data = $result->fetch_object(); |
|
329 | 329 | |
330 | - return $data; |
|
331 | - } |
|
330 | + return $data; |
|
331 | + } |
|
332 | 332 | |
333 | - public function getPokemonCountAll() |
|
334 | - { |
|
335 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
333 | + public function getPokemonCountAll() |
|
334 | + { |
|
335 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
336 | 336 | FROM pokemon_stats |
337 | 337 | GROUP BY pid'; |
338 | - $result = $this->mysqli->query($req); |
|
339 | - $array = array(); |
|
340 | - while ($data = $result->fetch_object()) { |
|
341 | - $array[] = $data; |
|
342 | - } |
|
343 | - |
|
344 | - return $array; |
|
345 | - } |
|
346 | - |
|
347 | - public function getRaidCount($pokemon_id) |
|
348 | - { |
|
349 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
338 | + $result = $this->mysqli->query($req); |
|
339 | + $array = array(); |
|
340 | + while ($data = $result->fetch_object()) { |
|
341 | + $array[] = $data; |
|
342 | + } |
|
343 | + |
|
344 | + return $array; |
|
345 | + } |
|
346 | + |
|
347 | + public function getRaidCount($pokemon_id) |
|
348 | + { |
|
349 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
350 | 350 | FROM raid_stats |
351 | 351 | WHERE pid = '.$pokemon_id; |
352 | - $result = $this->mysqli->query($req); |
|
353 | - $data = $result->fetch_object(); |
|
352 | + $result = $this->mysqli->query($req); |
|
353 | + $data = $result->fetch_object(); |
|
354 | 354 | |
355 | - return $data; |
|
356 | - } |
|
355 | + return $data; |
|
356 | + } |
|
357 | 357 | |
358 | - public function getRaidCountAll() |
|
359 | - { |
|
360 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
358 | + public function getRaidCountAll() |
|
359 | + { |
|
360 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
361 | 361 | FROM raid_stats |
362 | 362 | GROUP BY pid'; |
363 | - $result = $this->mysqli->query($req); |
|
364 | - $array = array(); |
|
365 | - while ($data = $result->fetch_object()) { |
|
366 | - $array[] = $data; |
|
367 | - } |
|
368 | - |
|
369 | - return $array; |
|
370 | - } |
|
371 | - |
|
372 | - /////////////// |
|
373 | - // Pokestops |
|
374 | - ////////////// |
|
375 | - |
|
376 | - public function getTotalPokestops() |
|
377 | - { |
|
378 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
379 | - $result = $this->mysqli->query($req); |
|
380 | - $data = $result->fetch_object(); |
|
381 | - |
|
382 | - return $data; |
|
383 | - } |
|
384 | - |
|
385 | - public function getAllPokestops() |
|
386 | - { |
|
387 | - $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, |
|
363 | + $result = $this->mysqli->query($req); |
|
364 | + $array = array(); |
|
365 | + while ($data = $result->fetch_object()) { |
|
366 | + $array[] = $data; |
|
367 | + } |
|
368 | + |
|
369 | + return $array; |
|
370 | + } |
|
371 | + |
|
372 | + /////////////// |
|
373 | + // Pokestops |
|
374 | + ////////////// |
|
375 | + |
|
376 | + public function getTotalPokestops() |
|
377 | + { |
|
378 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
379 | + $result = $this->mysqli->query($req); |
|
380 | + $data = $result->fetch_object(); |
|
381 | + |
|
382 | + return $data; |
|
383 | + } |
|
384 | + |
|
385 | + public function getAllPokestops() |
|
386 | + { |
|
387 | + $req = "SELECT latitude, longitude, lure_expiration, UTC_TIMESTAMP() AS now, |
|
388 | 388 | CONVERT_TZ(lure_expiration, '+00:00', '".self::$time_offset."') AS lure_expiration_real |
389 | 389 | FROM pokestop"; |
390 | - $result = $this->mysqli->query($req); |
|
391 | - $pokestops = array(); |
|
392 | - while ($data = $result->fetch_object()) { |
|
393 | - $pokestops[] = $data; |
|
394 | - } |
|
395 | - |
|
396 | - return $pokestops; |
|
397 | - } |
|
398 | - |
|
399 | - ///////// |
|
400 | - // Gyms |
|
401 | - ///////// |
|
402 | - |
|
403 | - public function getTeamGuardians($team_id) |
|
404 | - { |
|
405 | - $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
390 | + $result = $this->mysqli->query($req); |
|
391 | + $pokestops = array(); |
|
392 | + while ($data = $result->fetch_object()) { |
|
393 | + $pokestops[] = $data; |
|
394 | + } |
|
395 | + |
|
396 | + return $pokestops; |
|
397 | + } |
|
398 | + |
|
399 | + ///////// |
|
400 | + // Gyms |
|
401 | + ///////// |
|
402 | + |
|
403 | + public function getTeamGuardians($team_id) |
|
404 | + { |
|
405 | + $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
406 | 406 | FROM gym WHERE team_id = '".$team_id."' |
407 | 407 | GROUP BY guard_pokemon_id |
408 | 408 | ORDER BY total DESC |
409 | 409 | LIMIT 0,3"; |
410 | - $result = $this->mysqli->query($req); |
|
411 | - $datas = array(); |
|
412 | - while ($data = $result->fetch_object()) { |
|
413 | - $datas[] = $data; |
|
414 | - } |
|
415 | - |
|
416 | - return $datas; |
|
417 | - } |
|
418 | - |
|
419 | - public function getOwnedAndPoints($team_id) |
|
420 | - { |
|
421 | - $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, |
|
410 | + $result = $this->mysqli->query($req); |
|
411 | + $datas = array(); |
|
412 | + while ($data = $result->fetch_object()) { |
|
413 | + $datas[] = $data; |
|
414 | + } |
|
415 | + |
|
416 | + return $datas; |
|
417 | + } |
|
418 | + |
|
419 | + public function getOwnedAndPoints($team_id) |
|
420 | + { |
|
421 | + $req = "SELECT COUNT(DISTINCT(gym_id)) AS total, |
|
422 | 422 | ROUND(AVG(total_cp),0) AS average_points |
423 | 423 | FROM gym |
424 | 424 | WHERE team_id = '".$team_id."'"; |
425 | - $result = $this->mysqli->query($req); |
|
426 | - $data = $result->fetch_object(); |
|
425 | + $result = $this->mysqli->query($req); |
|
426 | + $data = $result->fetch_object(); |
|
427 | 427 | |
428 | - return $data; |
|
429 | - } |
|
428 | + return $data; |
|
429 | + } |
|
430 | 430 | |
431 | - public function getAllGyms() |
|
432 | - { |
|
433 | - $req = "SELECT gym_id, team_id, latitude, longitude, |
|
431 | + public function getAllGyms() |
|
432 | + { |
|
433 | + $req = "SELECT gym_id, team_id, latitude, longitude, |
|
434 | 434 | CONVERT_TZ(last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, |
435 | 435 | (6 - slots_available) AS level |
436 | 436 | FROM gym"; |
437 | - $result = $this->mysqli->query($req); |
|
438 | - $gyms = array(); |
|
439 | - while ($data = $result->fetch_object()) { |
|
440 | - $gyms[] = $data; |
|
441 | - } |
|
442 | - |
|
443 | - return $gyms; |
|
444 | - } |
|
445 | - |
|
446 | - public function getGymData($gym_id) |
|
447 | - { |
|
448 | - $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
|
437 | + $result = $this->mysqli->query($req); |
|
438 | + $gyms = array(); |
|
439 | + while ($data = $result->fetch_object()) { |
|
440 | + $gyms[] = $data; |
|
441 | + } |
|
442 | + |
|
443 | + return $gyms; |
|
444 | + } |
|
445 | + |
|
446 | + public function getGymData($gym_id) |
|
447 | + { |
|
448 | + $req = "SELECT gymdetails.name AS name, gymdetails.description AS description, gymdetails.url AS url, gym.team_id AS team, |
|
449 | 449 | CONVERT_TZ(gym.last_scanned, '+00:00', '".self::$time_offset."') AS last_scanned, |
450 | 450 | gym.guard_pokemon_id AS guard_pokemon_id, |
451 | 451 | gym.total_cp AS total_cp, |
@@ -453,53 +453,53 @@ discard block |
||
453 | 453 | FROM gymdetails |
454 | 454 | LEFT JOIN gym ON gym.gym_id = gymdetails.gym_id |
455 | 455 | WHERE gym.gym_id='".$gym_id."'"; |
456 | - $result = $this->mysqli->query($req); |
|
457 | - $data = $result->fetch_object(); |
|
456 | + $result = $this->mysqli->query($req); |
|
457 | + $data = $result->fetch_object(); |
|
458 | 458 | |
459 | - return $data; |
|
460 | - } |
|
459 | + return $data; |
|
460 | + } |
|
461 | 461 | |
462 | - public function getGymDefenders($gym_id) |
|
463 | - { |
|
464 | - $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
|
462 | + public function getGymDefenders($gym_id) |
|
463 | + { |
|
464 | + $req = "SELECT DISTINCT gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, MAX(cp) AS cp, gymmember.gym_id |
|
465 | 465 | FROM gympokemon |
466 | 466 | INNER JOIN gymmember ON gympokemon.pokemon_uid=gymmember.pokemon_uid |
467 | 467 | GROUP BY gympokemon.pokemon_uid, pokemon_id, iv_attack, iv_defense, iv_stamina, gym_id |
468 | 468 | HAVING gymmember.gym_id='".$gym_id."' |
469 | 469 | ORDER BY cp DESC"; |
470 | - $result = $this->mysqli->query($req); |
|
471 | - $defenders = array(); |
|
472 | - while ($data = $result->fetch_object()) { |
|
473 | - $defenders[] = $data; |
|
474 | - } |
|
475 | - |
|
476 | - return $defenders; |
|
477 | - } |
|
478 | - |
|
479 | - //////////////// |
|
480 | - // Gym History |
|
481 | - //////////////// |
|
482 | - |
|
483 | - public function getGymHistories($gym_name, $team, $page, $ranking) |
|
484 | - { |
|
485 | - $where = ''; |
|
486 | - if (isset($gym_name) && '' != $gym_name) { |
|
487 | - $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
488 | - } |
|
489 | - if (isset($team) && '' != $team) { |
|
490 | - $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team; |
|
491 | - } |
|
492 | - switch ($ranking) { |
|
493 | - case 1: |
|
494 | - $order = ' ORDER BY name, last_modified DESC'; |
|
495 | - break; |
|
496 | - case 2: |
|
497 | - $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
498 | - break; |
|
499 | - default: |
|
500 | - $order = ' ORDER BY last_modified DESC, name'; |
|
501 | - } |
|
502 | - $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, |
|
470 | + $result = $this->mysqli->query($req); |
|
471 | + $defenders = array(); |
|
472 | + while ($data = $result->fetch_object()) { |
|
473 | + $defenders[] = $data; |
|
474 | + } |
|
475 | + |
|
476 | + return $defenders; |
|
477 | + } |
|
478 | + |
|
479 | + //////////////// |
|
480 | + // Gym History |
|
481 | + //////////////// |
|
482 | + |
|
483 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
484 | + { |
|
485 | + $where = ''; |
|
486 | + if (isset($gym_name) && '' != $gym_name) { |
|
487 | + $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
488 | + } |
|
489 | + if (isset($team) && '' != $team) { |
|
490 | + $where .= ('' == $where ? ' WHERE' : ' AND').' team_id = '.$team; |
|
491 | + } |
|
492 | + switch ($ranking) { |
|
493 | + case 1: |
|
494 | + $order = ' ORDER BY name, last_modified DESC'; |
|
495 | + break; |
|
496 | + case 2: |
|
497 | + $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
498 | + break; |
|
499 | + default: |
|
500 | + $order = ' ORDER BY last_modified DESC, name'; |
|
501 | + } |
|
502 | + $req = "SELECT gymdetails.gym_id, name, team_id, total_cp, |
|
503 | 503 | (6 - slots_available) as pokemon_count, |
504 | 504 | CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified |
505 | 505 | FROM gymdetails |
@@ -507,93 +507,93 @@ discard block |
||
507 | 507 | ON gymdetails.gym_id = gym.gym_id |
508 | 508 | ".$where.$order." |
509 | 509 | LIMIT ".($page * 10).",10"; |
510 | - $result = $this->mysqli->query($req); |
|
511 | - $gym_history = array(); |
|
512 | - while ($data = $result->fetch_object()) { |
|
513 | - $gym_history[] = $data; |
|
514 | - } |
|
515 | - |
|
516 | - return $gym_history; |
|
517 | - } |
|
518 | - |
|
519 | - public function getGymHistoriesPokemon($gym_id) |
|
520 | - { |
|
521 | - $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
|
510 | + $result = $this->mysqli->query($req); |
|
511 | + $gym_history = array(); |
|
512 | + while ($data = $result->fetch_object()) { |
|
513 | + $gym_history[] = $data; |
|
514 | + } |
|
515 | + |
|
516 | + return $gym_history; |
|
517 | + } |
|
518 | + |
|
519 | + public function getGymHistoriesPokemon($gym_id) |
|
520 | + { |
|
521 | + $req = "SELECT DISTINCT gymmember.pokemon_uid, pokemon_id, cp, trainer_name |
|
522 | 522 | FROM gymmember |
523 | 523 | LEFT JOIN gympokemon |
524 | 524 | ON gymmember.pokemon_uid = gympokemon.pokemon_uid |
525 | 525 | WHERE gymmember.gym_id = '".$gym_id."' |
526 | 526 | ORDER BY deployment_time"; |
527 | - $result = $this->mysqli->query($req); |
|
528 | - $pokemons = array(); |
|
529 | - while ($data = $result->fetch_object()) { |
|
530 | - $pokemons[] = $data; |
|
531 | - } |
|
532 | - |
|
533 | - return $pokemons; |
|
534 | - } |
|
535 | - |
|
536 | - public function getHistoryForGym($page, $gym_id) |
|
537 | - { |
|
538 | - if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
539 | - $pageSize = 25; |
|
540 | - } else { |
|
541 | - $pageSize = 10; |
|
542 | - } |
|
543 | - $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count, |
|
527 | + $result = $this->mysqli->query($req); |
|
528 | + $pokemons = array(); |
|
529 | + while ($data = $result->fetch_object()) { |
|
530 | + $pokemons[] = $data; |
|
531 | + } |
|
532 | + |
|
533 | + return $pokemons; |
|
534 | + } |
|
535 | + |
|
536 | + public function getHistoryForGym($page, $gym_id) |
|
537 | + { |
|
538 | + if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
539 | + $pageSize = 25; |
|
540 | + } else { |
|
541 | + $pageSize = 10; |
|
542 | + } |
|
543 | + $req = "SELECT gym_id, team_id, total_cp, pokemon_uids, pokemon_count, |
|
544 | 544 | CONVERT_TZ(last_modified, '+00:00', '".self::$time_offset."') as last_modified |
545 | 545 | FROM gymhistory |
546 | 546 | WHERE gym_id='".$gym_id."' |
547 | 547 | ORDER BY last_modified DESC |
548 | 548 | LIMIT ".($page * $pageSize).','.($pageSize + 1); |
549 | - $result = $this->mysqli->query($req); |
|
550 | - $history = array(); |
|
551 | - $count = 0; |
|
552 | - while ($data = $result->fetch_object()) { |
|
553 | - ++$count; |
|
554 | - $pkm = array(); |
|
555 | - if (0 == $data->total_cp) { |
|
556 | - $data->pokemon_uids = ''; |
|
557 | - $data->pokemon_count = 0; |
|
558 | - } |
|
559 | - if ('' != $data->pokemon_uids) { |
|
560 | - $pkm_uids = explode(',', $data->pokemon_uids); |
|
561 | - $pkm = $this->getHistoryForGymPokemon($pkm_uids); |
|
562 | - } |
|
563 | - $data->pokemon = $pkm; |
|
564 | - $history[] = $data; |
|
565 | - } |
|
566 | - if ($count !== ($pageSize + 1)) { |
|
567 | - $last_page = true; |
|
568 | - } else { |
|
569 | - $last_page = false; |
|
570 | - } |
|
571 | - |
|
572 | - return array('last_page' => $last_page, 'data' => $history); |
|
573 | - } |
|
574 | - |
|
575 | - private function getHistoryForGymPokemon($pkm_uids) |
|
576 | - { |
|
577 | - $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name |
|
549 | + $result = $this->mysqli->query($req); |
|
550 | + $history = array(); |
|
551 | + $count = 0; |
|
552 | + while ($data = $result->fetch_object()) { |
|
553 | + ++$count; |
|
554 | + $pkm = array(); |
|
555 | + if (0 == $data->total_cp) { |
|
556 | + $data->pokemon_uids = ''; |
|
557 | + $data->pokemon_count = 0; |
|
558 | + } |
|
559 | + if ('' != $data->pokemon_uids) { |
|
560 | + $pkm_uids = explode(',', $data->pokemon_uids); |
|
561 | + $pkm = $this->getHistoryForGymPokemon($pkm_uids); |
|
562 | + } |
|
563 | + $data->pokemon = $pkm; |
|
564 | + $history[] = $data; |
|
565 | + } |
|
566 | + if ($count !== ($pageSize + 1)) { |
|
567 | + $last_page = true; |
|
568 | + } else { |
|
569 | + $last_page = false; |
|
570 | + } |
|
571 | + |
|
572 | + return array('last_page' => $last_page, 'data' => $history); |
|
573 | + } |
|
574 | + |
|
575 | + private function getHistoryForGymPokemon($pkm_uids) |
|
576 | + { |
|
577 | + $req = "SELECT DISTINCT pokemon_uid, pokemon_id, cp, trainer_name |
|
578 | 578 | FROM gympokemon |
579 | 579 | WHERE pokemon_uid IN ('".implode("','", $pkm_uids)."') |
580 | 580 | ORDER BY FIND_IN_SET(pokemon_uid, '".implode(',', $pkm_uids)."')"; |
581 | - $result = $this->mysqli->query($req); |
|
582 | - $pokemons = array(); |
|
583 | - while ($data = $result->fetch_object()) { |
|
584 | - $pokemons[$data->pokemon_uid] = $data; |
|
585 | - } |
|
586 | - |
|
587 | - return $pokemons; |
|
588 | - } |
|
589 | - |
|
590 | - /////////// |
|
591 | - // Raids |
|
592 | - /////////// |
|
593 | - |
|
594 | - public function getAllRaids($page) |
|
595 | - { |
|
596 | - $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, |
|
581 | + $result = $this->mysqli->query($req); |
|
582 | + $pokemons = array(); |
|
583 | + while ($data = $result->fetch_object()) { |
|
584 | + $pokemons[$data->pokemon_uid] = $data; |
|
585 | + } |
|
586 | + |
|
587 | + return $pokemons; |
|
588 | + } |
|
589 | + |
|
590 | + /////////// |
|
591 | + // Raids |
|
592 | + /////////// |
|
593 | + |
|
594 | + public function getAllRaids($page) |
|
595 | + { |
|
596 | + $req = "SELECT raid.gym_id, raid.level, raid.pokemon_id, raid.cp, raid.move_1, raid.move_2, |
|
597 | 597 | CONVERT_TZ(raid.spawn, '+00:00', '".self::$time_offset."') AS spawn, |
598 | 598 | CONVERT_TZ(raid.start, '+00:00', '".self::$time_offset."') AS start, |
599 | 599 | CONVERT_TZ(raid.end, '+00:00', '".self::$time_offset."') AS end, |
@@ -605,121 +605,121 @@ discard block |
||
605 | 605 | WHERE raid.end > UTC_TIMESTAMP() |
606 | 606 | ORDER BY raid.level DESC, raid.start |
607 | 607 | LIMIT ".($page * 10).",10"; |
608 | - $result = $this->mysqli->query($req); |
|
609 | - $raids = array(); |
|
610 | - while ($data = $result->fetch_object()) { |
|
611 | - $raids[] = $data; |
|
612 | - } |
|
613 | - |
|
614 | - return $raids; |
|
615 | - } |
|
616 | - |
|
617 | - ////////////// |
|
618 | - // Trainers |
|
619 | - ////////////// |
|
620 | - |
|
621 | - public function getTrainers($trainer_name, $team, $page, $ranking) |
|
622 | - { |
|
623 | - $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
|
624 | - foreach ($trainers as $trainer) { |
|
625 | - $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank; |
|
626 | - $active_gyms = 0; |
|
627 | - $pkmCount = 0; |
|
628 | - $trainer->pokemons = array(); |
|
629 | - $active_pokemon = $this->getTrainerActivePokemon($trainer->name); |
|
630 | - foreach ($active_pokemon as $pokemon) { |
|
631 | - ++$active_gyms; |
|
632 | - $trainer->pokemons[$pkmCount++] = $pokemon; |
|
633 | - } |
|
634 | - $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name); |
|
635 | - foreach ($inactive_pokemon as $pokemon) { |
|
636 | - $trainer->pokemons[$pkmCount++] = $pokemon; |
|
637 | - } |
|
638 | - $trainer->gyms = ''.$active_gyms; |
|
639 | - } |
|
640 | - |
|
641 | - return $trainers; |
|
642 | - } |
|
643 | - |
|
644 | - public function getTrainerLevelCount($team_id) |
|
645 | - { |
|
646 | - $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
|
647 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
648 | - $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
649 | - } |
|
650 | - $req .= ' GROUP BY level'; |
|
651 | - $result = $this->mysqli->query($req); |
|
652 | - $levelData = array(); |
|
653 | - while ($data = $result->fetch_object()) { |
|
654 | - $levelData[$data->level] = $data->count; |
|
655 | - } |
|
656 | - for ($i = 5; $i <= 40; ++$i) { |
|
657 | - if (!isset($levelData[$i])) { |
|
658 | - $levelData[$i] = 0; |
|
659 | - } |
|
660 | - } |
|
661 | - // sort array again |
|
662 | - ksort($levelData); |
|
663 | - |
|
664 | - return $levelData; |
|
665 | - } |
|
666 | - |
|
667 | - private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
668 | - { |
|
669 | - $where = ''; |
|
670 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
671 | - $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
672 | - } |
|
673 | - if ('' != $trainer_name) { |
|
674 | - $where = " HAVING name LIKE '%".$trainer_name."%'"; |
|
675 | - } |
|
676 | - if (0 != $team) { |
|
677 | - $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
678 | - } |
|
679 | - switch ($ranking) { |
|
680 | - case 1: |
|
681 | - $order = ' ORDER BY active DESC, level DESC'; |
|
682 | - break; |
|
683 | - case 2: |
|
684 | - $order = ' ORDER BY maxCp DESC, level DESC'; |
|
685 | - break; |
|
686 | - default: |
|
687 | - $order = ' ORDER BY level DESC, active DESC'; |
|
688 | - } |
|
689 | - $order .= ', last_seen DESC, name '; |
|
690 | - $limit = ' LIMIT '.($page * 10).',10 '; |
|
691 | - $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp |
|
608 | + $result = $this->mysqli->query($req); |
|
609 | + $raids = array(); |
|
610 | + while ($data = $result->fetch_object()) { |
|
611 | + $raids[] = $data; |
|
612 | + } |
|
613 | + |
|
614 | + return $raids; |
|
615 | + } |
|
616 | + |
|
617 | + ////////////// |
|
618 | + // Trainers |
|
619 | + ////////////// |
|
620 | + |
|
621 | + public function getTrainers($trainer_name, $team, $page, $ranking) |
|
622 | + { |
|
623 | + $trainers = $this->getTrainerData($trainer_name, $team, $page, $ranking); |
|
624 | + foreach ($trainers as $trainer) { |
|
625 | + $trainer->rank = $this->getTrainerLevelRating($trainer->level)->rank; |
|
626 | + $active_gyms = 0; |
|
627 | + $pkmCount = 0; |
|
628 | + $trainer->pokemons = array(); |
|
629 | + $active_pokemon = $this->getTrainerActivePokemon($trainer->name); |
|
630 | + foreach ($active_pokemon as $pokemon) { |
|
631 | + ++$active_gyms; |
|
632 | + $trainer->pokemons[$pkmCount++] = $pokemon; |
|
633 | + } |
|
634 | + $inactive_pokemon = $this->getTrainerInactivePokemon($trainer->name); |
|
635 | + foreach ($inactive_pokemon as $pokemon) { |
|
636 | + $trainer->pokemons[$pkmCount++] = $pokemon; |
|
637 | + } |
|
638 | + $trainer->gyms = ''.$active_gyms; |
|
639 | + } |
|
640 | + |
|
641 | + return $trainers; |
|
642 | + } |
|
643 | + |
|
644 | + public function getTrainerLevelCount($team_id) |
|
645 | + { |
|
646 | + $req = "SELECT level, count(level) AS count FROM trainer WHERE team = '".$team_id."'"; |
|
647 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
648 | + $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
649 | + } |
|
650 | + $req .= ' GROUP BY level'; |
|
651 | + $result = $this->mysqli->query($req); |
|
652 | + $levelData = array(); |
|
653 | + while ($data = $result->fetch_object()) { |
|
654 | + $levelData[$data->level] = $data->count; |
|
655 | + } |
|
656 | + for ($i = 5; $i <= 40; ++$i) { |
|
657 | + if (!isset($levelData[$i])) { |
|
658 | + $levelData[$i] = 0; |
|
659 | + } |
|
660 | + } |
|
661 | + // sort array again |
|
662 | + ksort($levelData); |
|
663 | + |
|
664 | + return $levelData; |
|
665 | + } |
|
666 | + |
|
667 | + private function getTrainerData($trainer_name, $team, $page, $ranking) |
|
668 | + { |
|
669 | + $where = ''; |
|
670 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
671 | + $where .= ('' == $where ? ' HAVING' : ' AND')." name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
672 | + } |
|
673 | + if ('' != $trainer_name) { |
|
674 | + $where = " HAVING name LIKE '%".$trainer_name."%'"; |
|
675 | + } |
|
676 | + if (0 != $team) { |
|
677 | + $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
678 | + } |
|
679 | + switch ($ranking) { |
|
680 | + case 1: |
|
681 | + $order = ' ORDER BY active DESC, level DESC'; |
|
682 | + break; |
|
683 | + case 2: |
|
684 | + $order = ' ORDER BY maxCp DESC, level DESC'; |
|
685 | + break; |
|
686 | + default: |
|
687 | + $order = ' ORDER BY level DESC, active DESC'; |
|
688 | + } |
|
689 | + $order .= ', last_seen DESC, name '; |
|
690 | + $limit = ' LIMIT '.($page * 10).',10 '; |
|
691 | + $req = "SELECT trainer.*, COUNT(actives_pokemons.trainer_name) AS active, max(actives_pokemons.cp) AS maxCp |
|
692 | 692 | FROM trainer |
693 | 693 | LEFT JOIN (SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.trainer_name, gympokemon.cp, DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned |
694 | 694 | FROM gympokemon |
695 | 695 | 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 |
696 | 696 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid) AS actives_pokemons ON actives_pokemons.trainer_name = trainer.name |
697 | 697 | GROUP BY trainer.name ".$where.$order.$limit; |
698 | - $result = $this->mysqli->query($req); |
|
699 | - $trainers = array(); |
|
700 | - while ($data = $result->fetch_object()) { |
|
701 | - $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
702 | - $trainers[$data->name] = $data; |
|
703 | - } |
|
704 | - |
|
705 | - return $trainers; |
|
706 | - } |
|
707 | - |
|
708 | - private function getTrainerLevelRating($level) |
|
709 | - { |
|
710 | - $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level; |
|
711 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
712 | - $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
713 | - } |
|
714 | - $result = $this->mysqli->query($req); |
|
715 | - $data = $result->fetch_object(); |
|
716 | - |
|
717 | - return $data; |
|
718 | - } |
|
719 | - |
|
720 | - private function getTrainerActivePokemon($trainer_name) |
|
721 | - { |
|
722 | - $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
698 | + $result = $this->mysqli->query($req); |
|
699 | + $trainers = array(); |
|
700 | + while ($data = $result->fetch_object()) { |
|
701 | + $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
702 | + $trainers[$data->name] = $data; |
|
703 | + } |
|
704 | + |
|
705 | + return $trainers; |
|
706 | + } |
|
707 | + |
|
708 | + private function getTrainerLevelRating($level) |
|
709 | + { |
|
710 | + $req = 'SELECT COUNT(1) AS rank FROM trainer WHERE level = '.$level; |
|
711 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
712 | + $req .= " AND name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
713 | + } |
|
714 | + $result = $this->mysqli->query($req); |
|
715 | + $data = $result->fetch_object(); |
|
716 | + |
|
717 | + return $data; |
|
718 | + } |
|
719 | + |
|
720 | + private function getTrainerActivePokemon($trainer_name) |
|
721 | + { |
|
722 | + $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
723 | 723 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
724 | 724 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
725 | 725 | filtered_gymmember.gym_id, |
@@ -730,18 +730,18 @@ discard block |
||
730 | 730 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
731 | 731 | WHERE gympokemon.trainer_name='".$trainer_name."' |
732 | 732 | ORDER BY gympokemon.cp DESC"; |
733 | - $result = $this->mysqli->query($req); |
|
734 | - $pokemons = array(); |
|
735 | - while ($data = $result->fetch_object()) { |
|
736 | - $pokemons[] = $data; |
|
737 | - } |
|
738 | - |
|
739 | - return $pokemons; |
|
740 | - } |
|
741 | - |
|
742 | - private function getTrainerInactivePokemon($trainer_name) |
|
743 | - { |
|
744 | - $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
733 | + $result = $this->mysqli->query($req); |
|
734 | + $pokemons = array(); |
|
735 | + while ($data = $result->fetch_object()) { |
|
736 | + $pokemons[] = $data; |
|
737 | + } |
|
738 | + |
|
739 | + return $pokemons; |
|
740 | + } |
|
741 | + |
|
742 | + private function getTrainerInactivePokemon($trainer_name) |
|
743 | + { |
|
744 | + $req = "SELECT DISTINCT gympokemon.pokemon_id, gympokemon.pokemon_uid, gympokemon.cp, |
|
745 | 745 | DATEDIFF(UTC_TIMESTAMP(), gympokemon.last_seen) AS last_scanned, |
746 | 746 | gympokemon.trainer_name, gympokemon.iv_defense, gympokemon.iv_stamina, gympokemon.iv_attack, |
747 | 747 | null AS gym_id, |
@@ -752,78 +752,78 @@ discard block |
||
752 | 752 | ON gympokemon.pokemon_uid = filtered_gymmember.pokemon_uid |
753 | 753 | WHERE filtered_gymmember.pokemon_uid IS NULL AND gympokemon.trainer_name='".$trainer_name."' |
754 | 754 | ORDER BY gympokemon.cp DESC"; |
755 | - $result = $this->mysqli->query($req); |
|
756 | - $pokemons = array(); |
|
757 | - while ($data = $result->fetch_object()) { |
|
758 | - $pokemons[] = $data; |
|
759 | - } |
|
760 | - |
|
761 | - return $pokemons; |
|
762 | - } |
|
763 | - |
|
764 | - ///////// |
|
765 | - // Cron |
|
766 | - ///////// |
|
767 | - |
|
768 | - public function getPokemonCountsActive() |
|
769 | - { |
|
770 | - $req = 'SELECT pokemon_id, COUNT(*) as total |
|
755 | + $result = $this->mysqli->query($req); |
|
756 | + $pokemons = array(); |
|
757 | + while ($data = $result->fetch_object()) { |
|
758 | + $pokemons[] = $data; |
|
759 | + } |
|
760 | + |
|
761 | + return $pokemons; |
|
762 | + } |
|
763 | + |
|
764 | + ///////// |
|
765 | + // Cron |
|
766 | + ///////// |
|
767 | + |
|
768 | + public function getPokemonCountsActive() |
|
769 | + { |
|
770 | + $req = 'SELECT pokemon_id, COUNT(*) as total |
|
771 | 771 | FROM pokemon |
772 | 772 | WHERE disappear_time >= UTC_TIMESTAMP() |
773 | 773 | GROUP BY pokemon_id'; |
774 | - $result = $this->mysqli->query($req); |
|
775 | - $counts = array(); |
|
776 | - while ($data = $result->fetch_object()) { |
|
777 | - $counts[$data->pokemon_id] = $data->total; |
|
778 | - } |
|
774 | + $result = $this->mysqli->query($req); |
|
775 | + $counts = array(); |
|
776 | + while ($data = $result->fetch_object()) { |
|
777 | + $counts[$data->pokemon_id] = $data->total; |
|
778 | + } |
|
779 | 779 | |
780 | - return $counts; |
|
781 | - } |
|
780 | + return $counts; |
|
781 | + } |
|
782 | 782 | |
783 | 783 | |
784 | - public function getTotalPokemonIV() |
|
785 | - { |
|
786 | - $req = 'SELECT COUNT(*) as total |
|
784 | + public function getTotalPokemonIV() |
|
785 | + { |
|
786 | + $req = 'SELECT COUNT(*) as total |
|
787 | 787 | FROM pokemon |
788 | 788 | WHERE disappear_time >= UTC_TIMESTAMP() AND cp IS NOT NULL'; |
789 | - $result = $this->mysqli->query($req); |
|
790 | - $data = $result->fetch_object(); |
|
789 | + $result = $this->mysqli->query($req); |
|
790 | + $data = $result->fetch_object(); |
|
791 | 791 | |
792 | - return $data; |
|
793 | - } |
|
792 | + return $data; |
|
793 | + } |
|
794 | 794 | |
795 | - public function getPokemonCountsLastDay() |
|
796 | - { |
|
797 | - $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
795 | + public function getPokemonCountsLastDay() |
|
796 | + { |
|
797 | + $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
798 | 798 | FROM pokemon |
799 | 799 | WHERE disappear_time >= (SELECT MAX(disappear_time) FROM pokemon) - INTERVAL 1 DAY |
800 | 800 | GROUP BY pokemon_id |
801 | 801 | ORDER BY pokemon_id ASC'; |
802 | - $result = $this->mysqli->query($req); |
|
803 | - $counts = array(); |
|
804 | - while ($data = $result->fetch_object()) { |
|
805 | - $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
806 | - } |
|
807 | - |
|
808 | - return $counts; |
|
809 | - } |
|
810 | - |
|
811 | - public function getCaptchaCount() |
|
812 | - { |
|
813 | - $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker'; |
|
814 | - $result = $this->mysqli->query($req); |
|
815 | - $data = $result->fetch_object(); |
|
816 | - |
|
817 | - return $data; |
|
818 | - } |
|
819 | - |
|
820 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
821 | - { |
|
822 | - $pokemon_exclude_sql = ''; |
|
823 | - if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
824 | - $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
825 | - } |
|
826 | - $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon, |
|
802 | + $result = $this->mysqli->query($req); |
|
803 | + $counts = array(); |
|
804 | + while ($data = $result->fetch_object()) { |
|
805 | + $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
806 | + } |
|
807 | + |
|
808 | + return $counts; |
|
809 | + } |
|
810 | + |
|
811 | + public function getCaptchaCount() |
|
812 | + { |
|
813 | + $req = 'SELECT SUM(accounts_captcha) AS total FROM mainworker'; |
|
814 | + $result = $this->mysqli->query($req); |
|
815 | + $data = $result->fetch_object(); |
|
816 | + |
|
817 | + return $data; |
|
818 | + } |
|
819 | + |
|
820 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
821 | + { |
|
822 | + $pokemon_exclude_sql = ''; |
|
823 | + if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
824 | + $pokemon_exclude_sql = 'AND pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
825 | + } |
|
826 | + $req = 'SELECT spawnpoint_id, pokemon_id, MAX(latitude) AS latitude, MAX(longitude) AS longitude, count(pokemon_id) AS total_pokemon, |
|
827 | 827 | MAX(UNIX_TIMESTAMP(disappear_time)) as latest_seen |
828 | 828 | FROM pokemon |
829 | 829 | WHERE disappear_time > (UTC_TIMESTAMP() - INTERVAL '.$time.' HOUR) |
@@ -832,23 +832,23 @@ discard block |
||
832 | 832 | GROUP BY spawnpoint_id, pokemon_id |
833 | 833 | HAVING COUNT(pokemon_id) >= '.($time / 4).' |
834 | 834 | ORDER BY pokemon_id'; |
835 | - $result = $this->mysqli->query($req); |
|
836 | - $nests = array(); |
|
837 | - while ($data = $result->fetch_object()) { |
|
838 | - $nests[] = $data; |
|
839 | - } |
|
840 | - |
|
841 | - return $nests; |
|
842 | - } |
|
843 | - |
|
844 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
845 | - { |
|
846 | - $req = 'SELECT COUNT(*) as total |
|
835 | + $result = $this->mysqli->query($req); |
|
836 | + $nests = array(); |
|
837 | + while ($data = $result->fetch_object()) { |
|
838 | + $nests[] = $data; |
|
839 | + } |
|
840 | + |
|
841 | + return $nests; |
|
842 | + } |
|
843 | + |
|
844 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
845 | + { |
|
846 | + $req = 'SELECT COUNT(*) as total |
|
847 | 847 | FROM spawnpoint |
848 | 848 | WHERE latitude >= '.$minLatitude.' AND latitude < '.$maxLatitude.' AND longitude >= '.$minLongitude.' AND longitude < '.$maxLongitude; |
849 | - $result = $this->mysqli->query($req); |
|
850 | - $data = $result->fetch_object(); |
|
849 | + $result = $this->mysqli->query($req); |
|
850 | + $data = $result->fetch_object(); |
|
851 | 851 | |
852 | - return $data; |
|
853 | - } |
|
852 | + return $data; |
|
853 | + } |
|
854 | 854 | } |
@@ -4,193 +4,193 @@ discard block |
||
4 | 4 | |
5 | 5 | class QueryManagerMysqlMonocleAlternate extends QueryManagerMysql |
6 | 6 | { |
7 | - public function __construct() |
|
8 | - { |
|
9 | - parent::__construct(); |
|
10 | - } |
|
11 | - |
|
12 | - public function __destruct() |
|
13 | - { |
|
14 | - parent::__destruct(); |
|
15 | - } |
|
16 | - |
|
17 | - /////////// |
|
18 | - // Tester |
|
19 | - /////////// |
|
20 | - |
|
21 | - public function testTotalPokemon() |
|
22 | - { |
|
23 | - $req = 'SELECT COUNT(*) as total FROM sightings'; |
|
24 | - $result = $this->mysqli->query($req); |
|
25 | - if (!is_object($result)) { |
|
26 | - return 1; |
|
27 | - } else { |
|
28 | - $data = $result->fetch_object(); |
|
29 | - $total = $data->total; |
|
30 | - |
|
31 | - if (0 == $total) { |
|
32 | - return 2; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - return 0; |
|
37 | - } |
|
38 | - |
|
39 | - public function testTotalGyms() |
|
40 | - { |
|
41 | - $req = 'SELECT COUNT(*) as total FROM forts'; |
|
42 | - $result = $this->mysqli->query($req); |
|
43 | - if (!is_object($result)) { |
|
44 | - return 1; |
|
45 | - } else { |
|
46 | - $data = $result->fetch_object(); |
|
47 | - $total = $data->total; |
|
48 | - |
|
49 | - if (0 == $total) { |
|
50 | - return 2; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return 0; |
|
55 | - } |
|
56 | - |
|
57 | - public function testTotalPokestops() |
|
58 | - { |
|
59 | - $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
60 | - $result = $this->mysqli->query($req); |
|
61 | - if (!is_object($result)) { |
|
62 | - return 1; |
|
63 | - } else { |
|
64 | - $data = $result->fetch_object(); |
|
65 | - $total = $data->total; |
|
66 | - |
|
67 | - if (0 == $total) { |
|
68 | - return 2; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return 0; |
|
73 | - } |
|
74 | - |
|
75 | - ///////////// |
|
76 | - // Homepage |
|
77 | - ///////////// |
|
78 | - |
|
79 | - public function getTotalPokemon() |
|
80 | - { |
|
81 | - $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()'; |
|
82 | - $result = $this->mysqli->query($req); |
|
83 | - $data = $result->fetch_object(); |
|
84 | - |
|
85 | - return $data; |
|
86 | - } |
|
87 | - |
|
88 | - public function getTotalLures() |
|
89 | - { |
|
90 | - $data = (object) array('total' => 0); |
|
91 | - |
|
92 | - return $data; |
|
93 | - } |
|
94 | - |
|
95 | - public function getTotalGyms() |
|
96 | - { |
|
97 | - $req = 'SELECT COUNT(*) AS total FROM forts'; |
|
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 raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_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(*) AS total |
|
7 | + public function __construct() |
|
8 | + { |
|
9 | + parent::__construct(); |
|
10 | + } |
|
11 | + |
|
12 | + public function __destruct() |
|
13 | + { |
|
14 | + parent::__destruct(); |
|
15 | + } |
|
16 | + |
|
17 | + /////////// |
|
18 | + // Tester |
|
19 | + /////////// |
|
20 | + |
|
21 | + public function testTotalPokemon() |
|
22 | + { |
|
23 | + $req = 'SELECT COUNT(*) as total FROM sightings'; |
|
24 | + $result = $this->mysqli->query($req); |
|
25 | + if (!is_object($result)) { |
|
26 | + return 1; |
|
27 | + } else { |
|
28 | + $data = $result->fetch_object(); |
|
29 | + $total = $data->total; |
|
30 | + |
|
31 | + if (0 == $total) { |
|
32 | + return 2; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + return 0; |
|
37 | + } |
|
38 | + |
|
39 | + public function testTotalGyms() |
|
40 | + { |
|
41 | + $req = 'SELECT COUNT(*) as total FROM forts'; |
|
42 | + $result = $this->mysqli->query($req); |
|
43 | + if (!is_object($result)) { |
|
44 | + return 1; |
|
45 | + } else { |
|
46 | + $data = $result->fetch_object(); |
|
47 | + $total = $data->total; |
|
48 | + |
|
49 | + if (0 == $total) { |
|
50 | + return 2; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return 0; |
|
55 | + } |
|
56 | + |
|
57 | + public function testTotalPokestops() |
|
58 | + { |
|
59 | + $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
60 | + $result = $this->mysqli->query($req); |
|
61 | + if (!is_object($result)) { |
|
62 | + return 1; |
|
63 | + } else { |
|
64 | + $data = $result->fetch_object(); |
|
65 | + $total = $data->total; |
|
66 | + |
|
67 | + if (0 == $total) { |
|
68 | + return 2; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return 0; |
|
73 | + } |
|
74 | + |
|
75 | + ///////////// |
|
76 | + // Homepage |
|
77 | + ///////////// |
|
78 | + |
|
79 | + public function getTotalPokemon() |
|
80 | + { |
|
81 | + $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP()'; |
|
82 | + $result = $this->mysqli->query($req); |
|
83 | + $data = $result->fetch_object(); |
|
84 | + |
|
85 | + return $data; |
|
86 | + } |
|
87 | + |
|
88 | + public function getTotalLures() |
|
89 | + { |
|
90 | + $data = (object) array('total' => 0); |
|
91 | + |
|
92 | + return $data; |
|
93 | + } |
|
94 | + |
|
95 | + public function getTotalGyms() |
|
96 | + { |
|
97 | + $req = 'SELECT COUNT(*) AS total FROM forts'; |
|
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 raids WHERE time_battle <= UNIX_TIMESTAMP() AND time_end >= UNIX_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(*) AS total |
|
116 | 116 | FROM forts f |
117 | 117 | 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)) |
118 | 118 | WHERE team = '$team_id'"; |
119 | - $result = $this->mysqli->query($req); |
|
120 | - $data = $result->fetch_object(); |
|
119 | + $result = $this->mysqli->query($req); |
|
120 | + $data = $result->fetch_object(); |
|
121 | 121 | |
122 | - return $data; |
|
123 | - } |
|
122 | + return $data; |
|
123 | + } |
|
124 | 124 | |
125 | - public function getRecentAll() |
|
126 | - { |
|
127 | - $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, |
|
125 | + public function getRecentAll() |
|
126 | + { |
|
127 | + $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, |
|
128 | 128 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
129 | 129 | FROM sightings |
130 | 130 | ORDER BY updated DESC |
131 | 131 | LIMIT 0,12'; |
132 | - $result = $this->mysqli->query($req); |
|
133 | - $data = array(); |
|
134 | - if ($result->num_rows > 0) { |
|
135 | - while ($row = $result->fetch_object()) { |
|
136 | - $data[] = $row; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $data; |
|
141 | - } |
|
142 | - |
|
143 | - public function getRecentMythic($mythic_pokemon) |
|
144 | - { |
|
145 | - $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, |
|
132 | + $result = $this->mysqli->query($req); |
|
133 | + $data = array(); |
|
134 | + if ($result->num_rows > 0) { |
|
135 | + while ($row = $result->fetch_object()) { |
|
136 | + $data[] = $row; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $data; |
|
141 | + } |
|
142 | + |
|
143 | + public function getRecentMythic($mythic_pokemon) |
|
144 | + { |
|
145 | + $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, |
|
146 | 146 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
147 | 147 | FROM sightings |
148 | 148 | WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).') |
149 | 149 | ORDER BY updated DESC |
150 | 150 | LIMIT 0,12'; |
151 | - $result = $this->mysqli->query($req); |
|
152 | - $data = array(); |
|
153 | - if ($result->num_rows > 0) { |
|
154 | - while ($row = $result->fetch_object()) { |
|
155 | - $data[] = $row; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - return $data; |
|
160 | - } |
|
161 | - |
|
162 | - /////////////////// |
|
163 | - // Single Pokemon |
|
164 | - /////////////////// |
|
165 | - |
|
166 | - public function getGymsProtectedByPokemon($pokemon_id) |
|
167 | - { |
|
168 | - $req = "SELECT COUNT(f.id) AS total |
|
151 | + $result = $this->mysqli->query($req); |
|
152 | + $data = array(); |
|
153 | + if ($result->num_rows > 0) { |
|
154 | + while ($row = $result->fetch_object()) { |
|
155 | + $data[] = $row; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + return $data; |
|
160 | + } |
|
161 | + |
|
162 | + /////////////////// |
|
163 | + // Single Pokemon |
|
164 | + /////////////////// |
|
165 | + |
|
166 | + public function getGymsProtectedByPokemon($pokemon_id) |
|
167 | + { |
|
168 | + $req = "SELECT COUNT(f.id) AS total |
|
169 | 169 | FROM forts f |
170 | 170 | 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)) |
171 | 171 | WHERE guard_pokemon_id = '".$pokemon_id."'"; |
172 | - $result = $this->mysqli->query($req); |
|
173 | - $data = $result->fetch_object(); |
|
172 | + $result = $this->mysqli->query($req); |
|
173 | + $data = $result->fetch_object(); |
|
174 | 174 | |
175 | - return $data; |
|
176 | - } |
|
175 | + return $data; |
|
176 | + } |
|
177 | 177 | |
178 | - public function getPokemonLastSeen($pokemon_id) |
|
179 | - { |
|
180 | - $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
178 | + public function getPokemonLastSeen($pokemon_id) |
|
179 | + { |
|
180 | + $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
181 | 181 | FROM sightings |
182 | 182 | WHERE pokemon_id = '".$pokemon_id."' |
183 | 183 | ORDER BY expire_timestamp DESC |
184 | 184 | LIMIT 0,1"; |
185 | - $result = $this->mysqli->query($req); |
|
186 | - $data = $result->fetch_object(); |
|
185 | + $result = $this->mysqli->query($req); |
|
186 | + $data = $result->fetch_object(); |
|
187 | 187 | |
188 | - return $data; |
|
189 | - } |
|
188 | + return $data; |
|
189 | + } |
|
190 | 190 | |
191 | - public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | - { |
|
193 | - $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, |
|
191 | + public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | + { |
|
193 | + $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, |
|
194 | 194 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
195 | 195 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS IV, move_1 as move_1, move_2, form |
196 | 196 | FROM sightings |
@@ -198,435 +198,435 @@ discard block |
||
198 | 198 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
199 | 199 | LIMIT 0,50"; |
200 | 200 | |
201 | - $result = $this->mysqli->query($req); |
|
202 | - $top = array(); |
|
203 | - while ($data = $result->fetch_object()) { |
|
204 | - $top[] = $data; |
|
205 | - } |
|
201 | + $result = $this->mysqli->query($req); |
|
202 | + $top = array(); |
|
203 | + while ($data = $result->fetch_object()) { |
|
204 | + $top[] = $data; |
|
205 | + } |
|
206 | 206 | |
207 | - return $top; |
|
208 | - } |
|
207 | + return $top; |
|
208 | + } |
|
209 | 209 | |
210 | - public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
211 | - { |
|
212 | - $trainer_blacklist = ''; |
|
213 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
214 | - $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
215 | - } |
|
210 | + public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
211 | + { |
|
212 | + $trainer_blacklist = ''; |
|
213 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
214 | + $trainer_blacklist = " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
215 | + } |
|
216 | 216 | |
217 | - $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, |
|
217 | + $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, |
|
218 | 218 | FROM_UNIXTIME(last_modified) AS lasttime, last_modified as last_seen |
219 | 219 | FROM gym_defenders |
220 | 220 | WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist." |
221 | 221 | ORDER BY $best_order_by $best_direction, owner_name ASC |
222 | 222 | LIMIT 0,50"; |
223 | 223 | |
224 | - $result = $this->mysqli->query($req); |
|
225 | - $toptrainer = array(); |
|
226 | - while ($data = $result->fetch_object()) { |
|
227 | - $toptrainer[] = $data; |
|
228 | - } |
|
229 | - |
|
230 | - return $toptrainer; |
|
231 | - } |
|
232 | - |
|
233 | - public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
234 | - { |
|
235 | - $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
236 | - ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
237 | - $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000'; |
|
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, HOUR(disappear_time) AS disappear_hour |
|
224 | + $result = $this->mysqli->query($req); |
|
225 | + $toptrainer = array(); |
|
226 | + while ($data = $result->fetch_object()) { |
|
227 | + $toptrainer[] = $data; |
|
228 | + } |
|
229 | + |
|
230 | + return $toptrainer; |
|
231 | + } |
|
232 | + |
|
233 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
234 | + { |
|
235 | + $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
236 | + ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
237 | + $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000'; |
|
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, HOUR(disappear_time) AS disappear_hour |
|
250 | 250 | FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
251 | 251 | GROUP BY disappear_hour |
252 | 252 | ORDER BY disappear_hour"; |
253 | - $result = $this->mysqli->query($req); |
|
254 | - $array = array_fill(0, 24, 0); |
|
255 | - while ($result && $data = $result->fetch_object()) { |
|
256 | - $array[$data->disappear_hour] = $data->total; |
|
257 | - } |
|
258 | - // shift array because AM/PM starts at 1AM not 0:00 |
|
259 | - $array[] = $array[0]; |
|
260 | - array_shift($array); |
|
261 | - |
|
262 | - return $array; |
|
263 | - } |
|
264 | - |
|
265 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
266 | - { |
|
267 | - $inmap_pkms_filter = ''; |
|
268 | - $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
269 | - |
|
270 | - $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$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)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') '; |
|
282 | - } |
|
283 | - if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
284 | - $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') '; |
|
285 | - } |
|
286 | - $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
253 | + $result = $this->mysqli->query($req); |
|
254 | + $array = array_fill(0, 24, 0); |
|
255 | + while ($result && $data = $result->fetch_object()) { |
|
256 | + $array[$data->disappear_hour] = $data->total; |
|
257 | + } |
|
258 | + // shift array because AM/PM starts at 1AM not 0:00 |
|
259 | + $array[] = $array[0]; |
|
260 | + array_shift($array); |
|
261 | + |
|
262 | + return $array; |
|
263 | + } |
|
264 | + |
|
265 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
266 | + { |
|
267 | + $inmap_pkms_filter = ''; |
|
268 | + $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
269 | + |
|
270 | + $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$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)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') '; |
|
282 | + } |
|
283 | + if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
284 | + $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') '; |
|
285 | + } |
|
286 | + $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
287 | 287 | FROM_UNIXTIME(expire_timestamp) AS disappear_time, |
288 | 288 | FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
289 | 289 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
290 | 290 | move_1, move_2 |
291 | 291 | FROM sightings '.$where.' |
292 | 292 | LIMIT 5000'; |
293 | - $result = $this->mysqli->query($req); |
|
294 | - $spawns = array(); |
|
295 | - while ($data = $result->fetch_object()) { |
|
296 | - $spawns[] = $data; |
|
297 | - } |
|
298 | - |
|
299 | - return $spawns; |
|
300 | - } |
|
301 | - |
|
302 | - public function getPokemonSliderMinMax() |
|
303 | - { |
|
304 | - $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings'; |
|
305 | - $result = $this->mysqli->query($req); |
|
306 | - $data = $result->fetch_object(); |
|
307 | - |
|
308 | - return $data; |
|
309 | - } |
|
310 | - |
|
311 | - public function getMapsCoords() |
|
312 | - { |
|
313 | - $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints'; |
|
314 | - $result = $this->mysqli->query($req); |
|
315 | - $data = $result->fetch_object(); |
|
316 | - |
|
317 | - return $data; |
|
318 | - } |
|
319 | - |
|
320 | - public function getPokemonCount($pokemon_id) |
|
321 | - { |
|
322 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
293 | + $result = $this->mysqli->query($req); |
|
294 | + $spawns = array(); |
|
295 | + while ($data = $result->fetch_object()) { |
|
296 | + $spawns[] = $data; |
|
297 | + } |
|
298 | + |
|
299 | + return $spawns; |
|
300 | + } |
|
301 | + |
|
302 | + public function getPokemonSliderMinMax() |
|
303 | + { |
|
304 | + $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM sightings'; |
|
305 | + $result = $this->mysqli->query($req); |
|
306 | + $data = $result->fetch_object(); |
|
307 | + |
|
308 | + return $data; |
|
309 | + } |
|
310 | + |
|
311 | + public function getMapsCoords() |
|
312 | + { |
|
313 | + $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints'; |
|
314 | + $result = $this->mysqli->query($req); |
|
315 | + $data = $result->fetch_object(); |
|
316 | + |
|
317 | + return $data; |
|
318 | + } |
|
319 | + |
|
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 getPokemonCountAll() |
|
332 | - { |
|
333 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
331 | + public function getPokemonCountAll() |
|
332 | + { |
|
333 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
334 | 334 | FROM pokemon_stats |
335 | 335 | GROUP BY pid'; |
336 | - $result = $this->mysqli->query($req); |
|
337 | - $array = array(); |
|
338 | - while ($data = $result->fetch_object()) { |
|
339 | - $array[] = $data; |
|
340 | - } |
|
341 | - |
|
342 | - return $array; |
|
343 | - } |
|
344 | - |
|
345 | - public function getRaidCount($pokemon_id) |
|
346 | - { |
|
347 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
336 | + $result = $this->mysqli->query($req); |
|
337 | + $array = array(); |
|
338 | + while ($data = $result->fetch_object()) { |
|
339 | + $array[] = $data; |
|
340 | + } |
|
341 | + |
|
342 | + return $array; |
|
343 | + } |
|
344 | + |
|
345 | + public function getRaidCount($pokemon_id) |
|
346 | + { |
|
347 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
348 | 348 | FROM raid_stats |
349 | 349 | WHERE pid = '.$pokemon_id; |
350 | - $result = $this->mysqli->query($req); |
|
351 | - $data = $result->fetch_object(); |
|
350 | + $result = $this->mysqli->query($req); |
|
351 | + $data = $result->fetch_object(); |
|
352 | 352 | |
353 | - return $data; |
|
354 | - } |
|
353 | + return $data; |
|
354 | + } |
|
355 | 355 | |
356 | - public function getRaidCountAll() |
|
357 | - { |
|
358 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
356 | + public function getRaidCountAll() |
|
357 | + { |
|
358 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
359 | 359 | FROM raid_stats |
360 | 360 | GROUP BY pid'; |
361 | - $result = $this->mysqli->query($req); |
|
362 | - $array = array(); |
|
363 | - while ($data = $result->fetch_object()) { |
|
364 | - $array[] = $data; |
|
365 | - } |
|
366 | - |
|
367 | - return $array; |
|
368 | - } |
|
369 | - |
|
370 | - /////////////// |
|
371 | - // Pokestops |
|
372 | - ////////////// |
|
373 | - |
|
374 | - public function getTotalPokestops() |
|
375 | - { |
|
376 | - $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
377 | - $result = $this->mysqli->query($req); |
|
378 | - $data = $result->fetch_object(); |
|
379 | - |
|
380 | - return $data; |
|
381 | - } |
|
382 | - |
|
383 | - public function getAllPokestops() |
|
384 | - { |
|
385 | - $req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops'; |
|
386 | - $result = $this->mysqli->query($req); |
|
387 | - $pokestops = array(); |
|
388 | - while ($data = $result->fetch_object()) { |
|
389 | - $pokestops[] = $data; |
|
390 | - } |
|
391 | - |
|
392 | - return $pokestops; |
|
393 | - } |
|
394 | - |
|
395 | - ///////// |
|
396 | - // Gyms |
|
397 | - ///////// |
|
398 | - |
|
399 | - public function getTeamGuardians($team_id) |
|
400 | - { |
|
401 | - $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
361 | + $result = $this->mysqli->query($req); |
|
362 | + $array = array(); |
|
363 | + while ($data = $result->fetch_object()) { |
|
364 | + $array[] = $data; |
|
365 | + } |
|
366 | + |
|
367 | + return $array; |
|
368 | + } |
|
369 | + |
|
370 | + /////////////// |
|
371 | + // Pokestops |
|
372 | + ////////////// |
|
373 | + |
|
374 | + public function getTotalPokestops() |
|
375 | + { |
|
376 | + $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
377 | + $result = $this->mysqli->query($req); |
|
378 | + $data = $result->fetch_object(); |
|
379 | + |
|
380 | + return $data; |
|
381 | + } |
|
382 | + |
|
383 | + public function getAllPokestops() |
|
384 | + { |
|
385 | + $req = 'SELECT lat as latitude, lon as longitude, null AS lure_expiration, UNIX_TIMESTAMP() AS now, null AS lure_expiration_real FROM pokestops'; |
|
386 | + $result = $this->mysqli->query($req); |
|
387 | + $pokestops = array(); |
|
388 | + while ($data = $result->fetch_object()) { |
|
389 | + $pokestops[] = $data; |
|
390 | + } |
|
391 | + |
|
392 | + return $pokestops; |
|
393 | + } |
|
394 | + |
|
395 | + ///////// |
|
396 | + // Gyms |
|
397 | + ///////// |
|
398 | + |
|
399 | + public function getTeamGuardians($team_id) |
|
400 | + { |
|
401 | + $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
402 | 402 | FROM forts f |
403 | 403 | 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)) |
404 | 404 | WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 0,3"; |
405 | - $result = $this->mysqli->query($req); |
|
405 | + $result = $this->mysqli->query($req); |
|
406 | 406 | |
407 | - $datas = array(); |
|
408 | - while ($data = $result->fetch_object()) { |
|
409 | - $datas[] = $data; |
|
410 | - } |
|
407 | + $datas = array(); |
|
408 | + while ($data = $result->fetch_object()) { |
|
409 | + $datas[] = $data; |
|
410 | + } |
|
411 | 411 | |
412 | - return $datas; |
|
413 | - } |
|
412 | + return $datas; |
|
413 | + } |
|
414 | 414 | |
415 | - public function getOwnedAndPoints($team_id) |
|
416 | - { |
|
417 | - $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points |
|
415 | + public function getOwnedAndPoints($team_id) |
|
416 | + { |
|
417 | + $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp)) AS average_points |
|
418 | 418 | FROM forts f |
419 | 419 | 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)) |
420 | 420 | WHERE fs.team = '".$team_id."'"; |
421 | - $result = $this->mysqli->query($req); |
|
422 | - $data = $result->fetch_object(); |
|
421 | + $result = $this->mysqli->query($req); |
|
422 | + $data = $result->fetch_object(); |
|
423 | 423 | |
424 | - return $data; |
|
425 | - } |
|
424 | + return $data; |
|
425 | + } |
|
426 | 426 | |
427 | - public function getAllGyms() |
|
428 | - { |
|
429 | - $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 |
|
427 | + public function getAllGyms() |
|
428 | + { |
|
429 | + $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 |
|
430 | 430 | FROM forts f |
431 | 431 | 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));'; |
432 | - $result = $this->mysqli->query($req); |
|
433 | - $gyms = array(); |
|
434 | - while ($data = $result->fetch_object()) { |
|
435 | - $gyms[] = $data; |
|
436 | - } |
|
437 | - |
|
438 | - return $gyms; |
|
439 | - } |
|
440 | - |
|
441 | - public function getGymData($gym_id) |
|
442 | - { |
|
443 | - $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 |
|
432 | + $result = $this->mysqli->query($req); |
|
433 | + $gyms = array(); |
|
434 | + while ($data = $result->fetch_object()) { |
|
435 | + $gyms[] = $data; |
|
436 | + } |
|
437 | + |
|
438 | + return $gyms; |
|
439 | + } |
|
440 | + |
|
441 | + public function getGymData($gym_id) |
|
442 | + { |
|
443 | + $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 |
|
444 | 444 | FROM forts f |
445 | 445 | 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)) |
446 | 446 | WHERE f.id ='".$gym_id."'"; |
447 | - $result = $this->mysqli->query($req); |
|
448 | - $data = $result->fetch_object(); |
|
447 | + $result = $this->mysqli->query($req); |
|
448 | + $data = $result->fetch_object(); |
|
449 | 449 | |
450 | - return $data; |
|
451 | - } |
|
450 | + return $data; |
|
451 | + } |
|
452 | 452 | |
453 | - public function getGymDefenders($gym_id) |
|
454 | - { |
|
455 | - $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 |
|
453 | + public function getGymDefenders($gym_id) |
|
454 | + { |
|
455 | + $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 |
|
456 | 456 | FROM gym_defenders |
457 | 457 | WHERE fort_id='".$gym_id."' |
458 | 458 | ORDER BY deployment_time"; |
459 | - $result = $this->mysqli->query($req); |
|
460 | - $defenders = array(); |
|
461 | - while ($data = $result->fetch_object()) { |
|
462 | - $defenders[] = $data; |
|
463 | - } |
|
464 | - |
|
465 | - return $defenders; |
|
466 | - } |
|
467 | - |
|
468 | - /////////// |
|
469 | - // Raids |
|
470 | - /////////// |
|
471 | - |
|
472 | - public function getAllRaids($page) |
|
473 | - { |
|
474 | - $limit = ' LIMIT '.($page * 10).',10'; |
|
475 | - $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 |
|
459 | + $result = $this->mysqli->query($req); |
|
460 | + $defenders = array(); |
|
461 | + while ($data = $result->fetch_object()) { |
|
462 | + $defenders[] = $data; |
|
463 | + } |
|
464 | + |
|
465 | + return $defenders; |
|
466 | + } |
|
467 | + |
|
468 | + /////////// |
|
469 | + // Raids |
|
470 | + /////////// |
|
471 | + |
|
472 | + public function getAllRaids($page) |
|
473 | + { |
|
474 | + $limit = ' LIMIT '.($page * 10).',10'; |
|
475 | + $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 |
|
476 | 476 | FROM forts f |
477 | 477 | 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)) |
478 | 478 | LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP()) |
479 | 479 | WHERE r.time_end > UNIX_TIMESTAMP() |
480 | 480 | ORDER BY r.level DESC, r.time_battle'.$limit; |
481 | - $result = $this->mysqli->query($req); |
|
482 | - $raids = array(); |
|
483 | - while ($data = $result->fetch_object()) { |
|
484 | - $raids[] = $data; |
|
485 | - } |
|
486 | - |
|
487 | - return $raids; |
|
488 | - } |
|
489 | - |
|
490 | - //////////////// |
|
491 | - // Gym History |
|
492 | - //////////////// |
|
493 | - |
|
494 | - public function getGymHistories($gym_name, $team, $page, $ranking) |
|
495 | - { |
|
496 | - $where = ''; |
|
497 | - if (isset($gym_name) && '' != $gym_name) { |
|
498 | - $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
499 | - } |
|
500 | - if (isset($team) && '' != $team) { |
|
501 | - $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team; |
|
502 | - } |
|
503 | - switch ($ranking) { |
|
504 | - case 1: |
|
505 | - $order = ' ORDER BY name, last_modified DESC'; |
|
506 | - break; |
|
507 | - case 2: |
|
508 | - $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
509 | - break; |
|
510 | - default: |
|
511 | - $order = ' ORDER BY last_modified DESC, name'; |
|
512 | - } |
|
513 | - |
|
514 | - $limit = ' LIMIT '.($page * 10).',10'; |
|
515 | - |
|
516 | - $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 |
|
481 | + $result = $this->mysqli->query($req); |
|
482 | + $raids = array(); |
|
483 | + while ($data = $result->fetch_object()) { |
|
484 | + $raids[] = $data; |
|
485 | + } |
|
486 | + |
|
487 | + return $raids; |
|
488 | + } |
|
489 | + |
|
490 | + //////////////// |
|
491 | + // Gym History |
|
492 | + //////////////// |
|
493 | + |
|
494 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
495 | + { |
|
496 | + $where = ''; |
|
497 | + if (isset($gym_name) && '' != $gym_name) { |
|
498 | + $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
499 | + } |
|
500 | + if (isset($team) && '' != $team) { |
|
501 | + $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team; |
|
502 | + } |
|
503 | + switch ($ranking) { |
|
504 | + case 1: |
|
505 | + $order = ' ORDER BY name, last_modified DESC'; |
|
506 | + break; |
|
507 | + case 2: |
|
508 | + $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
509 | + break; |
|
510 | + default: |
|
511 | + $order = ' ORDER BY last_modified DESC, name'; |
|
512 | + } |
|
513 | + |
|
514 | + $limit = ' LIMIT '.($page * 10).',10'; |
|
515 | + |
|
516 | + $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 |
|
517 | 517 | FROM forts f |
518 | 518 | 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)) |
519 | 519 | '.$where.$order.$limit; |
520 | - $result = $this->mysqli->query($req); |
|
521 | - $gym_history = array(); |
|
522 | - while ($data = $result->fetch_object()) { |
|
523 | - $gym_history[] = $data; |
|
524 | - } |
|
525 | - |
|
526 | - return $gym_history; |
|
527 | - } |
|
528 | - |
|
529 | - public function getGymHistoriesPokemon($gym_id) |
|
530 | - { |
|
531 | - $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
|
520 | + $result = $this->mysqli->query($req); |
|
521 | + $gym_history = array(); |
|
522 | + while ($data = $result->fetch_object()) { |
|
523 | + $gym_history[] = $data; |
|
524 | + } |
|
525 | + |
|
526 | + return $gym_history; |
|
527 | + } |
|
528 | + |
|
529 | + public function getGymHistoriesPokemon($gym_id) |
|
530 | + { |
|
531 | + $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
|
532 | 532 | FROM gym_defenders |
533 | 533 | WHERE fort_id = '".$gym_id."' |
534 | 534 | ORDER BY deployment_time"; |
535 | - $result = $this->mysqli->query($req); |
|
536 | - $pokemons = array(); |
|
537 | - while ($data = $result->fetch_object()) { |
|
538 | - $pokemons[] = $data; |
|
539 | - } |
|
540 | - |
|
541 | - return $pokemons; |
|
542 | - } |
|
543 | - |
|
544 | - public function getHistoryForGym($page, $gym_id) |
|
545 | - { |
|
546 | - if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
547 | - $pageSize = 25; |
|
548 | - } else { |
|
549 | - $pageSize = 10; |
|
550 | - } |
|
551 | - $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 |
|
535 | + $result = $this->mysqli->query($req); |
|
536 | + $pokemons = array(); |
|
537 | + while ($data = $result->fetch_object()) { |
|
538 | + $pokemons[] = $data; |
|
539 | + } |
|
540 | + |
|
541 | + return $pokemons; |
|
542 | + } |
|
543 | + |
|
544 | + public function getHistoryForGym($page, $gym_id) |
|
545 | + { |
|
546 | + if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
547 | + $pageSize = 25; |
|
548 | + } else { |
|
549 | + $pageSize = 10; |
|
550 | + } |
|
551 | + $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 |
|
552 | 552 | FROM fort_sightings fs |
553 | 553 | LEFT JOIN forts f ON f.id = fs.fort_id |
554 | 554 | WHERE f.id = '".$gym_id."' |
555 | 555 | ORDER BY fs.last_modified DESC |
556 | 556 | LIMIT ".($page * $pageSize).','.($pageSize + 1); |
557 | - $result = $this->mysqli->query($req); |
|
558 | - $history = array(); |
|
559 | - $count = 0; |
|
560 | - while ($data = $result->fetch_object()) { |
|
561 | - ++$count; |
|
562 | - if (0 == $data->total_cp) { |
|
563 | - $data->pokemon = array(); |
|
564 | - $data->pokemon_count = 0; |
|
565 | - $data->pokemon_uids = ''; |
|
566 | - } else { |
|
567 | - $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
568 | - $data->pokemon_count = count($data->pokemon); |
|
569 | - $data->pokemon_uids = implode(',', array_keys($data->pokemon)); |
|
570 | - } |
|
571 | - if (0 === $data->total_cp || 0 !== $data->pokemon_count) { |
|
572 | - $history[] = $data; |
|
573 | - } |
|
574 | - } |
|
575 | - if ($count !== ($pageSize + 1)) { |
|
576 | - $last_page = true; |
|
577 | - } else { |
|
578 | - $last_page = false; |
|
579 | - } |
|
580 | - |
|
581 | - return array('last_page' => $last_page, 'data' => $history); |
|
582 | - } |
|
583 | - |
|
584 | - private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
585 | - { |
|
586 | - $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
557 | + $result = $this->mysqli->query($req); |
|
558 | + $history = array(); |
|
559 | + $count = 0; |
|
560 | + while ($data = $result->fetch_object()) { |
|
561 | + ++$count; |
|
562 | + if (0 == $data->total_cp) { |
|
563 | + $data->pokemon = array(); |
|
564 | + $data->pokemon_count = 0; |
|
565 | + $data->pokemon_uids = ''; |
|
566 | + } else { |
|
567 | + $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
568 | + $data->pokemon_count = count($data->pokemon); |
|
569 | + $data->pokemon_uids = implode(',', array_keys($data->pokemon)); |
|
570 | + } |
|
571 | + if (0 === $data->total_cp || 0 !== $data->pokemon_count) { |
|
572 | + $history[] = $data; |
|
573 | + } |
|
574 | + } |
|
575 | + if ($count !== ($pageSize + 1)) { |
|
576 | + $last_page = true; |
|
577 | + } else { |
|
578 | + $last_page = false; |
|
579 | + } |
|
580 | + |
|
581 | + return array('last_page' => $last_page, 'data' => $history); |
|
582 | + } |
|
583 | + |
|
584 | + private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
585 | + { |
|
586 | + $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
587 | 587 | FROM gym_history_defenders ghd |
588 | 588 | JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
589 | 589 | WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."' |
590 | 590 | ORDER BY gd.deployment_time"; |
591 | - $result = $this->mysqli->query($req); |
|
592 | - $pokemons = array(); |
|
593 | - while ($data = $result->fetch_object()) { |
|
594 | - $pokemons[$data->defender_id] = $data; |
|
595 | - } |
|
596 | - |
|
597 | - return $pokemons; |
|
598 | - } |
|
599 | - |
|
600 | - ////////////// |
|
601 | - // Trainers |
|
602 | - ////////////// |
|
603 | - |
|
604 | - public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
605 | - { |
|
606 | - $ranking = $this->getTrainerLevelRanking(); |
|
607 | - $where = ''; |
|
608 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
609 | - $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
610 | - } |
|
611 | - if ('' != $trainer_name) { |
|
612 | - $where = " AND gd.owner_name LIKE '%".$trainer_name."%'"; |
|
613 | - } |
|
614 | - if (0 != $team) { |
|
615 | - $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
616 | - } |
|
617 | - switch ($rankingNumber) { |
|
618 | - case 1: |
|
619 | - $order = ' ORDER BY active DESC, level DESC'; |
|
620 | - break; |
|
621 | - case 2: |
|
622 | - $order = ' ORDER BY maxCp DESC, level DESC'; |
|
623 | - break; |
|
624 | - default: |
|
625 | - $order = ' ORDER BY level DESC, active DESC'; |
|
626 | - } |
|
627 | - $order .= ', last_seen DESC, name '; |
|
628 | - $limit = ' LIMIT '.($page * 10).',10 '; |
|
629 | - $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 |
|
591 | + $result = $this->mysqli->query($req); |
|
592 | + $pokemons = array(); |
|
593 | + while ($data = $result->fetch_object()) { |
|
594 | + $pokemons[$data->defender_id] = $data; |
|
595 | + } |
|
596 | + |
|
597 | + return $pokemons; |
|
598 | + } |
|
599 | + |
|
600 | + ////////////// |
|
601 | + // Trainers |
|
602 | + ////////////// |
|
603 | + |
|
604 | + public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
605 | + { |
|
606 | + $ranking = $this->getTrainerLevelRanking(); |
|
607 | + $where = ''; |
|
608 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
609 | + $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
610 | + } |
|
611 | + if ('' != $trainer_name) { |
|
612 | + $where = " AND gd.owner_name LIKE '%".$trainer_name."%'"; |
|
613 | + } |
|
614 | + if (0 != $team) { |
|
615 | + $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
616 | + } |
|
617 | + switch ($rankingNumber) { |
|
618 | + case 1: |
|
619 | + $order = ' ORDER BY active DESC, level DESC'; |
|
620 | + break; |
|
621 | + case 2: |
|
622 | + $order = ' ORDER BY maxCp DESC, level DESC'; |
|
623 | + break; |
|
624 | + default: |
|
625 | + $order = ' ORDER BY level DESC, active DESC'; |
|
626 | + } |
|
627 | + $order .= ', last_seen DESC, name '; |
|
628 | + $limit = ' LIMIT '.($page * 10).',10 '; |
|
629 | + $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 |
|
630 | 630 | FROM gym_defenders gd |
631 | 631 | LEFT JOIN ( |
632 | 632 | SELECT owner_name, COUNT(*) as active |
@@ -636,157 +636,157 @@ discard block |
||
636 | 636 | ) active ON active.owner_name = gd.owner_name |
637 | 637 | WHERE gd.owner_level IS NOT NULL '.$where.' |
638 | 638 | GROUP BY gd.owner_name'.$order.$limit; |
639 | - $result = $this->mysqli->query($req); |
|
640 | - $trainers = array(); |
|
641 | - while ($data = $result->fetch_object()) { |
|
642 | - $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
643 | - if (is_null($data->active)) { |
|
644 | - $data->active = 0; |
|
645 | - } |
|
646 | - $trainers[$data->name] = $data; |
|
647 | - |
|
648 | - $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
649 | - |
|
650 | - $trainers[$data->name]->gyms = $data->active; |
|
651 | - $trainers[$data->name]->pokemons = $pokemon; |
|
652 | - $trainers[$data->name]->rank = $ranking[$data->level]; |
|
653 | - } |
|
654 | - |
|
655 | - return $trainers; |
|
656 | - } |
|
657 | - |
|
658 | - public function getTrainerLevelRanking() |
|
659 | - { |
|
660 | - $exclue = ''; |
|
661 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
662 | - $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
663 | - } |
|
664 | - $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'; |
|
665 | - $result = $this->mysqli->query($req); |
|
666 | - $levelData = array(); |
|
667 | - while ($data = $result->fetch_object()) { |
|
668 | - $levelData[$data->level] = $data->count; |
|
669 | - } |
|
670 | - for ($i = 5; $i <= 40; ++$i) { |
|
671 | - if (!isset($levelData[$i])) { |
|
672 | - $levelData[$i] = 0; |
|
673 | - } |
|
674 | - } |
|
675 | - // sort array again |
|
676 | - ksort($levelData); |
|
677 | - |
|
678 | - return $levelData; |
|
679 | - } |
|
680 | - |
|
681 | - public function getActivePokemon($trainer_name) |
|
682 | - { |
|
683 | - $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 |
|
639 | + $result = $this->mysqli->query($req); |
|
640 | + $trainers = array(); |
|
641 | + while ($data = $result->fetch_object()) { |
|
642 | + $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
643 | + if (is_null($data->active)) { |
|
644 | + $data->active = 0; |
|
645 | + } |
|
646 | + $trainers[$data->name] = $data; |
|
647 | + |
|
648 | + $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
649 | + |
|
650 | + $trainers[$data->name]->gyms = $data->active; |
|
651 | + $trainers[$data->name]->pokemons = $pokemon; |
|
652 | + $trainers[$data->name]->rank = $ranking[$data->level]; |
|
653 | + } |
|
654 | + |
|
655 | + return $trainers; |
|
656 | + } |
|
657 | + |
|
658 | + public function getTrainerLevelRanking() |
|
659 | + { |
|
660 | + $exclue = ''; |
|
661 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
662 | + $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
663 | + } |
|
664 | + $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'; |
|
665 | + $result = $this->mysqli->query($req); |
|
666 | + $levelData = array(); |
|
667 | + while ($data = $result->fetch_object()) { |
|
668 | + $levelData[$data->level] = $data->count; |
|
669 | + } |
|
670 | + for ($i = 5; $i <= 40; ++$i) { |
|
671 | + if (!isset($levelData[$i])) { |
|
672 | + $levelData[$i] = 0; |
|
673 | + } |
|
674 | + } |
|
675 | + // sort array again |
|
676 | + ksort($levelData); |
|
677 | + |
|
678 | + return $levelData; |
|
679 | + } |
|
680 | + |
|
681 | + public function getActivePokemon($trainer_name) |
|
682 | + { |
|
683 | + $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 |
|
684 | 684 | FROM gym_defenders |
685 | 685 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL |
686 | 686 | ORDER BY deployment_time"; |
687 | - $result = $this->mysqli->query($req); |
|
688 | - $pokemon = array(); |
|
689 | - while ($data = $result->fetch_object()) { |
|
690 | - $pokemon[] = $data; |
|
691 | - } |
|
692 | - |
|
693 | - return $pokemon; |
|
694 | - } |
|
695 | - |
|
696 | - public function getInactivePokemon($trainer_name) |
|
697 | - { |
|
698 | - $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 |
|
687 | + $result = $this->mysqli->query($req); |
|
688 | + $pokemon = array(); |
|
689 | + while ($data = $result->fetch_object()) { |
|
690 | + $pokemon[] = $data; |
|
691 | + } |
|
692 | + |
|
693 | + return $pokemon; |
|
694 | + } |
|
695 | + |
|
696 | + public function getInactivePokemon($trainer_name) |
|
697 | + { |
|
698 | + $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 |
|
699 | 699 | FROM gym_defenders |
700 | 700 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL |
701 | 701 | ORDER BY last_scanned"; |
702 | - $result = $this->mysqli->query($req); |
|
703 | - $pokemon = array(); |
|
704 | - while ($data = $result->fetch_object()) { |
|
705 | - $pokemon[] = $data; |
|
706 | - } |
|
707 | - |
|
708 | - return $pokemon; |
|
709 | - } |
|
710 | - |
|
711 | - public function getTrainerLevelCount($team_id) |
|
712 | - { |
|
713 | - $exclue = ''; |
|
714 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
715 | - $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
716 | - } |
|
717 | - $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'; |
|
718 | - $result = $this->mysqli->query($req); |
|
719 | - $levelData = array(); |
|
720 | - while ($data = $result->fetch_object()) { |
|
721 | - $levelData[$data->level] = $data->count; |
|
722 | - } |
|
723 | - for ($i = 5; $i <= 40; ++$i) { |
|
724 | - if (!isset($levelData[$i])) { |
|
725 | - $levelData[$i] = 0; |
|
726 | - } |
|
727 | - } |
|
728 | - // sort array again |
|
729 | - ksort($levelData); |
|
730 | - |
|
731 | - return $levelData; |
|
732 | - } |
|
733 | - |
|
734 | - ///////// |
|
735 | - // Cron |
|
736 | - ///////// |
|
737 | - |
|
738 | - public function getPokemonCountsActive() |
|
739 | - { |
|
740 | - $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id'; |
|
741 | - $result = $this->mysqli->query($req); |
|
742 | - $counts = array(); |
|
743 | - while ($data = $result->fetch_object()) { |
|
744 | - $counts[$data->pokemon_id] = $data->total; |
|
745 | - } |
|
746 | - |
|
747 | - return $counts; |
|
748 | - } |
|
749 | - |
|
750 | - public function getTotalPokemonIV() |
|
751 | - { |
|
752 | - $req = 'SELECT COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() AND cp IS NOT NULL'; |
|
753 | - $result = $this->mysqli->query($req); |
|
754 | - $data = $result->fetch_object(); |
|
755 | - |
|
756 | - return $data; |
|
757 | - } |
|
758 | - public function getPokemonCountsLastDay() |
|
759 | - { |
|
760 | - $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
702 | + $result = $this->mysqli->query($req); |
|
703 | + $pokemon = array(); |
|
704 | + while ($data = $result->fetch_object()) { |
|
705 | + $pokemon[] = $data; |
|
706 | + } |
|
707 | + |
|
708 | + return $pokemon; |
|
709 | + } |
|
710 | + |
|
711 | + public function getTrainerLevelCount($team_id) |
|
712 | + { |
|
713 | + $exclue = ''; |
|
714 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
715 | + $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
716 | + } |
|
717 | + $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'; |
|
718 | + $result = $this->mysqli->query($req); |
|
719 | + $levelData = array(); |
|
720 | + while ($data = $result->fetch_object()) { |
|
721 | + $levelData[$data->level] = $data->count; |
|
722 | + } |
|
723 | + for ($i = 5; $i <= 40; ++$i) { |
|
724 | + if (!isset($levelData[$i])) { |
|
725 | + $levelData[$i] = 0; |
|
726 | + } |
|
727 | + } |
|
728 | + // sort array again |
|
729 | + ksort($levelData); |
|
730 | + |
|
731 | + return $levelData; |
|
732 | + } |
|
733 | + |
|
734 | + ///////// |
|
735 | + // Cron |
|
736 | + ///////// |
|
737 | + |
|
738 | + public function getPokemonCountsActive() |
|
739 | + { |
|
740 | + $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id'; |
|
741 | + $result = $this->mysqli->query($req); |
|
742 | + $counts = array(); |
|
743 | + while ($data = $result->fetch_object()) { |
|
744 | + $counts[$data->pokemon_id] = $data->total; |
|
745 | + } |
|
746 | + |
|
747 | + return $counts; |
|
748 | + } |
|
749 | + |
|
750 | + public function getTotalPokemonIV() |
|
751 | + { |
|
752 | + $req = 'SELECT COUNT(*) as total FROM sightings WHERE expire_timestamp >= UNIX_TIMESTAMP() AND cp IS NOT NULL'; |
|
753 | + $result = $this->mysqli->query($req); |
|
754 | + $data = $result->fetch_object(); |
|
755 | + |
|
756 | + return $data; |
|
757 | + } |
|
758 | + public function getPokemonCountsLastDay() |
|
759 | + { |
|
760 | + $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
761 | 761 | FROM sightings |
762 | 762 | WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings) |
763 | 763 | GROUP BY pokemon_id |
764 | 764 | ORDER BY pokemon_id ASC'; |
765 | - $result = $this->mysqli->query($req); |
|
766 | - $counts = array(); |
|
767 | - while ($data = $result->fetch_object()) { |
|
768 | - $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
769 | - } |
|
770 | - |
|
771 | - return $counts; |
|
772 | - } |
|
773 | - |
|
774 | - public function getCaptchaCount() |
|
775 | - { |
|
776 | - $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL'; |
|
777 | - $result = $this->mysqli->query($req); |
|
778 | - $data = $result->fetch_object(); |
|
779 | - |
|
780 | - return $data; |
|
781 | - } |
|
782 | - |
|
783 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
784 | - { |
|
785 | - $pokemon_exclude_sql = ''; |
|
786 | - if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
787 | - $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
788 | - } |
|
789 | - $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 |
|
765 | + $result = $this->mysqli->query($req); |
|
766 | + $counts = array(); |
|
767 | + while ($data = $result->fetch_object()) { |
|
768 | + $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
769 | + } |
|
770 | + |
|
771 | + return $counts; |
|
772 | + } |
|
773 | + |
|
774 | + public function getCaptchaCount() |
|
775 | + { |
|
776 | + $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL'; |
|
777 | + $result = $this->mysqli->query($req); |
|
778 | + $data = $result->fetch_object(); |
|
779 | + |
|
780 | + return $data; |
|
781 | + } |
|
782 | + |
|
783 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
784 | + { |
|
785 | + $pokemon_exclude_sql = ''; |
|
786 | + if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
787 | + $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
788 | + } |
|
789 | + $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 |
|
790 | 790 | FROM sightings p |
791 | 791 | INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
792 | 792 | WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).' |
@@ -795,23 +795,23 @@ discard block |
||
795 | 795 | GROUP BY p.spawn_id, p.pokemon_id |
796 | 796 | HAVING COUNT(p.pokemon_id) >= '.($time / 4).' |
797 | 797 | ORDER BY p.pokemon_id'; |
798 | - $result = $this->mysqli->query($req); |
|
799 | - $nests = array(); |
|
800 | - while ($data = $result->fetch_object()) { |
|
801 | - $nests[] = $data; |
|
802 | - } |
|
803 | - |
|
804 | - return $nests; |
|
805 | - } |
|
806 | - |
|
807 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
808 | - { |
|
809 | - $req = 'SELECT COUNT(*) as total |
|
798 | + $result = $this->mysqli->query($req); |
|
799 | + $nests = array(); |
|
800 | + while ($data = $result->fetch_object()) { |
|
801 | + $nests[] = $data; |
|
802 | + } |
|
803 | + |
|
804 | + return $nests; |
|
805 | + } |
|
806 | + |
|
807 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
808 | + { |
|
809 | + $req = 'SELECT COUNT(*) as total |
|
810 | 810 | FROM spawnpoints |
811 | 811 | WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude; |
812 | - $result = $this->mysqli->query($req); |
|
813 | - $data = $result->fetch_object(); |
|
812 | + $result = $this->mysqli->query($req); |
|
813 | + $data = $result->fetch_object(); |
|
814 | 814 | |
815 | - return $data; |
|
816 | - } |
|
815 | + return $data; |
|
816 | + } |
|
817 | 817 | } |
@@ -4,185 +4,185 @@ discard block |
||
4 | 4 | |
5 | 5 | class QueryManagerMysqlRealDeviceMap extends QueryManagerMysql |
6 | 6 | { |
7 | - public function __construct() |
|
8 | - { |
|
9 | - parent::__construct(); |
|
10 | - } |
|
11 | - |
|
12 | - public function __destruct() |
|
13 | - { |
|
14 | - parent::__destruct(); |
|
15 | - } |
|
16 | - |
|
17 | - /////////// |
|
18 | - // Tester |
|
19 | - /////////// |
|
20 | - |
|
21 | - public function testTotalPokemon() |
|
22 | - { |
|
23 | - $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
24 | - $result = $this->mysqli->query($req); |
|
25 | - if (!is_object($result)) { |
|
26 | - return 1; |
|
27 | - } else { |
|
28 | - $data = $result->fetch_object(); |
|
29 | - $total = $data->total; |
|
30 | - |
|
31 | - if (0 == $total) { |
|
32 | - return 2; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - return 0; |
|
37 | - } |
|
38 | - |
|
39 | - public function testTotalGyms() |
|
40 | - { |
|
41 | - $req = 'SELECT COUNT(*) as total FROM gym'; |
|
42 | - $result = $this->mysqli->query($req); |
|
43 | - if (!is_object($result)) { |
|
44 | - return 1; |
|
45 | - } else { |
|
46 | - $data = $result->fetch_object(); |
|
47 | - $total = $data->total; |
|
48 | - |
|
49 | - if (0 == $total) { |
|
50 | - return 2; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return 0; |
|
55 | - } |
|
56 | - |
|
57 | - public function testTotalPokestops() |
|
58 | - { |
|
59 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
60 | - $result = $this->mysqli->query($req); |
|
61 | - if (!is_object($result)) { |
|
62 | - return 1; |
|
63 | - } else { |
|
64 | - $data = $result->fetch_object(); |
|
65 | - $total = $data->total; |
|
66 | - |
|
67 | - if (0 == $total) { |
|
68 | - return 2; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return 0; |
|
73 | - } |
|
74 | - |
|
75 | - ///////////// |
|
76 | - // Homepage |
|
77 | - ///////////// |
|
78 | - |
|
79 | - public function getTotalPokemon() |
|
80 | - { |
|
81 | - $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP()'; |
|
82 | - $result = $this->mysqli->query($req); |
|
83 | - $data = $result->fetch_object(); |
|
84 | - |
|
85 | - return $data; |
|
86 | - } |
|
87 | - |
|
88 | - public function getTotalLures() |
|
89 | - { |
|
90 | - $req = 'SELECT COUNT(*) as total FROM pokestop WHERE lure_expire_timestamp >= UNIX_TIMESTAMP()'; |
|
91 | - $result = $this->mysqli->query($req); |
|
92 | - $data = $result->fetch_object(); |
|
93 | - |
|
94 | - return $data; |
|
95 | - } |
|
96 | - |
|
97 | - public function getTotalGyms() |
|
98 | - { |
|
99 | - $req = 'SELECT COUNT(*) AS total FROM gym'; |
|
100 | - $result = $this->mysqli->query($req); |
|
101 | - $data = $result->fetch_object(); |
|
102 | - |
|
103 | - return $data; |
|
104 | - } |
|
105 | - |
|
106 | - public function getTotalRaids() |
|
107 | - { |
|
108 | - $req = 'SELECT COUNT(*) AS total FROM gym WHERE raid_battle_timestamp <= UNIX_TIMESTAMP() AND raid_end_timestamp >= UNIX_TIMESTAMP()'; |
|
109 | - $result = $this->mysqli->query($req); |
|
110 | - $data = $result->fetch_object(); |
|
111 | - |
|
112 | - return $data; |
|
113 | - } |
|
114 | - |
|
115 | - public function getTotalGymsForTeam($team_id) |
|
116 | - { |
|
117 | - $req = 'SELECT COUNT(*) AS total FROM gym WHERE team_id = '.$team_id; |
|
118 | - $result = $this->mysqli->query($req); |
|
119 | - $data = $result->fetch_object(); |
|
120 | - |
|
121 | - return $data; |
|
122 | - } |
|
123 | - |
|
124 | - public function getRecentAll() |
|
125 | - { |
|
126 | - $req = 'SELECT pokemon_id, id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
7 | + public function __construct() |
|
8 | + { |
|
9 | + parent::__construct(); |
|
10 | + } |
|
11 | + |
|
12 | + public function __destruct() |
|
13 | + { |
|
14 | + parent::__destruct(); |
|
15 | + } |
|
16 | + |
|
17 | + /////////// |
|
18 | + // Tester |
|
19 | + /////////// |
|
20 | + |
|
21 | + public function testTotalPokemon() |
|
22 | + { |
|
23 | + $req = 'SELECT COUNT(*) as total FROM pokemon'; |
|
24 | + $result = $this->mysqli->query($req); |
|
25 | + if (!is_object($result)) { |
|
26 | + return 1; |
|
27 | + } else { |
|
28 | + $data = $result->fetch_object(); |
|
29 | + $total = $data->total; |
|
30 | + |
|
31 | + if (0 == $total) { |
|
32 | + return 2; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + return 0; |
|
37 | + } |
|
38 | + |
|
39 | + public function testTotalGyms() |
|
40 | + { |
|
41 | + $req = 'SELECT COUNT(*) as total FROM gym'; |
|
42 | + $result = $this->mysqli->query($req); |
|
43 | + if (!is_object($result)) { |
|
44 | + return 1; |
|
45 | + } else { |
|
46 | + $data = $result->fetch_object(); |
|
47 | + $total = $data->total; |
|
48 | + |
|
49 | + if (0 == $total) { |
|
50 | + return 2; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return 0; |
|
55 | + } |
|
56 | + |
|
57 | + public function testTotalPokestops() |
|
58 | + { |
|
59 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
60 | + $result = $this->mysqli->query($req); |
|
61 | + if (!is_object($result)) { |
|
62 | + return 1; |
|
63 | + } else { |
|
64 | + $data = $result->fetch_object(); |
|
65 | + $total = $data->total; |
|
66 | + |
|
67 | + if (0 == $total) { |
|
68 | + return 2; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return 0; |
|
73 | + } |
|
74 | + |
|
75 | + ///////////// |
|
76 | + // Homepage |
|
77 | + ///////////// |
|
78 | + |
|
79 | + public function getTotalPokemon() |
|
80 | + { |
|
81 | + $req = 'SELECT COUNT(*) AS total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP()'; |
|
82 | + $result = $this->mysqli->query($req); |
|
83 | + $data = $result->fetch_object(); |
|
84 | + |
|
85 | + return $data; |
|
86 | + } |
|
87 | + |
|
88 | + public function getTotalLures() |
|
89 | + { |
|
90 | + $req = 'SELECT COUNT(*) as total FROM pokestop WHERE lure_expire_timestamp >= UNIX_TIMESTAMP()'; |
|
91 | + $result = $this->mysqli->query($req); |
|
92 | + $data = $result->fetch_object(); |
|
93 | + |
|
94 | + return $data; |
|
95 | + } |
|
96 | + |
|
97 | + public function getTotalGyms() |
|
98 | + { |
|
99 | + $req = 'SELECT COUNT(*) AS total FROM gym'; |
|
100 | + $result = $this->mysqli->query($req); |
|
101 | + $data = $result->fetch_object(); |
|
102 | + |
|
103 | + return $data; |
|
104 | + } |
|
105 | + |
|
106 | + public function getTotalRaids() |
|
107 | + { |
|
108 | + $req = 'SELECT COUNT(*) AS total FROM gym WHERE raid_battle_timestamp <= UNIX_TIMESTAMP() AND raid_end_timestamp >= UNIX_TIMESTAMP()'; |
|
109 | + $result = $this->mysqli->query($req); |
|
110 | + $data = $result->fetch_object(); |
|
111 | + |
|
112 | + return $data; |
|
113 | + } |
|
114 | + |
|
115 | + public function getTotalGymsForTeam($team_id) |
|
116 | + { |
|
117 | + $req = 'SELECT COUNT(*) AS total FROM gym WHERE team_id = '.$team_id; |
|
118 | + $result = $this->mysqli->query($req); |
|
119 | + $data = $result->fetch_object(); |
|
120 | + |
|
121 | + return $data; |
|
122 | + } |
|
123 | + |
|
124 | + public function getRecentAll() |
|
125 | + { |
|
126 | + $req = 'SELECT pokemon_id, id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
127 | 127 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
128 | 128 | FROM pokemon |
129 | 129 | ORDER BY changed DESC |
130 | 130 | LIMIT 0,12;'; |
131 | - $result = $this->mysqli->query($req); |
|
132 | - $data = array(); |
|
133 | - if ($result->num_rows > 0) { |
|
134 | - while ($row = $result->fetch_object()) { |
|
135 | - $data[] = $row; |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - return $data; |
|
140 | - } |
|
141 | - |
|
142 | - public function getRecentMythic($mythic_pokemon) |
|
143 | - { |
|
144 | - $req = 'SELECT pokemon_id, id as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
131 | + $result = $this->mysqli->query($req); |
|
132 | + $data = array(); |
|
133 | + if ($result->num_rows > 0) { |
|
134 | + while ($row = $result->fetch_object()) { |
|
135 | + $data[] = $row; |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + return $data; |
|
140 | + } |
|
141 | + |
|
142 | + public function getRecentMythic($mythic_pokemon) |
|
143 | + { |
|
144 | + $req = 'SELECT pokemon_id, id as encounter_id, FROM_UNIXTIME(expire_timestamp) AS disappear_time, FROM_UNIXTIME(updated) AS last_modified, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
|
145 | 145 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
146 | 146 | FROM pokemon |
147 | 147 | WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).') |
148 | 148 | ORDER BY changed 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 | - return array(); |
|
168 | - } |
|
169 | - |
|
170 | - public function getPokemonLastSeen($pokemon_id) |
|
171 | - { |
|
172 | - $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
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 | + return array(); |
|
168 | + } |
|
169 | + |
|
170 | + public function getPokemonLastSeen($pokemon_id) |
|
171 | + { |
|
172 | + $req = "SELECT FROM_UNIXTIME(expire_timestamp) AS expire_timestamp, FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
173 | 173 | FROM pokemon |
174 | 174 | WHERE pokemon_id = '".$pokemon_id."' |
175 | 175 | ORDER BY expire_timestamp DESC |
176 | 176 | LIMIT 0,1"; |
177 | - $result = $this->mysqli->query($req); |
|
178 | - $data = $result->fetch_object(); |
|
177 | + $result = $this->mysqli->query($req); |
|
178 | + $data = $result->fetch_object(); |
|
179 | 179 | |
180 | - return $data; |
|
181 | - } |
|
180 | + return $data; |
|
181 | + } |
|
182 | 182 | |
183 | - public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
184 | - { |
|
185 | - $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, |
|
183 | + public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
184 | + { |
|
185 | + $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, |
|
186 | 186 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
187 | 187 | iv AS IV, move_1 as move_1, move_2, form |
188 | 188 | FROM pokemon |
@@ -190,354 +190,354 @@ discard block |
||
190 | 190 | ORDER BY $top_order_by $top_direction, expire_timestamp DESC |
191 | 191 | LIMIT 0,50"; |
192 | 192 | |
193 | - $result = $this->mysqli->query($req); |
|
194 | - $top = array(); |
|
195 | - while ($data = $result->fetch_object()) { |
|
196 | - $top[] = $data; |
|
197 | - } |
|
198 | - |
|
199 | - return $top; |
|
200 | - } |
|
201 | - |
|
202 | - public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
203 | - { |
|
204 | - return array(); |
|
205 | - } |
|
206 | - |
|
207 | - public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
208 | - { |
|
209 | - $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
210 | - ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
211 | - $req = 'SELECT lat AS latitude, lon AS longitude FROM pokemon'.$where.' LIMIT 100000'; |
|
212 | - $result = $this->mysqli->query($req); |
|
213 | - $points = array(); |
|
214 | - while ($data = $result->fetch_object()) { |
|
215 | - $points[] = $data; |
|
216 | - } |
|
217 | - |
|
218 | - return $points; |
|
219 | - } |
|
220 | - |
|
221 | - public function getPokemonGraph($pokemon_id) |
|
222 | - { |
|
223 | - $req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour |
|
193 | + $result = $this->mysqli->query($req); |
|
194 | + $top = array(); |
|
195 | + while ($data = $result->fetch_object()) { |
|
196 | + $top[] = $data; |
|
197 | + } |
|
198 | + |
|
199 | + return $top; |
|
200 | + } |
|
201 | + |
|
202 | + public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
203 | + { |
|
204 | + return array(); |
|
205 | + } |
|
206 | + |
|
207 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
208 | + { |
|
209 | + $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
210 | + ."AND FROM_UNIXTIME(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
211 | + $req = 'SELECT lat AS latitude, lon AS longitude FROM pokemon'.$where.' LIMIT 100000'; |
|
212 | + $result = $this->mysqli->query($req); |
|
213 | + $points = array(); |
|
214 | + while ($data = $result->fetch_object()) { |
|
215 | + $points[] = $data; |
|
216 | + } |
|
217 | + |
|
218 | + return $points; |
|
219 | + } |
|
220 | + |
|
221 | + public function getPokemonGraph($pokemon_id) |
|
222 | + { |
|
223 | + $req = "SELECT COUNT(*) AS total, HOUR(disappear_time) AS disappear_hour |
|
224 | 224 | FROM (SELECT FROM_UNIXTIME(expire_timestamp) as disappear_time FROM pokemon WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
225 | 225 | GROUP BY disappear_hour |
226 | 226 | ORDER BY disappear_hour"; |
227 | - $result = $this->mysqli->query($req); |
|
228 | - $array = array_fill(0, 24, 0); |
|
229 | - while ($result && $data = $result->fetch_object()) { |
|
230 | - $array[$data->disappear_hour] = $data->total; |
|
231 | - } |
|
232 | - // shift array because AM/PM starts at 1AM not 0:00 |
|
233 | - $array[] = $array[0]; |
|
234 | - array_shift($array); |
|
235 | - |
|
236 | - return $array; |
|
237 | - } |
|
238 | - |
|
239 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
240 | - { |
|
241 | - $inmap_pkms_filter = ''; |
|
242 | - $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
243 | - |
|
244 | - $reqTestIv = 'SELECT MAX(iv) AS iv FROM pokemon '.$where; |
|
245 | - $resultTestIv = $this->mysqli->query($reqTestIv); |
|
246 | - $testIv = $resultTestIv->fetch_object(); |
|
247 | - if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
248 | - foreach ($inmap_pokemons as $inmap) { |
|
249 | - $inmap_pkms_filter .= "'".$inmap."',"; |
|
250 | - } |
|
251 | - $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
252 | - $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
253 | - } |
|
254 | - if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin) && !($ivMax == 100 && $ivMin == 0)) { |
|
255 | - $where .= ' AND iv >= ('.$ivMin.') '; |
|
256 | - } |
|
257 | - if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax) && !($ivMax == 100 && $ivMin == 0)) { |
|
258 | - $where .= ' AND iv <= ('.$ivMax.') '; |
|
259 | - } |
|
260 | - $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
227 | + $result = $this->mysqli->query($req); |
|
228 | + $array = array_fill(0, 24, 0); |
|
229 | + while ($result && $data = $result->fetch_object()) { |
|
230 | + $array[$data->disappear_hour] = $data->total; |
|
231 | + } |
|
232 | + // shift array because AM/PM starts at 1AM not 0:00 |
|
233 | + $array[] = $array[0]; |
|
234 | + array_shift($array); |
|
235 | + |
|
236 | + return $array; |
|
237 | + } |
|
238 | + |
|
239 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
240 | + { |
|
241 | + $inmap_pkms_filter = ''; |
|
242 | + $where = ' WHERE expire_timestamp >= UNIX_TIMESTAMP() AND pokemon_id = '.$pokemon_id; |
|
243 | + |
|
244 | + $reqTestIv = 'SELECT MAX(iv) AS iv FROM pokemon '.$where; |
|
245 | + $resultTestIv = $this->mysqli->query($reqTestIv); |
|
246 | + $testIv = $resultTestIv->fetch_object(); |
|
247 | + if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
248 | + foreach ($inmap_pokemons as $inmap) { |
|
249 | + $inmap_pkms_filter .= "'".$inmap."',"; |
|
250 | + } |
|
251 | + $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
252 | + $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
253 | + } |
|
254 | + if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin) && !($ivMax == 100 && $ivMin == 0)) { |
|
255 | + $where .= ' AND iv >= ('.$ivMin.') '; |
|
256 | + } |
|
257 | + if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax) && !($ivMax == 100 && $ivMin == 0)) { |
|
258 | + $where .= ' AND iv <= ('.$ivMax.') '; |
|
259 | + } |
|
260 | + $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
261 | 261 | FROM_UNIXTIME(expire_timestamp) AS disappear_time, |
262 | 262 | FROM_UNIXTIME(expire_timestamp) AS disappear_time_real, |
263 | 263 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
264 | 264 | move_1, move_2 |
265 | 265 | FROM pokemon '.$where.' |
266 | 266 | LIMIT 5000'; |
267 | - $result = $this->mysqli->query($req); |
|
268 | - $spawns = array(); |
|
269 | - while ($data = $result->fetch_object()) { |
|
270 | - $spawns[] = $data; |
|
271 | - } |
|
272 | - |
|
273 | - return $spawns; |
|
274 | - } |
|
275 | - |
|
276 | - public function getPokemonSliderMinMax() |
|
277 | - { |
|
278 | - $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM pokemon'; |
|
279 | - $result = $this->mysqli->query($req); |
|
280 | - $data = $result->fetch_object(); |
|
281 | - |
|
282 | - return $data; |
|
283 | - } |
|
284 | - |
|
285 | - public function getMapsCoords() |
|
286 | - { |
|
287 | - $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoint'; |
|
288 | - $result = $this->mysqli->query($req); |
|
289 | - $data = $result->fetch_object(); |
|
290 | - |
|
291 | - return $data; |
|
292 | - } |
|
293 | - |
|
294 | - public function getPokemonCount($pokemon_id) |
|
295 | - { |
|
296 | - $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day |
|
267 | + $result = $this->mysqli->query($req); |
|
268 | + $spawns = array(); |
|
269 | + while ($data = $result->fetch_object()) { |
|
270 | + $spawns[] = $data; |
|
271 | + } |
|
272 | + |
|
273 | + return $spawns; |
|
274 | + } |
|
275 | + |
|
276 | + public function getPokemonSliderMinMax() |
|
277 | + { |
|
278 | + $req = 'SELECT FROM_UNIXTIME(MIN(expire_timestamp)) AS min, FROM_UNIXTIME(MAX(expire_timestamp)) AS max FROM pokemon'; |
|
279 | + $result = $this->mysqli->query($req); |
|
280 | + $data = $result->fetch_object(); |
|
281 | + |
|
282 | + return $data; |
|
283 | + } |
|
284 | + |
|
285 | + public function getMapsCoords() |
|
286 | + { |
|
287 | + $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoint'; |
|
288 | + $result = $this->mysqli->query($req); |
|
289 | + $data = $result->fetch_object(); |
|
290 | + |
|
291 | + return $data; |
|
292 | + } |
|
293 | + |
|
294 | + public function getPokemonCount($pokemon_id) |
|
295 | + { |
|
296 | + $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day |
|
297 | 297 | FROM pokemon_stats |
298 | 298 | WHERE pokemon_id = '.$pokemon_id; |
299 | - $result = $this->mysqli->query($req); |
|
300 | - $data = $result->fetch_object(); |
|
299 | + $result = $this->mysqli->query($req); |
|
300 | + $data = $result->fetch_object(); |
|
301 | 301 | |
302 | - return $data; |
|
303 | - } |
|
302 | + return $data; |
|
303 | + } |
|
304 | 304 | |
305 | - public function getPokemonCountAll() |
|
306 | - { |
|
307 | - $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day |
|
305 | + public function getPokemonCountAll() |
|
306 | + { |
|
307 | + $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day |
|
308 | 308 | FROM pokemon_stats |
309 | 309 | GROUP BY pokemon_id'; |
310 | - $result = $this->mysqli->query($req); |
|
311 | - $array = array(); |
|
312 | - while ($data = $result->fetch_object()) { |
|
313 | - $array[] = $data; |
|
314 | - } |
|
310 | + $result = $this->mysqli->query($req); |
|
311 | + $array = array(); |
|
312 | + while ($data = $result->fetch_object()) { |
|
313 | + $array[] = $data; |
|
314 | + } |
|
315 | 315 | |
316 | - return $array; |
|
317 | - } |
|
316 | + return $array; |
|
317 | + } |
|
318 | 318 | |
319 | 319 | |
320 | - public function getRaidCount($pokemon_id) |
|
321 | - { |
|
322 | - $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day |
|
320 | + public function getRaidCount($pokemon_id) |
|
321 | + { |
|
322 | + $req = 'SELECT COALESCE(SUM(count),0) as count, MAX(date) as last_seen_day |
|
323 | 323 | FROM raid_stats |
324 | 324 | WHERE pokemon_id = '.$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 getRaidCountAll() |
|
332 | - { |
|
333 | - $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day |
|
331 | + public function getRaidCountAll() |
|
332 | + { |
|
333 | + $req = 'SELECT pokemon_id, SUM(count) as count, MAX(date) as last_seen_day |
|
334 | 334 | FROM raid_stats |
335 | 335 | GROUP BY pokemon_id'; |
336 | - $result = $this->mysqli->query($req); |
|
337 | - $array = array(); |
|
338 | - while ($data = $result->fetch_object()) { |
|
339 | - $array[] = $data; |
|
340 | - } |
|
341 | - |
|
342 | - return $array; |
|
343 | - } |
|
344 | - |
|
345 | - /////////////// |
|
346 | - // Pokestops |
|
347 | - ////////////// |
|
348 | - |
|
349 | - public function getTotalPokestops() |
|
350 | - { |
|
351 | - $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
352 | - $result = $this->mysqli->query($req); |
|
353 | - $data = $result->fetch_object(); |
|
354 | - |
|
355 | - return $data; |
|
356 | - } |
|
357 | - |
|
358 | - public function getAllPokestops() |
|
359 | - { |
|
360 | - $req = 'SELECT lat as latitude, lon as longitude, lure_expire_timestamp AS lure_expiration, UNIX_TIMESTAMP() AS now, FROM_UNIXTIME(lure_expire_timestamp) AS lure_expiration_real FROM pokestop'; |
|
361 | - $result = $this->mysqli->query($req); |
|
362 | - $pokestops = array(); |
|
363 | - while ($data = $result->fetch_object()) { |
|
364 | - $pokestops[] = $data; |
|
365 | - } |
|
366 | - |
|
367 | - return $pokestops; |
|
368 | - } |
|
369 | - |
|
370 | - ///////// |
|
371 | - // Gyms |
|
372 | - ///////// |
|
373 | - |
|
374 | - public function getTeamGuardians($team_id) |
|
375 | - { |
|
376 | - return array(); |
|
377 | - } |
|
378 | - |
|
379 | - public function getOwnedAndPoints($team_id) |
|
380 | - { |
|
381 | - $req = "SELECT COUNT(id) AS total, ROUND(AVG(total_cp)) AS average_points |
|
336 | + $result = $this->mysqli->query($req); |
|
337 | + $array = array(); |
|
338 | + while ($data = $result->fetch_object()) { |
|
339 | + $array[] = $data; |
|
340 | + } |
|
341 | + |
|
342 | + return $array; |
|
343 | + } |
|
344 | + |
|
345 | + /////////////// |
|
346 | + // Pokestops |
|
347 | + ////////////// |
|
348 | + |
|
349 | + public function getTotalPokestops() |
|
350 | + { |
|
351 | + $req = 'SELECT COUNT(*) as total FROM pokestop'; |
|
352 | + $result = $this->mysqli->query($req); |
|
353 | + $data = $result->fetch_object(); |
|
354 | + |
|
355 | + return $data; |
|
356 | + } |
|
357 | + |
|
358 | + public function getAllPokestops() |
|
359 | + { |
|
360 | + $req = 'SELECT lat as latitude, lon as longitude, lure_expire_timestamp AS lure_expiration, UNIX_TIMESTAMP() AS now, FROM_UNIXTIME(lure_expire_timestamp) AS lure_expiration_real FROM pokestop'; |
|
361 | + $result = $this->mysqli->query($req); |
|
362 | + $pokestops = array(); |
|
363 | + while ($data = $result->fetch_object()) { |
|
364 | + $pokestops[] = $data; |
|
365 | + } |
|
366 | + |
|
367 | + return $pokestops; |
|
368 | + } |
|
369 | + |
|
370 | + ///////// |
|
371 | + // Gyms |
|
372 | + ///////// |
|
373 | + |
|
374 | + public function getTeamGuardians($team_id) |
|
375 | + { |
|
376 | + return array(); |
|
377 | + } |
|
378 | + |
|
379 | + public function getOwnedAndPoints($team_id) |
|
380 | + { |
|
381 | + $req = "SELECT COUNT(id) AS total, ROUND(AVG(total_cp)) AS average_points |
|
382 | 382 | FROM gym |
383 | 383 | WHERE team_id = '".$team_id."'"; |
384 | - $result = $this->mysqli->query($req); |
|
385 | - $data = $result->fetch_object(); |
|
384 | + $result = $this->mysqli->query($req); |
|
385 | + $data = $result->fetch_object(); |
|
386 | 386 | |
387 | - return $data; |
|
388 | - } |
|
387 | + return $data; |
|
388 | + } |
|
389 | 389 | |
390 | - public function getAllGyms() |
|
391 | - { |
|
392 | - $req = 'SELECT id as gym_id, team_id, lat as latitude, lon as longitude, updated as last_scanned, (6 - availble_slots) AS level |
|
390 | + public function getAllGyms() |
|
391 | + { |
|
392 | + $req = 'SELECT id as gym_id, team_id, lat as latitude, lon as longitude, updated as last_scanned, (6 - availble_slots) AS level |
|
393 | 393 | FROM gym'; |
394 | - $result = $this->mysqli->query($req); |
|
395 | - $gyms = array(); |
|
396 | - while ($data = $result->fetch_object()) { |
|
397 | - $gyms[] = $data; |
|
398 | - } |
|
399 | - |
|
400 | - return $gyms; |
|
401 | - } |
|
402 | - |
|
403 | - public function getGymData($gym_id) |
|
404 | - { |
|
405 | - $req = "SELECT name, null AS description, url, team_id AS team, FROM_UNIXTIME(updated) AS last_scanned, guarding_pokemon_id AS guard_pokemon_id, (6 - availble_slots) AS level, total_cp |
|
394 | + $result = $this->mysqli->query($req); |
|
395 | + $gyms = array(); |
|
396 | + while ($data = $result->fetch_object()) { |
|
397 | + $gyms[] = $data; |
|
398 | + } |
|
399 | + |
|
400 | + return $gyms; |
|
401 | + } |
|
402 | + |
|
403 | + public function getGymData($gym_id) |
|
404 | + { |
|
405 | + $req = "SELECT name, null AS description, url, team_id AS team, FROM_UNIXTIME(updated) AS last_scanned, guarding_pokemon_id AS guard_pokemon_id, (6 - availble_slots) AS level, total_cp |
|
406 | 406 | FROM gym |
407 | 407 | WHERE id = '".$gym_id."'"; |
408 | - $result = $this->mysqli->query($req); |
|
409 | - $data = $result->fetch_object(); |
|
408 | + $result = $this->mysqli->query($req); |
|
409 | + $data = $result->fetch_object(); |
|
410 | 410 | |
411 | - return $data; |
|
412 | - } |
|
411 | + return $data; |
|
412 | + } |
|
413 | 413 | |
414 | - public function getGymDefenders($gym_id) |
|
415 | - { |
|
416 | - return array(); |
|
417 | - } |
|
414 | + public function getGymDefenders($gym_id) |
|
415 | + { |
|
416 | + return array(); |
|
417 | + } |
|
418 | 418 | |
419 | - /////////// |
|
420 | - // Raids |
|
421 | - /////////// |
|
419 | + /////////// |
|
420 | + // Raids |
|
421 | + /////////// |
|
422 | 422 | |
423 | - public function getAllRaids($page) |
|
424 | - { |
|
425 | - $limit = ' LIMIT '.($page * 10).',10'; |
|
426 | - $req = 'SELECT id AS gym_id, raid_level AS level, raid_pokemon_id AS pokemon_id, raid_pokemon_cp AS cp, raid_pokemon_move_1 AS move_1, raid_pokemon_move_2 AS move_2, FROM_UNIXTIME(raid_spawn_timestamp) AS spawn, FROM_UNIXTIME(raid_battle_timestamp) AS start, FROM_UNIXTIME(raid_end_timestamp) AS end, FROM_UNIXTIME(updated) AS last_scanned, name, lat AS latitude, lon as longitude |
|
423 | + public function getAllRaids($page) |
|
424 | + { |
|
425 | + $limit = ' LIMIT '.($page * 10).',10'; |
|
426 | + $req = 'SELECT id AS gym_id, raid_level AS level, raid_pokemon_id AS pokemon_id, raid_pokemon_cp AS cp, raid_pokemon_move_1 AS move_1, raid_pokemon_move_2 AS move_2, FROM_UNIXTIME(raid_spawn_timestamp) AS spawn, FROM_UNIXTIME(raid_battle_timestamp) AS start, FROM_UNIXTIME(raid_end_timestamp) AS end, FROM_UNIXTIME(updated) AS last_scanned, name, lat AS latitude, lon as longitude |
|
427 | 427 | FROM gym |
428 | 428 | WHERE raid_end_timestamp > UNIX_TIMESTAMP() |
429 | 429 | ORDER BY raid_level DESC, raid_battle_timestamp'.$limit; |
430 | - $result = $this->mysqli->query($req); |
|
431 | - $raids = array(); |
|
432 | - while ($data = $result->fetch_object()) { |
|
433 | - $raids[] = $data; |
|
434 | - } |
|
435 | - |
|
436 | - return $raids; |
|
437 | - } |
|
438 | - |
|
439 | - //////////////// |
|
440 | - // Gym History |
|
441 | - //////////////// |
|
442 | - |
|
443 | - public function getGymHistories($gym_name, $team, $page, $ranking) |
|
444 | - { |
|
445 | - return array(); |
|
446 | - } |
|
447 | - |
|
448 | - public function getGymHistoriesPokemon($gym_id) |
|
449 | - { |
|
450 | - return array(); |
|
451 | - } |
|
452 | - |
|
453 | - public function getHistoryForGym($page, $gym_id) |
|
454 | - { |
|
455 | - return array(); |
|
456 | - } |
|
457 | - |
|
458 | - ////////////// |
|
459 | - // Trainers |
|
460 | - ////////////// |
|
461 | - |
|
462 | - public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
463 | - { |
|
464 | - return array(); |
|
465 | - } |
|
466 | - |
|
467 | - public function getTrainerLevelRanking() |
|
468 | - { |
|
469 | - return array(); |
|
470 | - } |
|
471 | - |
|
472 | - public function getActivePokemon($trainer_name) |
|
473 | - { |
|
474 | - return array(); |
|
475 | - } |
|
476 | - |
|
477 | - public function getInactivePokemon($trainer_name) |
|
478 | - { |
|
479 | - return array(); |
|
480 | - } |
|
481 | - |
|
482 | - public function getTrainerLevelCount($team_id) |
|
483 | - { |
|
484 | - return array(); |
|
485 | - } |
|
486 | - |
|
487 | - ///////// |
|
488 | - // Cron |
|
489 | - ///////// |
|
490 | - |
|
491 | - public function getPokemonCountsActive() |
|
492 | - { |
|
493 | - $req = 'SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id'; |
|
494 | - $result = $this->mysqli->query($req); |
|
495 | - $counts = array(); |
|
496 | - while ($data = $result->fetch_object()) { |
|
497 | - $counts[$data->pokemon_id] = $data->total; |
|
498 | - } |
|
499 | - |
|
500 | - return $counts; |
|
501 | - } |
|
502 | - |
|
503 | - public function getTotalPokemonIV() |
|
504 | - { |
|
505 | - $req = 'SELECT COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() AND iv IS NOT NULL'; |
|
506 | - $result = $this->mysqli->query($req); |
|
507 | - $data = $result->fetch_object(); |
|
508 | - |
|
509 | - return $data; |
|
510 | - } |
|
511 | - |
|
512 | - public function getPokemonCountsLastDay() |
|
513 | - { |
|
514 | - $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
430 | + $result = $this->mysqli->query($req); |
|
431 | + $raids = array(); |
|
432 | + while ($data = $result->fetch_object()) { |
|
433 | + $raids[] = $data; |
|
434 | + } |
|
435 | + |
|
436 | + return $raids; |
|
437 | + } |
|
438 | + |
|
439 | + //////////////// |
|
440 | + // Gym History |
|
441 | + //////////////// |
|
442 | + |
|
443 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
444 | + { |
|
445 | + return array(); |
|
446 | + } |
|
447 | + |
|
448 | + public function getGymHistoriesPokemon($gym_id) |
|
449 | + { |
|
450 | + return array(); |
|
451 | + } |
|
452 | + |
|
453 | + public function getHistoryForGym($page, $gym_id) |
|
454 | + { |
|
455 | + return array(); |
|
456 | + } |
|
457 | + |
|
458 | + ////////////// |
|
459 | + // Trainers |
|
460 | + ////////////// |
|
461 | + |
|
462 | + public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
463 | + { |
|
464 | + return array(); |
|
465 | + } |
|
466 | + |
|
467 | + public function getTrainerLevelRanking() |
|
468 | + { |
|
469 | + return array(); |
|
470 | + } |
|
471 | + |
|
472 | + public function getActivePokemon($trainer_name) |
|
473 | + { |
|
474 | + return array(); |
|
475 | + } |
|
476 | + |
|
477 | + public function getInactivePokemon($trainer_name) |
|
478 | + { |
|
479 | + return array(); |
|
480 | + } |
|
481 | + |
|
482 | + public function getTrainerLevelCount($team_id) |
|
483 | + { |
|
484 | + return array(); |
|
485 | + } |
|
486 | + |
|
487 | + ///////// |
|
488 | + // Cron |
|
489 | + ///////// |
|
490 | + |
|
491 | + public function getPokemonCountsActive() |
|
492 | + { |
|
493 | + $req = 'SELECT pokemon_id, COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() GROUP BY pokemon_id'; |
|
494 | + $result = $this->mysqli->query($req); |
|
495 | + $counts = array(); |
|
496 | + while ($data = $result->fetch_object()) { |
|
497 | + $counts[$data->pokemon_id] = $data->total; |
|
498 | + } |
|
499 | + |
|
500 | + return $counts; |
|
501 | + } |
|
502 | + |
|
503 | + public function getTotalPokemonIV() |
|
504 | + { |
|
505 | + $req = 'SELECT COUNT(*) as total FROM pokemon WHERE expire_timestamp >= UNIX_TIMESTAMP() AND iv IS NOT NULL'; |
|
506 | + $result = $this->mysqli->query($req); |
|
507 | + $data = $result->fetch_object(); |
|
508 | + |
|
509 | + return $data; |
|
510 | + } |
|
511 | + |
|
512 | + public function getPokemonCountsLastDay() |
|
513 | + { |
|
514 | + $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
515 | 515 | FROM pokemon |
516 | 516 | WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM pokemon) |
517 | 517 | GROUP BY pokemon_id |
518 | 518 | ORDER BY pokemon_id ASC'; |
519 | - $result = $this->mysqli->query($req); |
|
520 | - $counts = array(); |
|
521 | - while ($data = $result->fetch_object()) { |
|
522 | - $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
523 | - } |
|
524 | - |
|
525 | - return $counts; |
|
526 | - } |
|
527 | - |
|
528 | - public function getCaptchaCount() |
|
529 | - { |
|
530 | - return ["total"=>0]; |
|
531 | - } |
|
532 | - |
|
533 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
534 | - { |
|
535 | - $pokemon_exclude_sql = ''; |
|
536 | - if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
537 | - $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
538 | - } |
|
539 | - |
|
540 | - $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration |
|
519 | + $result = $this->mysqli->query($req); |
|
520 | + $counts = array(); |
|
521 | + while ($data = $result->fetch_object()) { |
|
522 | + $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
523 | + } |
|
524 | + |
|
525 | + return $counts; |
|
526 | + } |
|
527 | + |
|
528 | + public function getCaptchaCount() |
|
529 | + { |
|
530 | + return ["total"=>0]; |
|
531 | + } |
|
532 | + |
|
533 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
534 | + { |
|
535 | + $pokemon_exclude_sql = ''; |
|
536 | + if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
537 | + $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
538 | + } |
|
539 | + |
|
540 | + $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration |
|
541 | 541 | FROM pokemon p |
542 | 542 | WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).' AND p.spawn_id IS NOT NULL |
543 | 543 | AND p.lat >= '.$minLatitude.' AND p.lat < '.$maxLatitude.' AND p.lon >= '.$minLongitude.' AND p.lon < '.$maxLongitude.' |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | GROUP BY p.spawn_id, p.pokemon_id |
546 | 546 | HAVING COUNT(p.pokemon_id) >= '.($time / 4).' |
547 | 547 | ORDER BY p.pokemon_id'; |
548 | - $result = $this->mysqli->query($req); |
|
549 | - $nests = array(); |
|
550 | - while ($data = $result->fetch_object()) { |
|
551 | - $nests[] = $data; |
|
552 | - } |
|
553 | - $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration |
|
548 | + $result = $this->mysqli->query($req); |
|
549 | + $nests = array(); |
|
550 | + while ($data = $result->fetch_object()) { |
|
551 | + $nests[] = $data; |
|
552 | + } |
|
553 | + $req = 'SELECT p.pokemon_id, MAX(p.lat) AS latitude, MAX(p.lon) AS longitude, count(p.pokemon_id) AS total_pokemon, MAX(p.updated) as latest_seen, 0 as duration |
|
554 | 554 | FROM pokemon p |
555 | 555 | WHERE p.expire_timestamp > UNIX_TIMESTAMP() - '.($time * 3600).' AND p.pokestop_id IS NOT NULL |
556 | 556 | AND p.lat >= '.$minLatitude.' AND p.lat < '.$maxLatitude.' AND p.lon >= '.$minLongitude.' AND p.lon < '.$maxLongitude.' |
@@ -558,22 +558,22 @@ discard block |
||
558 | 558 | GROUP BY p.pokestop_id, p.pokemon_id |
559 | 559 | HAVING COUNT(p.pokemon_id) >= '.($time / 4).' |
560 | 560 | ORDER BY p.pokemon_id'; |
561 | - $result = $this->mysqli->query($req); |
|
562 | - while ($data = $result->fetch_object()) { |
|
563 | - $nests[] = $data; |
|
564 | - } |
|
561 | + $result = $this->mysqli->query($req); |
|
562 | + while ($data = $result->fetch_object()) { |
|
563 | + $nests[] = $data; |
|
564 | + } |
|
565 | 565 | |
566 | - return $nests; |
|
567 | - } |
|
566 | + return $nests; |
|
567 | + } |
|
568 | 568 | |
569 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
570 | - { |
|
571 | - $req = 'SELECT COUNT(*) as total |
|
569 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
570 | + { |
|
571 | + $req = 'SELECT COUNT(*) as total |
|
572 | 572 | FROM spawnpoint |
573 | 573 | WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude; |
574 | - $result = $this->mysqli->query($req); |
|
575 | - $data = $result->fetch_object(); |
|
574 | + $result = $this->mysqli->query($req); |
|
575 | + $data = $result->fetch_object(); |
|
576 | 576 | |
577 | - return $data; |
|
578 | - } |
|
577 | + return $data; |
|
578 | + } |
|
579 | 579 | } |
@@ -4,630 +4,630 @@ discard block |
||
4 | 4 | |
5 | 5 | class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql |
6 | 6 | { |
7 | - public function __construct() |
|
8 | - { |
|
9 | - parent::__construct(); |
|
10 | - } |
|
11 | - |
|
12 | - public function __destruct() |
|
13 | - { |
|
14 | - parent::__destruct(); |
|
15 | - } |
|
16 | - |
|
17 | - /////////// |
|
18 | - // Tester |
|
19 | - /////////// |
|
20 | - |
|
21 | - public function testTotalPokemon() |
|
22 | - { |
|
23 | - $req = 'SELECT COUNT(*) as total FROM sightings'; |
|
24 | - $result = pg_query($this->db, $req); |
|
25 | - if (false === $result) { |
|
26 | - return 1; |
|
27 | - } else { |
|
28 | - $data = pg_fetch_object($result); |
|
29 | - $total = $data->total; |
|
30 | - |
|
31 | - if (0 == $total) { |
|
32 | - return 2; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - return 0; |
|
37 | - } |
|
38 | - |
|
39 | - public function testTotalGyms() |
|
40 | - { |
|
41 | - $req = 'SELECT COUNT(*) as total FROM forts'; |
|
42 | - $result = pg_query($this->db, $req); |
|
43 | - if (false === $result) { |
|
44 | - return 1; |
|
45 | - } else { |
|
46 | - $data = pg_fetch_object($result); |
|
47 | - $total = $data->total; |
|
48 | - |
|
49 | - if (0 == $total) { |
|
50 | - return 2; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return 0; |
|
55 | - } |
|
56 | - |
|
57 | - public function testTotalPokestops() |
|
58 | - { |
|
59 | - $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
60 | - $result = pg_query($this->db, $req); |
|
61 | - if (false === $result) { |
|
62 | - return 1; |
|
63 | - } else { |
|
64 | - $data = pg_fetch_object($result); |
|
65 | - $total = $data->total; |
|
66 | - |
|
67 | - if (0 == $total) { |
|
68 | - return 2; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return 0; |
|
73 | - } |
|
74 | - |
|
75 | - ///////////// |
|
76 | - // Homepage |
|
77 | - ///////////// |
|
78 | - |
|
79 | - public function getTotalPokemon() |
|
80 | - { |
|
81 | - $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())'; |
|
82 | - $result = pg_query($this->db, $req); |
|
83 | - $data = pg_fetch_object($result); |
|
84 | - |
|
85 | - return $data; |
|
86 | - } |
|
87 | - |
|
88 | - public function getTotalLures() |
|
89 | - { |
|
90 | - $data = (object) array('total' => 0); |
|
91 | - |
|
92 | - return $data; |
|
93 | - } |
|
94 | - |
|
95 | - public function getTotalGyms() |
|
96 | - { |
|
97 | - $req = 'SELECT COUNT(*) AS total FROM forts'; |
|
98 | - $result = pg_query($this->db, $req); |
|
99 | - $data = pg_fetch_object($result); |
|
100 | - |
|
101 | - return $data; |
|
102 | - } |
|
103 | - |
|
104 | - public function getTotalRaids() |
|
105 | - { |
|
106 | - $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())'; |
|
107 | - $result = pg_query($this->db, $req); |
|
108 | - $data = pg_fetch_object($result); |
|
109 | - |
|
110 | - return $data; |
|
111 | - } |
|
112 | - |
|
113 | - public function getTotalGymsForTeam($team_id) |
|
114 | - { |
|
115 | - $req = "SELECT COUNT(*) AS total |
|
7 | + public function __construct() |
|
8 | + { |
|
9 | + parent::__construct(); |
|
10 | + } |
|
11 | + |
|
12 | + public function __destruct() |
|
13 | + { |
|
14 | + parent::__destruct(); |
|
15 | + } |
|
16 | + |
|
17 | + /////////// |
|
18 | + // Tester |
|
19 | + /////////// |
|
20 | + |
|
21 | + public function testTotalPokemon() |
|
22 | + { |
|
23 | + $req = 'SELECT COUNT(*) as total FROM sightings'; |
|
24 | + $result = pg_query($this->db, $req); |
|
25 | + if (false === $result) { |
|
26 | + return 1; |
|
27 | + } else { |
|
28 | + $data = pg_fetch_object($result); |
|
29 | + $total = $data->total; |
|
30 | + |
|
31 | + if (0 == $total) { |
|
32 | + return 2; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + return 0; |
|
37 | + } |
|
38 | + |
|
39 | + public function testTotalGyms() |
|
40 | + { |
|
41 | + $req = 'SELECT COUNT(*) as total FROM forts'; |
|
42 | + $result = pg_query($this->db, $req); |
|
43 | + if (false === $result) { |
|
44 | + return 1; |
|
45 | + } else { |
|
46 | + $data = pg_fetch_object($result); |
|
47 | + $total = $data->total; |
|
48 | + |
|
49 | + if (0 == $total) { |
|
50 | + return 2; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return 0; |
|
55 | + } |
|
56 | + |
|
57 | + public function testTotalPokestops() |
|
58 | + { |
|
59 | + $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
60 | + $result = pg_query($this->db, $req); |
|
61 | + if (false === $result) { |
|
62 | + return 1; |
|
63 | + } else { |
|
64 | + $data = pg_fetch_object($result); |
|
65 | + $total = $data->total; |
|
66 | + |
|
67 | + if (0 == $total) { |
|
68 | + return 2; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return 0; |
|
73 | + } |
|
74 | + |
|
75 | + ///////////// |
|
76 | + // Homepage |
|
77 | + ///////////// |
|
78 | + |
|
79 | + public function getTotalPokemon() |
|
80 | + { |
|
81 | + $req = 'SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())'; |
|
82 | + $result = pg_query($this->db, $req); |
|
83 | + $data = pg_fetch_object($result); |
|
84 | + |
|
85 | + return $data; |
|
86 | + } |
|
87 | + |
|
88 | + public function getTotalLures() |
|
89 | + { |
|
90 | + $data = (object) array('total' => 0); |
|
91 | + |
|
92 | + return $data; |
|
93 | + } |
|
94 | + |
|
95 | + public function getTotalGyms() |
|
96 | + { |
|
97 | + $req = 'SELECT COUNT(*) AS total FROM forts'; |
|
98 | + $result = pg_query($this->db, $req); |
|
99 | + $data = pg_fetch_object($result); |
|
100 | + |
|
101 | + return $data; |
|
102 | + } |
|
103 | + |
|
104 | + public function getTotalRaids() |
|
105 | + { |
|
106 | + $req = 'SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())'; |
|
107 | + $result = pg_query($this->db, $req); |
|
108 | + $data = pg_fetch_object($result); |
|
109 | + |
|
110 | + return $data; |
|
111 | + } |
|
112 | + |
|
113 | + public function getTotalGymsForTeam($team_id) |
|
114 | + { |
|
115 | + $req = "SELECT COUNT(*) AS total |
|
116 | 116 | FROM forts f |
117 | 117 | 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)) |
118 | 118 | WHERE team = '$team_id'"; |
119 | - $result = pg_query($this->db, $req); |
|
120 | - $data = pg_fetch_object($result); |
|
119 | + $result = pg_query($this->db, $req); |
|
120 | + $data = pg_fetch_object($result); |
|
121 | 121 | |
122 | - return $data; |
|
123 | - } |
|
122 | + return $data; |
|
123 | + } |
|
124 | 124 | |
125 | - public function getRecentAll() |
|
126 | - { |
|
127 | - $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, |
|
125 | + public function getRecentAll() |
|
126 | + { |
|
127 | + $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, |
|
128 | 128 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
129 | 129 | FROM sightings |
130 | 130 | ORDER BY updated DESC |
131 | 131 | LIMIT 12 OFFSET 0'; |
132 | - $result = pg_query($this->db, $req); |
|
133 | - $data = array(); |
|
134 | - if ($result->num_rows > 0) { |
|
135 | - while ($row = pg_fetch_object($result)) { |
|
136 | - $data[] = $row; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $data; |
|
141 | - } |
|
142 | - |
|
143 | - public function getRecentMythic($mythic_pokemon) |
|
144 | - { |
|
145 | - $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, |
|
132 | + $result = pg_query($this->db, $req); |
|
133 | + $data = array(); |
|
134 | + if ($result->num_rows > 0) { |
|
135 | + while ($row = pg_fetch_object($result)) { |
|
136 | + $data[] = $row; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $data; |
|
141 | + } |
|
142 | + |
|
143 | + public function getRecentMythic($mythic_pokemon) |
|
144 | + { |
|
145 | + $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, |
|
146 | 146 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
147 | 147 | FROM sightings |
148 | 148 | WHERE pokemon_id IN ('.implode(',', $mythic_pokemon).') |
149 | 149 | ORDER BY updated DESC |
150 | 150 | LIMIT 12 OFFSET 0'; |
151 | - $result = pg_query($this->db, $req); |
|
152 | - $data = array(); |
|
153 | - if ($result->num_rows > 0) { |
|
154 | - while ($row = pg_fetch_object($result)) { |
|
155 | - $data[] = $row; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - return $data; |
|
160 | - } |
|
161 | - |
|
162 | - /////////////////// |
|
163 | - // Single Pokemon |
|
164 | - /////////////////// |
|
165 | - |
|
166 | - public function getGymsProtectedByPokemon($pokemon_id) |
|
167 | - { |
|
168 | - $req = "SELECT COUNT(f.id) AS total |
|
151 | + $result = pg_query($this->db, $req); |
|
152 | + $data = array(); |
|
153 | + if ($result->num_rows > 0) { |
|
154 | + while ($row = pg_fetch_object($result)) { |
|
155 | + $data[] = $row; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + return $data; |
|
160 | + } |
|
161 | + |
|
162 | + /////////////////// |
|
163 | + // Single Pokemon |
|
164 | + /////////////////// |
|
165 | + |
|
166 | + public function getGymsProtectedByPokemon($pokemon_id) |
|
167 | + { |
|
168 | + $req = "SELECT COUNT(f.id) AS total |
|
169 | 169 | FROM forts f |
170 | 170 | 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)) |
171 | 171 | WHERE guard_pokemon_id = '".$pokemon_id."'"; |
172 | - $result = pg_query($this->db, $req); |
|
173 | - $data = pg_fetch_object($result); |
|
172 | + $result = pg_query($this->db, $req); |
|
173 | + $data = pg_fetch_object($result); |
|
174 | 174 | |
175 | - return $data; |
|
176 | - } |
|
175 | + return $data; |
|
176 | + } |
|
177 | 177 | |
178 | - public function getPokemonLastSeen($pokemon_id) |
|
179 | - { |
|
180 | - $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
178 | + public function getPokemonLastSeen($pokemon_id) |
|
179 | + { |
|
180 | + $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
|
181 | 181 | FROM sightings |
182 | 182 | WHERE pokemon_id = '".$pokemon_id."' |
183 | 183 | ORDER BY expire_timestamp DESC |
184 | 184 | LIMIT 1 OFFSET 0"; |
185 | - $result = pg_query($this->db, $req); |
|
186 | - $data = pg_fetch_object($result); |
|
185 | + $result = pg_query($this->db, $req); |
|
186 | + $data = pg_fetch_object($result); |
|
187 | 187 | |
188 | - return $data; |
|
189 | - } |
|
188 | + return $data; |
|
189 | + } |
|
190 | 190 | |
191 | - public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | - { |
|
193 | - $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, |
|
191 | + public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
192 | + { |
|
193 | + $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, |
|
194 | 194 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
195 | 195 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
196 | 196 | FROM sightings |
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, expire_timestamp DESC |
199 | 199 | LIMIT 50 OFFSET 0"; |
200 | - $result = pg_query($this->db, $req); |
|
201 | - $top = array(); |
|
202 | - while ($data = pg_fetch_object($result)) { |
|
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 owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
214 | - } |
|
215 | - |
|
216 | - $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, |
|
200 | + $result = pg_query($this->db, $req); |
|
201 | + $top = array(); |
|
202 | + while ($data = pg_fetch_object($result)) { |
|
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 owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
214 | + } |
|
215 | + |
|
216 | + $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, |
|
217 | 217 | TO_TIMESTAMP(last_modified) AS lasttime, last_modified as last_seen |
218 | 218 | FROM gym_defenders |
219 | 219 | WHERE pokemon_id = '".$pokemon_id."'".$trainer_blacklist." |
220 | 220 | ORDER BY $best_order_by $best_direction, owner_name ASC |
221 | 221 | LIMIT 50 OFFSET 0"; |
222 | 222 | |
223 | - $result = pg_query($this->db, $req); |
|
224 | - $toptrainer = array(); |
|
225 | - while ($data = pg_fetch_object($result)) { |
|
226 | - $toptrainer[] = $data; |
|
227 | - } |
|
228 | - |
|
229 | - return $toptrainer; |
|
230 | - } |
|
231 | - |
|
232 | - public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
233 | - { |
|
234 | - $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
235 | - ."AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
236 | - $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000'; |
|
237 | - $result = pg_query($this->db, $req); |
|
238 | - $points = array(); |
|
239 | - while ($data = pg_fetch_object($result)) { |
|
240 | - $points[] = $data; |
|
241 | - } |
|
242 | - |
|
243 | - return $points; |
|
244 | - } |
|
245 | - |
|
246 | - public function getPokemonGraph($pokemon_id) |
|
247 | - { |
|
248 | - $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour |
|
223 | + $result = pg_query($this->db, $req); |
|
224 | + $toptrainer = array(); |
|
225 | + while ($data = pg_fetch_object($result)) { |
|
226 | + $toptrainer[] = $data; |
|
227 | + } |
|
228 | + |
|
229 | + return $toptrainer; |
|
230 | + } |
|
231 | + |
|
232 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
233 | + { |
|
234 | + $where = ' WHERE pokemon_id = '.$pokemon_id.' ' |
|
235 | + ."AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
|
236 | + $req = 'SELECT lat AS latitude, lon AS longitude FROM sightings'.$where.' LIMIT 100000'; |
|
237 | + $result = pg_query($this->db, $req); |
|
238 | + $points = array(); |
|
239 | + while ($data = pg_fetch_object($result)) { |
|
240 | + $points[] = $data; |
|
241 | + } |
|
242 | + |
|
243 | + return $points; |
|
244 | + } |
|
245 | + |
|
246 | + public function getPokemonGraph($pokemon_id) |
|
247 | + { |
|
248 | + $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour |
|
249 | 249 | FROM (SELECT TO_TIMESTAMP(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
250 | 250 | GROUP BY disappear_hour |
251 | 251 | ORDER BY disappear_hour"; |
252 | - $result = pg_query($this->db, $req); |
|
253 | - $array = array_fill(0, 24, 0); |
|
254 | - while ($result && $data = pg_fetch_object($result)) { |
|
255 | - $array[$data->disappear_hour] = $data->total; |
|
256 | - } |
|
257 | - // shift array because AM/PM starts at 1AM not 0:00 |
|
258 | - $array[] = $array[0]; |
|
259 | - array_shift($array); |
|
260 | - |
|
261 | - return $array; |
|
262 | - } |
|
263 | - |
|
264 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
265 | - { |
|
266 | - $inmap_pkms_filter = ''; |
|
267 | - $where = ' WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = '.$pokemon_id; |
|
268 | - |
|
269 | - $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where; |
|
270 | - $resultTestIv = pg_query($this->db, $reqTestIv); |
|
271 | - $testIv = pg_fetch_object($resultTestIv); |
|
272 | - if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
273 | - foreach ($inmap_pokemons as $inmap) { |
|
274 | - $inmap_pkms_filter .= "'".$inmap."',"; |
|
275 | - } |
|
276 | - $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
277 | - $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
278 | - } |
|
279 | - if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
280 | - $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') '; |
|
281 | - } |
|
282 | - if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
283 | - $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') '; |
|
284 | - } |
|
285 | - $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
252 | + $result = pg_query($this->db, $req); |
|
253 | + $array = array_fill(0, 24, 0); |
|
254 | + while ($result && $data = pg_fetch_object($result)) { |
|
255 | + $array[$data->disappear_hour] = $data->total; |
|
256 | + } |
|
257 | + // shift array because AM/PM starts at 1AM not 0:00 |
|
258 | + $array[] = $array[0]; |
|
259 | + array_shift($array); |
|
260 | + |
|
261 | + return $array; |
|
262 | + } |
|
263 | + |
|
264 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
265 | + { |
|
266 | + $inmap_pkms_filter = ''; |
|
267 | + $where = ' WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = '.$pokemon_id; |
|
268 | + |
|
269 | + $reqTestIv = 'SELECT MAX(atk_iv) AS iv FROM sightings '.$where; |
|
270 | + $resultTestIv = pg_query($this->db, $reqTestIv); |
|
271 | + $testIv = pg_fetch_object($resultTestIv); |
|
272 | + if (!is_null($inmap_pokemons) && ('' != $inmap_pokemons)) { |
|
273 | + foreach ($inmap_pokemons as $inmap) { |
|
274 | + $inmap_pkms_filter .= "'".$inmap."',"; |
|
275 | + } |
|
276 | + $inmap_pkms_filter = rtrim($inmap_pkms_filter, ','); |
|
277 | + $where .= ' AND encounter_id NOT IN ('.$inmap_pkms_filter.') '; |
|
278 | + } |
|
279 | + if (null != $testIv->iv && !is_null($ivMin) && ('' != $ivMin)) { |
|
280 | + $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) >= ('.$ivMin.') '; |
|
281 | + } |
|
282 | + if (null != $testIv->iv && !is_null($ivMax) && ('' != $ivMax)) { |
|
283 | + $where .= ' AND ((100/45)*(atk_iv + def_iv + sta_iv)) <= ('.$ivMax.') '; |
|
284 | + } |
|
285 | + $req = 'SELECT pokemon_id, lat AS latitude, lon AS longitude, |
|
286 | 286 | TO_TIMESTAMP(expire_timestamp) AS disappear_time, |
287 | 287 | TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
288 | 288 | atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina, |
289 | 289 | move_1, move_2 |
290 | 290 | FROM sightings '.$where.' |
291 | 291 | LIMIT 5000'; |
292 | - $result = pg_query($this->db, $req); |
|
293 | - $spawns = array(); |
|
294 | - while ($data = pg_fetch_object($result)) { |
|
295 | - $spawns[] = $data; |
|
296 | - } |
|
297 | - |
|
298 | - return $spawns; |
|
299 | - } |
|
300 | - |
|
301 | - public function getPokemonSliderMinMax() |
|
302 | - { |
|
303 | - $req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings'; |
|
304 | - $result = pg_query($this->db, $req); |
|
305 | - $data = pg_fetch_object($result); |
|
306 | - |
|
307 | - return $data; |
|
308 | - } |
|
309 | - |
|
310 | - public function getMapsCoords() |
|
311 | - { |
|
312 | - $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints'; |
|
313 | - $result = pg_query($this->db, $req); |
|
314 | - $data = pg_fetch_object($result); |
|
315 | - |
|
316 | - return $data; |
|
317 | - } |
|
318 | - |
|
319 | - public function getPokemonCount($pokemon_id) |
|
320 | - { |
|
321 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
292 | + $result = pg_query($this->db, $req); |
|
293 | + $spawns = array(); |
|
294 | + while ($data = pg_fetch_object($result)) { |
|
295 | + $spawns[] = $data; |
|
296 | + } |
|
297 | + |
|
298 | + return $spawns; |
|
299 | + } |
|
300 | + |
|
301 | + public function getPokemonSliderMinMax() |
|
302 | + { |
|
303 | + $req = 'SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings'; |
|
304 | + $result = pg_query($this->db, $req); |
|
305 | + $data = pg_fetch_object($result); |
|
306 | + |
|
307 | + return $data; |
|
308 | + } |
|
309 | + |
|
310 | + public function getMapsCoords() |
|
311 | + { |
|
312 | + $req = 'SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints'; |
|
313 | + $result = pg_query($this->db, $req); |
|
314 | + $data = pg_fetch_object($result); |
|
315 | + |
|
316 | + return $data; |
|
317 | + } |
|
318 | + |
|
319 | + public function getPokemonCount($pokemon_id) |
|
320 | + { |
|
321 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
322 | 322 | FROM pokemon_stats |
323 | 323 | WHERE pid = '.$pokemon_id; |
324 | - $result = pg_query($this->db, $req); |
|
325 | - $data = pg_fetch_object($result); |
|
324 | + $result = pg_query($this->db, $req); |
|
325 | + $data = pg_fetch_object($result); |
|
326 | 326 | |
327 | - return $data; |
|
328 | - } |
|
327 | + return $data; |
|
328 | + } |
|
329 | 329 | |
330 | - public function getPokemonCountAll() |
|
331 | - { |
|
332 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
330 | + public function getPokemonCountAll() |
|
331 | + { |
|
332 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
333 | 333 | FROM pokemon_stats |
334 | 334 | GROUP BY pid'; |
335 | - $result = $this->mysqli->query($req); |
|
336 | - $array = array(); |
|
337 | - while ($data = pg_fetch_object($result)) { |
|
338 | - $array[] = $data; |
|
339 | - } |
|
340 | - |
|
341 | - return $array; |
|
342 | - } |
|
343 | - |
|
344 | - public function getRaidCount($pokemon_id) |
|
345 | - { |
|
346 | - $req = 'SELECT count, last_seen, latitude, longitude |
|
335 | + $result = $this->mysqli->query($req); |
|
336 | + $array = array(); |
|
337 | + while ($data = pg_fetch_object($result)) { |
|
338 | + $array[] = $data; |
|
339 | + } |
|
340 | + |
|
341 | + return $array; |
|
342 | + } |
|
343 | + |
|
344 | + public function getRaidCount($pokemon_id) |
|
345 | + { |
|
346 | + $req = 'SELECT count, last_seen, latitude, longitude |
|
347 | 347 | FROM raid_stats |
348 | 348 | WHERE pid = '.$pokemon_id; |
349 | - $result = pg_query($this->db, $req); |
|
350 | - $data = pg_fetch_object($result); |
|
349 | + $result = pg_query($this->db, $req); |
|
350 | + $data = pg_fetch_object($result); |
|
351 | 351 | |
352 | - return $data; |
|
353 | - } |
|
352 | + return $data; |
|
353 | + } |
|
354 | 354 | |
355 | - public function getRaidCountAll() |
|
356 | - { |
|
357 | - $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
355 | + public function getRaidCountAll() |
|
356 | + { |
|
357 | + $req = 'SELECT pid as pokemon_id, count, last_seen, latitude, longitude |
|
358 | 358 | FROM raid_stats |
359 | 359 | GROUP BY pid'; |
360 | - $result = $this->mysqli->query($req); |
|
361 | - $array = array(); |
|
362 | - while ($data = pg_fetch_object($result)) { |
|
363 | - $array[] = $data; |
|
364 | - } |
|
365 | - |
|
366 | - return $array; |
|
367 | - } |
|
368 | - |
|
369 | - /////////////// |
|
370 | - // Pokestops |
|
371 | - ////////////// |
|
372 | - |
|
373 | - public function getTotalPokestops() |
|
374 | - { |
|
375 | - $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
376 | - $result = pg_query($this->db, $req); |
|
377 | - $data = pg_fetch_object($result); |
|
378 | - |
|
379 | - return $data; |
|
380 | - } |
|
381 | - |
|
382 | - public function getAllPokestops() |
|
383 | - { |
|
384 | - $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'; |
|
385 | - $result = pg_query($this->db, $req); |
|
386 | - $pokestops = array(); |
|
387 | - while ($data = pg_fetch_object($result)) { |
|
388 | - $pokestops[] = $data; |
|
389 | - } |
|
390 | - |
|
391 | - return $pokestops; |
|
392 | - } |
|
393 | - |
|
394 | - ///////// |
|
395 | - // Gyms |
|
396 | - ///////// |
|
397 | - |
|
398 | - public function getTeamGuardians($team_id) |
|
399 | - { |
|
400 | - $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
360 | + $result = $this->mysqli->query($req); |
|
361 | + $array = array(); |
|
362 | + while ($data = pg_fetch_object($result)) { |
|
363 | + $array[] = $data; |
|
364 | + } |
|
365 | + |
|
366 | + return $array; |
|
367 | + } |
|
368 | + |
|
369 | + /////////////// |
|
370 | + // Pokestops |
|
371 | + ////////////// |
|
372 | + |
|
373 | + public function getTotalPokestops() |
|
374 | + { |
|
375 | + $req = 'SELECT COUNT(*) as total FROM pokestops'; |
|
376 | + $result = pg_query($this->db, $req); |
|
377 | + $data = pg_fetch_object($result); |
|
378 | + |
|
379 | + return $data; |
|
380 | + } |
|
381 | + |
|
382 | + public function getAllPokestops() |
|
383 | + { |
|
384 | + $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'; |
|
385 | + $result = pg_query($this->db, $req); |
|
386 | + $pokestops = array(); |
|
387 | + while ($data = pg_fetch_object($result)) { |
|
388 | + $pokestops[] = $data; |
|
389 | + } |
|
390 | + |
|
391 | + return $pokestops; |
|
392 | + } |
|
393 | + |
|
394 | + ///////// |
|
395 | + // Gyms |
|
396 | + ///////// |
|
397 | + |
|
398 | + public function getTeamGuardians($team_id) |
|
399 | + { |
|
400 | + $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
|
401 | 401 | FROM forts f |
402 | 402 | 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)) |
403 | 403 | WHERE team = '".$team_id."' GROUP BY guard_pokemon_id ORDER BY total DESC LIMIT 3 OFFSET 0"; |
404 | - $result = pg_query($this->db, $req); |
|
404 | + $result = pg_query($this->db, $req); |
|
405 | 405 | |
406 | - $datas = array(); |
|
407 | - while ($data = pg_fetch_object($result)) { |
|
408 | - $datas[] = $data; |
|
409 | - } |
|
406 | + $datas = array(); |
|
407 | + while ($data = pg_fetch_object($result)) { |
|
408 | + $datas[] = $data; |
|
409 | + } |
|
410 | 410 | |
411 | - return $datas; |
|
412 | - } |
|
411 | + return $datas; |
|
412 | + } |
|
413 | 413 | |
414 | - public function getOwnedAndPoints($team_id) |
|
415 | - { |
|
416 | - $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points |
|
414 | + public function getOwnedAndPoints($team_id) |
|
415 | + { |
|
416 | + $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points |
|
417 | 417 | FROM forts f |
418 | 418 | 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)) |
419 | 419 | WHERE fs.team = '".$team_id."'"; |
420 | - $result = pg_query($this->db, $req); |
|
421 | - $data = pg_fetch_object($result); |
|
420 | + $result = pg_query($this->db, $req); |
|
421 | + $data = pg_fetch_object($result); |
|
422 | 422 | |
423 | - return $data; |
|
424 | - } |
|
423 | + return $data; |
|
424 | + } |
|
425 | 425 | |
426 | - public function getAllGyms() |
|
427 | - { |
|
428 | - $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 |
|
426 | + public function getAllGyms() |
|
427 | + { |
|
428 | + $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 |
|
429 | 429 | FROM forts f |
430 | 430 | 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))'; |
431 | - $result = pg_query($this->db, $req); |
|
432 | - $gyms = array(); |
|
433 | - while ($data = pg_fetch_object($result)) { |
|
434 | - $gyms[] = $data; |
|
435 | - } |
|
436 | - |
|
437 | - return $gyms; |
|
438 | - } |
|
439 | - |
|
440 | - public function getGymData($gym_id) |
|
441 | - { |
|
442 | - $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 |
|
431 | + $result = pg_query($this->db, $req); |
|
432 | + $gyms = array(); |
|
433 | + while ($data = pg_fetch_object($result)) { |
|
434 | + $gyms[] = $data; |
|
435 | + } |
|
436 | + |
|
437 | + return $gyms; |
|
438 | + } |
|
439 | + |
|
440 | + public function getGymData($gym_id) |
|
441 | + { |
|
442 | + $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 |
|
443 | 443 | FROM forts f |
444 | 444 | 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)) |
445 | 445 | WHERE f.id ='".$gym_id."' |
446 | 446 | GROUP BY f.name, f.url, fs.team, fs.updated, fs.guard_pokemon_id, fs.slots_available, gd.cp"; |
447 | - $result = pg_query($this->db, $req); |
|
448 | - $data = pg_fetch_object($result); |
|
447 | + $result = pg_query($this->db, $req); |
|
448 | + $data = pg_fetch_object($result); |
|
449 | 449 | |
450 | - return $data; |
|
451 | - } |
|
450 | + return $data; |
|
451 | + } |
|
452 | 452 | |
453 | - public function getGymDefenders($gym_id) |
|
454 | - { |
|
455 | - $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 |
|
453 | + public function getGymDefenders($gym_id) |
|
454 | + { |
|
455 | + $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 |
|
456 | 456 | FROM gym_defenders |
457 | 457 | WHERE fort_id='".$gym_id."' |
458 | 458 | ORDER BY deployment_time"; |
459 | - $result = pg_query($this->db, $req); |
|
460 | - $defenders = array(); |
|
461 | - while ($data = pg_fetch_object($result)) { |
|
462 | - $defenders[] = $data; |
|
463 | - } |
|
464 | - |
|
465 | - return $defenders; |
|
466 | - } |
|
467 | - |
|
468 | - //////////////// |
|
469 | - // Gym History |
|
470 | - //////////////// |
|
471 | - |
|
472 | - public function getGymHistories($gym_name, $team, $page, $ranking) |
|
473 | - { |
|
474 | - $where = ''; |
|
475 | - if (isset($gym_name) && '' != $gym_name) { |
|
476 | - $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
477 | - } |
|
478 | - if (isset($team) && '' != $team) { |
|
479 | - $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team; |
|
480 | - } |
|
481 | - switch ($ranking) { |
|
482 | - case 1: |
|
483 | - $order = ' ORDER BY name, last_modified DESC'; |
|
484 | - break; |
|
485 | - case 2: |
|
486 | - $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
487 | - break; |
|
488 | - default: |
|
489 | - $order = ' ORDER BY last_modified DESC, name'; |
|
490 | - } |
|
491 | - |
|
492 | - $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
493 | - |
|
494 | - $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 |
|
459 | + $result = pg_query($this->db, $req); |
|
460 | + $defenders = array(); |
|
461 | + while ($data = pg_fetch_object($result)) { |
|
462 | + $defenders[] = $data; |
|
463 | + } |
|
464 | + |
|
465 | + return $defenders; |
|
466 | + } |
|
467 | + |
|
468 | + //////////////// |
|
469 | + // Gym History |
|
470 | + //////////////// |
|
471 | + |
|
472 | + public function getGymHistories($gym_name, $team, $page, $ranking) |
|
473 | + { |
|
474 | + $where = ''; |
|
475 | + if (isset($gym_name) && '' != $gym_name) { |
|
476 | + $where = " WHERE name LIKE '%".$gym_name."%'"; |
|
477 | + } |
|
478 | + if (isset($team) && '' != $team) { |
|
479 | + $where .= ('' === $where ? ' WHERE' : ' AND').' fs.team = '.$team; |
|
480 | + } |
|
481 | + switch ($ranking) { |
|
482 | + case 1: |
|
483 | + $order = ' ORDER BY name, last_modified DESC'; |
|
484 | + break; |
|
485 | + case 2: |
|
486 | + $order = ' ORDER BY total_cp DESC, last_modified DESC'; |
|
487 | + break; |
|
488 | + default: |
|
489 | + $order = ' ORDER BY last_modified DESC, name'; |
|
490 | + } |
|
491 | + |
|
492 | + $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
493 | + |
|
494 | + $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 |
|
495 | 495 | FROM forts f |
496 | 496 | 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)) |
497 | 497 | '.$where.$order.$limit; |
498 | 498 | |
499 | - $result = pg_query($this->db, $req); |
|
500 | - $gym_history = array(); |
|
501 | - while ($data = pg_fetch_object($result)) { |
|
502 | - $gym_history[] = $data; |
|
503 | - } |
|
499 | + $result = pg_query($this->db, $req); |
|
500 | + $gym_history = array(); |
|
501 | + while ($data = pg_fetch_object($result)) { |
|
502 | + $gym_history[] = $data; |
|
503 | + } |
|
504 | 504 | |
505 | - return $gym_history; |
|
506 | - } |
|
505 | + return $gym_history; |
|
506 | + } |
|
507 | 507 | |
508 | - public function getGymHistoriesPokemon($gym_id) |
|
509 | - { |
|
510 | - $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
|
508 | + public function getGymHistoriesPokemon($gym_id) |
|
509 | + { |
|
510 | + $req = "SELECT external_id AS pokemon_uid, pokemon_id, cp_now as cp, owner_name AS trainer_name |
|
511 | 511 | FROM gym_defenders |
512 | 512 | WHERE fort_id = '".$gym_id."' |
513 | 513 | ORDER BY deployment_time"; |
514 | - $result = pg_query($this->db, $req); |
|
515 | - $pokemons = array(); |
|
516 | - while ($data = pg_fetch_object($result)) { |
|
517 | - $pokemons[] = $data; |
|
518 | - } |
|
519 | - |
|
520 | - return $pokemons; |
|
521 | - } |
|
522 | - |
|
523 | - public function getHistoryForGym($page, $gym_id) |
|
524 | - { |
|
525 | - if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
526 | - $pageSize = 25; |
|
527 | - } else { |
|
528 | - $pageSize = 10; |
|
529 | - } |
|
530 | - $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 |
|
514 | + $result = pg_query($this->db, $req); |
|
515 | + $pokemons = array(); |
|
516 | + while ($data = pg_fetch_object($result)) { |
|
517 | + $pokemons[] = $data; |
|
518 | + } |
|
519 | + |
|
520 | + return $pokemons; |
|
521 | + } |
|
522 | + |
|
523 | + public function getHistoryForGym($page, $gym_id) |
|
524 | + { |
|
525 | + if (isset(self::$config->system->gymhistory_hide_cp_changes) && true === self::$config->system->gymhistory_hide_cp_changes) { |
|
526 | + $pageSize = 25; |
|
527 | + } else { |
|
528 | + $pageSize = 10; |
|
529 | + } |
|
530 | + $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 |
|
531 | 531 | FROM fort_sightings fs |
532 | 532 | LEFT JOIN forts f ON f.id = fs.fort_id |
533 | 533 | WHERE f.id = '".$gym_id."' |
534 | 534 | ORDER BY fs.last_modified DESC |
535 | 535 | LIMIT ".($pageSize + 1).' OFFSET '.($page * $pageSize); |
536 | - $result = pg_query($this->db, $req); |
|
537 | - $history = array(); |
|
538 | - $count = 0; |
|
539 | - while ($data = pg_fetch_object($result)) { |
|
540 | - ++$count; |
|
541 | - if (0 == $data->total_cp) { |
|
542 | - $data->pokemon = array(); |
|
543 | - $data->pokemon_count = 0; |
|
544 | - $data->pokemon_uids = ''; |
|
545 | - } else { |
|
546 | - $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
547 | - $data->pokemon_count = count($data->pokemon); |
|
548 | - $data->pokemon_uids = implode(',', array_keys($data->pokemon)); |
|
549 | - } |
|
550 | - if (0 === $data->total_cp || 0 !== $data->pokemon_count) { |
|
551 | - $history[] = $data; |
|
552 | - } |
|
553 | - } |
|
554 | - if ($count !== ($pageSize + 1)) { |
|
555 | - $last_page = true; |
|
556 | - } else { |
|
557 | - $last_page = false; |
|
558 | - } |
|
559 | - |
|
560 | - return array('last_page' => $last_page, 'data' => $history); |
|
561 | - } |
|
562 | - |
|
563 | - private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
564 | - { |
|
565 | - $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
536 | + $result = pg_query($this->db, $req); |
|
537 | + $history = array(); |
|
538 | + $count = 0; |
|
539 | + while ($data = pg_fetch_object($result)) { |
|
540 | + ++$count; |
|
541 | + if (0 == $data->total_cp) { |
|
542 | + $data->pokemon = array(); |
|
543 | + $data->pokemon_count = 0; |
|
544 | + $data->pokemon_uids = ''; |
|
545 | + } else { |
|
546 | + $data->pokemon = $this->getHistoryForGymPokemon($gym_id, $data->last_modified_real); |
|
547 | + $data->pokemon_count = count($data->pokemon); |
|
548 | + $data->pokemon_uids = implode(',', array_keys($data->pokemon)); |
|
549 | + } |
|
550 | + if (0 === $data->total_cp || 0 !== $data->pokemon_count) { |
|
551 | + $history[] = $data; |
|
552 | + } |
|
553 | + } |
|
554 | + if ($count !== ($pageSize + 1)) { |
|
555 | + $last_page = true; |
|
556 | + } else { |
|
557 | + $last_page = false; |
|
558 | + } |
|
559 | + |
|
560 | + return array('last_page' => $last_page, 'data' => $history); |
|
561 | + } |
|
562 | + |
|
563 | + private function getHistoryForGymPokemon($gym_id, $last_modified) |
|
564 | + { |
|
565 | + $req = "SELECT ghd.defender_id, gd.pokemon_id, ghd.cp, gd.owner_name as trainer_name |
|
566 | 566 | FROM gym_history_defenders ghd |
567 | 567 | JOIN gym_defenders gd ON ghd.defender_id = gd.external_id |
568 | 568 | WHERE ghd.fort_id = '".$gym_id."' AND date = '".$last_modified."' |
569 | 569 | ORDER BY gd.deployment_time"; |
570 | - $result = pg_query($this->db, $req); |
|
571 | - $pokemons = array(); |
|
572 | - while ($data = pg_fetch_object($result)) { |
|
573 | - $pokemons[$data->defender_id] = $data; |
|
574 | - } |
|
575 | - |
|
576 | - return $pokemons; |
|
577 | - } |
|
578 | - |
|
579 | - /////////// |
|
580 | - // Raids |
|
581 | - /////////// |
|
582 | - |
|
583 | - public function getAllRaids($page) |
|
584 | - { |
|
585 | - $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
586 | - $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 |
|
570 | + $result = pg_query($this->db, $req); |
|
571 | + $pokemons = array(); |
|
572 | + while ($data = pg_fetch_object($result)) { |
|
573 | + $pokemons[$data->defender_id] = $data; |
|
574 | + } |
|
575 | + |
|
576 | + return $pokemons; |
|
577 | + } |
|
578 | + |
|
579 | + /////////// |
|
580 | + // Raids |
|
581 | + /////////// |
|
582 | + |
|
583 | + public function getAllRaids($page) |
|
584 | + { |
|
585 | + $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
586 | + $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 |
|
587 | 587 | FROM forts f |
588 | 588 | 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)) |
589 | 589 | LEFT JOIN raids r ON (r.fort_id = f.id AND r.time_end >= UNIX_TIMESTAMP()) |
590 | 590 | WHERE r.time_end > EXTRACT(EPOCH FROM NOW()) |
591 | 591 | ORDER BY r.level DESC, r.time_battle'.$limit; |
592 | - $result = pg_query($this->db, $req); |
|
593 | - $raids = array(); |
|
594 | - while ($data = pg_fetch_object($result)) { |
|
595 | - $raids[] = $data; |
|
596 | - } |
|
597 | - |
|
598 | - return $raids; |
|
599 | - } |
|
600 | - |
|
601 | - ////////////// |
|
602 | - // Trainers |
|
603 | - ////////////// |
|
604 | - |
|
605 | - public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
606 | - { |
|
607 | - $ranking = $this->getTrainerLevelRanking(); |
|
608 | - $where = ''; |
|
609 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
610 | - $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
611 | - } |
|
612 | - if ('' != $trainer_name) { |
|
613 | - $where = " AND gd.owner_name LIKE '%".$trainer_name."%'"; |
|
614 | - } |
|
615 | - if (0 != $team) { |
|
616 | - $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
617 | - } |
|
618 | - switch ($rankingNumber) { |
|
619 | - case 1: |
|
620 | - $order = ' ORDER BY active DESC, level DESC'; |
|
621 | - break; |
|
622 | - case 2: |
|
623 | - $order = ' ORDER BY maxCp DESC, level DESC'; |
|
624 | - break; |
|
625 | - default: |
|
626 | - $order = ' ORDER BY level DESC, active DESC'; |
|
627 | - } |
|
628 | - $order .= ', last_seen DESC, name '; |
|
629 | - $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
630 | - $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 |
|
592 | + $result = pg_query($this->db, $req); |
|
593 | + $raids = array(); |
|
594 | + while ($data = pg_fetch_object($result)) { |
|
595 | + $raids[] = $data; |
|
596 | + } |
|
597 | + |
|
598 | + return $raids; |
|
599 | + } |
|
600 | + |
|
601 | + ////////////// |
|
602 | + // Trainers |
|
603 | + ////////////// |
|
604 | + |
|
605 | + public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
606 | + { |
|
607 | + $ranking = $this->getTrainerLevelRanking(); |
|
608 | + $where = ''; |
|
609 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
610 | + $where .= " AND gd.owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
611 | + } |
|
612 | + if ('' != $trainer_name) { |
|
613 | + $where = " AND gd.owner_name LIKE '%".$trainer_name."%'"; |
|
614 | + } |
|
615 | + if (0 != $team) { |
|
616 | + $where .= ('' == $where ? ' HAVING' : ' AND').' team = '.$team; |
|
617 | + } |
|
618 | + switch ($rankingNumber) { |
|
619 | + case 1: |
|
620 | + $order = ' ORDER BY active DESC, level DESC'; |
|
621 | + break; |
|
622 | + case 2: |
|
623 | + $order = ' ORDER BY maxCp DESC, level DESC'; |
|
624 | + break; |
|
625 | + default: |
|
626 | + $order = ' ORDER BY level DESC, active DESC'; |
|
627 | + } |
|
628 | + $order .= ', last_seen DESC, name '; |
|
629 | + $limit = ' LIMIT 10 OFFSET '.($page * 10); |
|
630 | + $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 |
|
631 | 631 | FROM gym_defenders gd |
632 | 632 | LEFT JOIN ( |
633 | 633 | SELECT owner_name, COUNT(*) as active |
@@ -637,158 +637,158 @@ discard block |
||
637 | 637 | ) active ON active.owner_name = gd.owner_name |
638 | 638 | WHERE level IS NOT NULL '.$where.' |
639 | 639 | GROUP BY gd.owner_name'.$order.$limit; |
640 | - $result = pg_query($this->db, $req); |
|
641 | - $trainers = array(); |
|
642 | - while ($data = pg_fetch_object($result)) { |
|
643 | - $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
644 | - if (is_null($data->active)) { |
|
645 | - $data->active = 0; |
|
646 | - } |
|
647 | - $trainers[$data->name] = $data; |
|
648 | - |
|
649 | - $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
650 | - |
|
651 | - $trainers[$data->name]->gyms = $data->active; |
|
652 | - $trainers[$data->name]->pokemons = $pokemon; |
|
653 | - $trainers[$data->name]->rank = $ranking[$data->level]; |
|
654 | - } |
|
655 | - |
|
656 | - return $trainers; |
|
657 | - } |
|
658 | - |
|
659 | - public function getTrainerLevelRanking() |
|
660 | - { |
|
661 | - $exclue = ''; |
|
662 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
663 | - $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
664 | - } |
|
665 | - $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'; |
|
666 | - $result = pg_query($this->db, $req); |
|
667 | - $levelData = array(); |
|
668 | - while ($data = pg_fetch_object($result)) { |
|
669 | - $levelData[$data->level] = $data->count; |
|
670 | - } |
|
671 | - for ($i = 5; $i <= 40; ++$i) { |
|
672 | - if (!isset($levelData[$i])) { |
|
673 | - $levelData[$i] = 0; |
|
674 | - } |
|
675 | - } |
|
676 | - // sort array again |
|
677 | - ksort($levelData); |
|
678 | - |
|
679 | - return $levelData; |
|
680 | - } |
|
681 | - |
|
682 | - public function getActivePokemon($trainer_name) |
|
683 | - { |
|
684 | - $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 |
|
640 | + $result = pg_query($this->db, $req); |
|
641 | + $trainers = array(); |
|
642 | + while ($data = pg_fetch_object($result)) { |
|
643 | + $data->last_seen = date('Y-m-d', strtotime($data->last_seen)); |
|
644 | + if (is_null($data->active)) { |
|
645 | + $data->active = 0; |
|
646 | + } |
|
647 | + $trainers[$data->name] = $data; |
|
648 | + |
|
649 | + $pokemon = array_merge($this->getActivePokemon($data->name), $this->getInactivePokemon($data->name)); |
|
650 | + |
|
651 | + $trainers[$data->name]->gyms = $data->active; |
|
652 | + $trainers[$data->name]->pokemons = $pokemon; |
|
653 | + $trainers[$data->name]->rank = $ranking[$data->level]; |
|
654 | + } |
|
655 | + |
|
656 | + return $trainers; |
|
657 | + } |
|
658 | + |
|
659 | + public function getTrainerLevelRanking() |
|
660 | + { |
|
661 | + $exclue = ''; |
|
662 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
663 | + $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
664 | + } |
|
665 | + $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'; |
|
666 | + $result = pg_query($this->db, $req); |
|
667 | + $levelData = array(); |
|
668 | + while ($data = pg_fetch_object($result)) { |
|
669 | + $levelData[$data->level] = $data->count; |
|
670 | + } |
|
671 | + for ($i = 5; $i <= 40; ++$i) { |
|
672 | + if (!isset($levelData[$i])) { |
|
673 | + $levelData[$i] = 0; |
|
674 | + } |
|
675 | + } |
|
676 | + // sort array again |
|
677 | + ksort($levelData); |
|
678 | + |
|
679 | + return $levelData; |
|
680 | + } |
|
681 | + |
|
682 | + public function getActivePokemon($trainer_name) |
|
683 | + { |
|
684 | + $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 |
|
685 | 685 | FROM gym_defenders |
686 | 686 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL |
687 | 687 | ORDER BY deployment_time"; |
688 | - $result = pg_query($this->db, $req); |
|
689 | - $pokemon = array(); |
|
690 | - while ($data = pg_fetch_object($result)) { |
|
691 | - $pokemon[] = $data; |
|
692 | - } |
|
693 | - |
|
694 | - return $pokemon; |
|
695 | - } |
|
696 | - |
|
697 | - public function getInactivePokemon($trainer_name) |
|
698 | - { |
|
699 | - $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 |
|
688 | + $result = pg_query($this->db, $req); |
|
689 | + $pokemon = array(); |
|
690 | + while ($data = pg_fetch_object($result)) { |
|
691 | + $pokemon[] = $data; |
|
692 | + } |
|
693 | + |
|
694 | + return $pokemon; |
|
695 | + } |
|
696 | + |
|
697 | + public function getInactivePokemon($trainer_name) |
|
698 | + { |
|
699 | + $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 |
|
700 | 700 | FROM gym_defenders |
701 | 701 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL |
702 | 702 | ORDER BY last_scanned"; |
703 | - $result = pg_query($this->db, $req); |
|
704 | - $pokemon = array(); |
|
705 | - while ($data = pg_fetch_object($result)) { |
|
706 | - $pokemon[] = $data; |
|
707 | - } |
|
708 | - |
|
709 | - return $pokemon; |
|
710 | - } |
|
711 | - |
|
712 | - public function getTrainerLevelCount($team_id) |
|
713 | - { |
|
714 | - $exclue = ''; |
|
715 | - if (!empty(self::$config->system->trainer_blacklist)) { |
|
716 | - $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
717 | - } |
|
718 | - $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'; |
|
719 | - $result = pg_query($this->db, $req); |
|
720 | - $levelData = array(); |
|
721 | - while ($data = pg_fetch_object($result)) { |
|
722 | - $levelData[$data->level] = $data->count; |
|
723 | - } |
|
724 | - for ($i = 5; $i <= 40; ++$i) { |
|
725 | - if (!isset($levelData[$i])) { |
|
726 | - $levelData[$i] = 0; |
|
727 | - } |
|
728 | - } |
|
729 | - // sort array again |
|
730 | - ksort($levelData); |
|
731 | - |
|
732 | - return $levelData; |
|
733 | - } |
|
734 | - |
|
735 | - ///////// |
|
736 | - // Cron |
|
737 | - ///////// |
|
738 | - |
|
739 | - public function getPokemonCountsActive() |
|
740 | - { |
|
741 | - $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id'; |
|
742 | - $result = pg_query($this->db, $req); |
|
743 | - $counts = array(); |
|
744 | - while ($data = pg_fetch_object($result)) { |
|
745 | - $counts[$data->pokemon_id] = $data->total; |
|
746 | - } |
|
747 | - |
|
748 | - return $counts; |
|
749 | - } |
|
750 | - |
|
751 | - public function getTotalPokemonIV() |
|
752 | - { |
|
753 | - $req = 'SELECT COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND cp IS NOT NULL'; |
|
754 | - $result = pg_query($this->db, $req); |
|
755 | - $data = pg_fetch_object($result); |
|
756 | - |
|
757 | - return $data; |
|
758 | - } |
|
759 | - |
|
760 | - public function getPokemonCountsLastDay() |
|
761 | - { |
|
762 | - $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
703 | + $result = pg_query($this->db, $req); |
|
704 | + $pokemon = array(); |
|
705 | + while ($data = pg_fetch_object($result)) { |
|
706 | + $pokemon[] = $data; |
|
707 | + } |
|
708 | + |
|
709 | + return $pokemon; |
|
710 | + } |
|
711 | + |
|
712 | + public function getTrainerLevelCount($team_id) |
|
713 | + { |
|
714 | + $exclue = ''; |
|
715 | + if (!empty(self::$config->system->trainer_blacklist)) { |
|
716 | + $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
|
717 | + } |
|
718 | + $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'; |
|
719 | + $result = pg_query($this->db, $req); |
|
720 | + $levelData = array(); |
|
721 | + while ($data = pg_fetch_object($result)) { |
|
722 | + $levelData[$data->level] = $data->count; |
|
723 | + } |
|
724 | + for ($i = 5; $i <= 40; ++$i) { |
|
725 | + if (!isset($levelData[$i])) { |
|
726 | + $levelData[$i] = 0; |
|
727 | + } |
|
728 | + } |
|
729 | + // sort array again |
|
730 | + ksort($levelData); |
|
731 | + |
|
732 | + return $levelData; |
|
733 | + } |
|
734 | + |
|
735 | + ///////// |
|
736 | + // Cron |
|
737 | + ///////// |
|
738 | + |
|
739 | + public function getPokemonCountsActive() |
|
740 | + { |
|
741 | + $req = 'SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id'; |
|
742 | + $result = pg_query($this->db, $req); |
|
743 | + $counts = array(); |
|
744 | + while ($data = pg_fetch_object($result)) { |
|
745 | + $counts[$data->pokemon_id] = $data->total; |
|
746 | + } |
|
747 | + |
|
748 | + return $counts; |
|
749 | + } |
|
750 | + |
|
751 | + public function getTotalPokemonIV() |
|
752 | + { |
|
753 | + $req = 'SELECT COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND cp IS NOT NULL'; |
|
754 | + $result = pg_query($this->db, $req); |
|
755 | + $data = pg_fetch_object($result); |
|
756 | + |
|
757 | + return $data; |
|
758 | + } |
|
759 | + |
|
760 | + public function getPokemonCountsLastDay() |
|
761 | + { |
|
762 | + $req = 'SELECT pokemon_id, COUNT(*) AS spawns_last_day |
|
763 | 763 | FROM sightings |
764 | 764 | WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings) |
765 | 765 | GROUP BY pokemon_id |
766 | 766 | ORDER BY pokemon_id ASC'; |
767 | - $result = pg_query($this->db, $req); |
|
768 | - $counts = array(); |
|
769 | - while ($data = pg_fetch_object($result)) { |
|
770 | - $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
771 | - } |
|
772 | - |
|
773 | - return $counts; |
|
774 | - } |
|
775 | - |
|
776 | - public function getCaptchaCount() |
|
777 | - { |
|
778 | - $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL'; |
|
779 | - $result = pg_query($this->db, $req); |
|
780 | - $data = pg_fetch_object($result); |
|
781 | - |
|
782 | - return $data; |
|
783 | - } |
|
784 | - |
|
785 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
786 | - { |
|
787 | - $pokemon_exclude_sql = ''; |
|
788 | - if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
789 | - $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
790 | - } |
|
791 | - $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 |
|
767 | + $result = pg_query($this->db, $req); |
|
768 | + $counts = array(); |
|
769 | + while ($data = pg_fetch_object($result)) { |
|
770 | + $counts[$data->pokemon_id] = $data->spawns_last_day; |
|
771 | + } |
|
772 | + |
|
773 | + return $counts; |
|
774 | + } |
|
775 | + |
|
776 | + public function getCaptchaCount() |
|
777 | + { |
|
778 | + $req = ' SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL'; |
|
779 | + $result = pg_query($this->db, $req); |
|
780 | + $data = pg_fetch_object($result); |
|
781 | + |
|
782 | + return $data; |
|
783 | + } |
|
784 | + |
|
785 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
786 | + { |
|
787 | + $pokemon_exclude_sql = ''; |
|
788 | + if (!empty(self::$config->system->nest_exclude_pokemon)) { |
|
789 | + $pokemon_exclude_sql = 'AND p.pokemon_id NOT IN ('.implode(',', self::$config->system->nest_exclude_pokemon).')'; |
|
790 | + } |
|
791 | + $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 |
|
792 | 792 | FROM sightings p |
793 | 793 | INNER JOIN spawnpoints s ON (p.spawn_id = s.spawn_id) |
794 | 794 | WHERE p.expire_timestamp > EXTRACT(EPOCH FROM NOW()) - '.($time * 3600).' |
@@ -797,23 +797,23 @@ discard block |
||
797 | 797 | GROUP BY p.spawn_id, p.pokemon_id |
798 | 798 | HAVING COUNT(p.pokemon_id) >= '.($time / 4).' |
799 | 799 | ORDER BY p.pokemon_id'; |
800 | - $result = pg_query($this->db, $req); |
|
801 | - $nests = array(); |
|
802 | - while ($data = pg_fetch_object($result)) { |
|
803 | - $nests[] = $data; |
|
804 | - } |
|
805 | - |
|
806 | - return $nests; |
|
807 | - } |
|
808 | - |
|
809 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
810 | - { |
|
811 | - $req = 'SELECT COUNT(*) as total |
|
800 | + $result = pg_query($this->db, $req); |
|
801 | + $nests = array(); |
|
802 | + while ($data = pg_fetch_object($result)) { |
|
803 | + $nests[] = $data; |
|
804 | + } |
|
805 | + |
|
806 | + return $nests; |
|
807 | + } |
|
808 | + |
|
809 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
810 | + { |
|
811 | + $req = 'SELECT COUNT(*) as total |
|
812 | 812 | FROM spawnpoints |
813 | 813 | WHERE lat >= '.$minLatitude.' AND lat < '.$maxLatitude.' AND lon >= '.$minLongitude.' AND lon < '.$maxLongitude; |
814 | - $result = pg_query($this->db, $req); |
|
815 | - $data = pg_fetch_object($result); |
|
814 | + $result = pg_query($this->db, $req); |
|
815 | + $data = pg_fetch_object($result); |
|
816 | 816 | |
817 | - return $data; |
|
818 | - } |
|
817 | + return $data; |
|
818 | + } |
|
819 | 819 | } |
@@ -8,140 +8,140 @@ |
||
8 | 8 | |
9 | 9 | abstract class QueryManager |
10 | 10 | { |
11 | - protected static $time_offset; |
|
12 | - protected static $config; |
|
11 | + protected static $time_offset; |
|
12 | + protected static $config; |
|
13 | 13 | |
14 | - private static $current; |
|
14 | + private static $current; |
|
15 | 15 | |
16 | - public static function current() |
|
17 | - { |
|
18 | - global $time_offset; |
|
16 | + public static function current() |
|
17 | + { |
|
18 | + global $time_offset; |
|
19 | 19 | |
20 | - if (null == self::$current) { |
|
21 | - $variables = realpath(dirname(__FILE__)).'/../../json/variables.json'; |
|
22 | - self::$config = json_decode(file_get_contents($variables)); |
|
20 | + if (null == self::$current) { |
|
21 | + $variables = realpath(dirname(__FILE__)).'/../../json/variables.json'; |
|
22 | + self::$config = json_decode(file_get_contents($variables)); |
|
23 | 23 | |
24 | - include_once SYS_PATH.'/core/process/timezone.loader.php'; |
|
25 | - self::$time_offset = $time_offset; |
|
24 | + include_once SYS_PATH.'/core/process/timezone.loader.php'; |
|
25 | + self::$time_offset = $time_offset; |
|
26 | 26 | |
27 | - switch (strtolower(SYS_DB_TYPE)) { |
|
28 | - case 'rdm': |
|
29 | - case 'realdevicemap': |
|
30 | - self::$current = new QueryManagerMysqlRealDeviceMap(); |
|
31 | - break; |
|
32 | - case 'monocle-alt': |
|
33 | - case 'monocle-alt-mysql': |
|
34 | - self::$current = new QueryManagerMysqlMonocleAlternate(); |
|
35 | - break; |
|
36 | - case 'monocle-alt-pgsql': |
|
37 | - self::$current = new QueryManagerPostgresqlMonocleAlternate(); |
|
38 | - break; |
|
39 | - default: //rocketmap |
|
40 | - self::$current = new QueryManagerMysqlRocketmap(); |
|
41 | - break; |
|
42 | - } |
|
43 | - } |
|
27 | + switch (strtolower(SYS_DB_TYPE)) { |
|
28 | + case 'rdm': |
|
29 | + case 'realdevicemap': |
|
30 | + self::$current = new QueryManagerMysqlRealDeviceMap(); |
|
31 | + break; |
|
32 | + case 'monocle-alt': |
|
33 | + case 'monocle-alt-mysql': |
|
34 | + self::$current = new QueryManagerMysqlMonocleAlternate(); |
|
35 | + break; |
|
36 | + case 'monocle-alt-pgsql': |
|
37 | + self::$current = new QueryManagerPostgresqlMonocleAlternate(); |
|
38 | + break; |
|
39 | + default: //rocketmap |
|
40 | + self::$current = new QueryManagerMysqlRocketmap(); |
|
41 | + break; |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - return self::$current; |
|
46 | - } |
|
45 | + return self::$current; |
|
46 | + } |
|
47 | 47 | |
48 | - private function __construct() |
|
49 | - { |
|
50 | - } |
|
48 | + private function __construct() |
|
49 | + { |
|
50 | + } |
|
51 | 51 | |
52 | - // Misc |
|
53 | - abstract public function getEcapedString($string); |
|
52 | + // Misc |
|
53 | + abstract public function getEcapedString($string); |
|
54 | 54 | |
55 | - // Tester |
|
56 | - abstract public function testTotalPokemon(); |
|
55 | + // Tester |
|
56 | + abstract public function testTotalPokemon(); |
|
57 | 57 | |
58 | - abstract public function testTotalGyms(); |
|
58 | + abstract public function testTotalGyms(); |
|
59 | 59 | |
60 | - abstract public function testTotalPokestops(); |
|
60 | + abstract public function testTotalPokestops(); |
|
61 | 61 | |
62 | - // Homepage |
|
63 | - abstract public function getTotalPokemon(); |
|
62 | + // Homepage |
|
63 | + abstract public function getTotalPokemon(); |
|
64 | 64 | |
65 | - abstract public function getTotalLures(); |
|
65 | + abstract public function getTotalLures(); |
|
66 | 66 | |
67 | - abstract public function getTotalGyms(); |
|
67 | + abstract public function getTotalGyms(); |
|
68 | 68 | |
69 | - abstract public function getTotalRaids(); |
|
69 | + abstract public function getTotalRaids(); |
|
70 | 70 | |
71 | - abstract public function getTotalGymsForTeam($team_id); |
|
71 | + abstract public function getTotalGymsForTeam($team_id); |
|
72 | 72 | |
73 | - abstract public function getRecentAll(); |
|
73 | + abstract public function getRecentAll(); |
|
74 | 74 | |
75 | - abstract public function getRecentMythic($mythic_pokemon); |
|
75 | + abstract public function getRecentMythic($mythic_pokemon); |
|
76 | 76 | |
77 | - // Single Pokemon |
|
78 | - abstract public function getGymsProtectedByPokemon($pokemon_id); |
|
77 | + // Single Pokemon |
|
78 | + abstract public function getGymsProtectedByPokemon($pokemon_id); |
|
79 | 79 | |
80 | - abstract public function getPokemonLastSeen($pokemon_id); |
|
80 | + abstract public function getPokemonLastSeen($pokemon_id); |
|
81 | 81 | |
82 | - abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction); |
|
82 | + abstract public function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction); |
|
83 | 83 | |
84 | - abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction); |
|
84 | + abstract public function getTop50Trainers($pokemon_id, $best_order_by, $best_direction); |
|
85 | 85 | |
86 | - abstract public function getPokemonHeatmap($pokemon_id, $start, $end); |
|
86 | + abstract public function getPokemonHeatmap($pokemon_id, $start, $end); |
|
87 | 87 | |
88 | - abstract public function getPokemonGraph($pokemon_id); |
|
88 | + abstract public function getPokemonGraph($pokemon_id); |
|
89 | 89 | |
90 | - abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons); |
|
90 | + abstract public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons); |
|
91 | 91 | |
92 | - abstract public function getPokemonSliderMinMax(); |
|
92 | + abstract public function getPokemonSliderMinMax(); |
|
93 | 93 | |
94 | - abstract public function getMapsCoords(); |
|
94 | + abstract public function getMapsCoords(); |
|
95 | 95 | |
96 | - abstract public function getPokemonCount($pokemon_id); |
|
96 | + abstract public function getPokemonCount($pokemon_id); |
|
97 | 97 | |
98 | - abstract public function getPokemonCountAll(); |
|
98 | + abstract public function getPokemonCountAll(); |
|
99 | 99 | |
100 | - abstract public function getRaidCount($pokemon_id); |
|
100 | + abstract public function getRaidCount($pokemon_id); |
|
101 | 101 | |
102 | - abstract public function getRaidCountAll(); |
|
102 | + abstract public function getRaidCountAll(); |
|
103 | 103 | |
104 | - // Pokestops |
|
105 | - abstract public function getTotalPokestops(); |
|
104 | + // Pokestops |
|
105 | + abstract public function getTotalPokestops(); |
|
106 | 106 | |
107 | - abstract public function getAllPokestops(); |
|
107 | + abstract public function getAllPokestops(); |
|
108 | 108 | |
109 | - // Gyms |
|
110 | - abstract public function getTeamGuardians($team_id); |
|
109 | + // Gyms |
|
110 | + abstract public function getTeamGuardians($team_id); |
|
111 | 111 | |
112 | - abstract public function getOwnedAndPoints($team_id); |
|
112 | + abstract public function getOwnedAndPoints($team_id); |
|
113 | 113 | |
114 | - abstract public function getAllGyms(); |
|
114 | + abstract public function getAllGyms(); |
|
115 | 115 | |
116 | - abstract public function getGymData($gym_id); |
|
116 | + abstract public function getGymData($gym_id); |
|
117 | 117 | |
118 | - abstract public function getGymDefenders($gym_id); |
|
118 | + abstract public function getGymDefenders($gym_id); |
|
119 | 119 | |
120 | - // Gym History |
|
121 | - abstract public function getGymHistories($gym_name, $team, $page, $ranking); |
|
120 | + // Gym History |
|
121 | + abstract public function getGymHistories($gym_name, $team, $page, $ranking); |
|
122 | 122 | |
123 | - abstract public function getGymHistoriesPokemon($gym_id); |
|
123 | + abstract public function getGymHistoriesPokemon($gym_id); |
|
124 | 124 | |
125 | - abstract public function getHistoryForGym($page, $gym_id); |
|
125 | + abstract public function getHistoryForGym($page, $gym_id); |
|
126 | 126 | |
127 | - // Raids |
|
128 | - abstract public function getAllRaids($page); |
|
127 | + // Raids |
|
128 | + abstract public function getAllRaids($page); |
|
129 | 129 | |
130 | - // Trainers |
|
131 | - abstract public function getTrainers($trainer_name, $team, $page, $ranking); |
|
130 | + // Trainers |
|
131 | + abstract public function getTrainers($trainer_name, $team, $page, $ranking); |
|
132 | 132 | |
133 | - abstract public function getTrainerLevelCount($team_id); |
|
133 | + abstract public function getTrainerLevelCount($team_id); |
|
134 | 134 | |
135 | - // Cron |
|
136 | - abstract public function getPokemonCountsActive(); |
|
135 | + // Cron |
|
136 | + abstract public function getPokemonCountsActive(); |
|
137 | 137 | |
138 | - abstract public function getTotalPokemonIV(); |
|
138 | + abstract public function getTotalPokemonIV(); |
|
139 | 139 | |
140 | - abstract public function getPokemonCountsLastDay(); |
|
140 | + abstract public function getPokemonCountsLastDay(); |
|
141 | 141 | |
142 | - abstract public function getCaptchaCount(); |
|
142 | + abstract public function getCaptchaCount(); |
|
143 | 143 | |
144 | - abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
144 | + abstract public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
145 | 145 | |
146 | - abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
146 | + abstract public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude); |
|
147 | 147 | } |
@@ -8,8 +8,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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->total_cp) { |
|
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->total_cp) { |
|
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 |
||
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 |
||
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 | } |
@@ -56,116 +56,116 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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->total_cp) { |
|
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->total_cp) { |
|
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 |
||
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 |
||
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) { |
@@ -26,28 +26,28 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |