@@ -323,8 +323,7 @@ |
||
| 323 | 323 | } elseif (isset($obj->info)) { |
| 324 | 324 | $infoName = 'INFO_' . $obj->info; |
| 325 | 325 | echo '<br>(' . $locales->$infoName . ')'; |
| 326 | - } |
|
| 327 | - else { |
|
| 326 | + } else { |
|
| 328 | 327 | echo '<br> </br>'; |
| 329 | 328 | } |
| 330 | 329 | ?> |
@@ -3,11 +3,13 @@ discard block |
||
| 3 | 3 | include_once __DIR__ . '/QueryManagerPostgresqlMonocleAlternate.php'; |
| 4 | 4 | |
| 5 | 5 | |
| 6 | -abstract class QueryManagerPostgresql extends QueryManager { |
|
| 6 | +abstract class QueryManagerPostgresql extends QueryManager |
|
| 7 | +{ |
|
| 7 | 8 | |
| 8 | 9 | protected $db; |
| 9 | 10 | |
| 10 | - protected function __construct() { |
|
| 11 | + protected function __construct() |
|
| 12 | + { |
|
| 11 | 13 | |
| 12 | 14 | $this->db = pg_connect("host=".SYS_DB_HOST." port=".SYS_DB_PORT." dbname=".SYS_DB_NAME." user=".SYS_DB_USER." password=".SYS_DB_PSWD); |
| 13 | 15 | |
@@ -17,7 +19,8 @@ discard block |
||
| 17 | 19 | } |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | - public function __destruct() { |
|
| 22 | + public function __destruct() |
|
| 23 | + { |
|
| 21 | 24 | pg_close($this->db); |
| 22 | 25 | } |
| 23 | 26 | |
@@ -25,7 +28,8 @@ discard block |
||
| 25 | 28 | // Misc |
| 26 | 29 | ///////// |
| 27 | 30 | |
| 28 | - public function getEcapedString($string) { |
|
| 31 | + public function getEcapedString($string) |
|
| 32 | + { |
|
| 29 | 33 | return pg_escape_string($this->db, $string); |
| 30 | 34 | } |
| 31 | 35 | |
@@ -4,11 +4,13 @@ discard block |
||
| 4 | 4 | include_once __DIR__ . '/QueryManagerMysqlMonocleAlternate.php'; |
| 5 | 5 | |
| 6 | 6 | |
| 7 | -abstract class QueryManagerMysql extends QueryManager { |
|
| 7 | +abstract class QueryManagerMysql extends QueryManager |
|
| 8 | +{ |
|
| 8 | 9 | |
| 9 | 10 | protected $mysqli; |
| 10 | 11 | |
| 11 | - protected function __construct() { |
|
| 12 | + protected function __construct() |
|
| 13 | + { |
|
| 12 | 14 | $this->mysqli = new mysqli(SYS_DB_HOST, SYS_DB_USER, SYS_DB_PSWD, SYS_DB_NAME, SYS_DB_PORT); |
| 13 | 15 | if ($this->mysqli->connect_error != '') { |
| 14 | 16 | header('Location:'.HOST_URL.'offline.html'); |
@@ -22,7 +24,8 @@ discard block |
||
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | - public function __destruct() { |
|
| 27 | + public function __destruct() |
|
| 28 | + { |
|
| 26 | 29 | $this->mysqli->close(); |
| 27 | 30 | } |
| 28 | 31 | |
@@ -30,7 +33,8 @@ discard block |
||
| 30 | 33 | // Misc |
| 31 | 34 | ///////// |
| 32 | 35 | |
| 33 | - public function getEcapedString($string) { |
|
| 36 | + public function getEcapedString($string) |
|
| 37 | + { |
|
| 34 | 38 | return mysqli_real_escape_string($this->mysqli, $string); |
| 35 | 39 | } |
| 36 | 40 | |
@@ -4,13 +4,15 @@ discard block |
||
| 4 | 4 | include_once __DIR__ . '/QueryManagerMysql.php'; |
| 5 | 5 | include_once __DIR__ . '/QueryManagerPostgresql.php'; |
| 6 | 6 | |
| 7 | -abstract class QueryManager { |
|
| 7 | +abstract class QueryManager |
|
| 8 | +{ |
|
| 8 | 9 | |
| 9 | 10 | protected static $time_offset; |
| 10 | 11 | protected static $config; |
| 11 | 12 | |
| 12 | 13 | private static $current; |
| 13 | - public static function current() { |
|
| 14 | + public static function current() |
|
| 15 | + { |
|
| 14 | 16 | global $time_offset; |
| 15 | 17 | |
| 16 | 18 | if (self::$current == null) { |
@@ -37,7 +39,9 @@ discard block |
||
| 37 | 39 | } |
| 38 | 40 | return self::$current; |
| 39 | 41 | } |
| 40 | - private function __construct(){} |
|
| 42 | + private function __construct() |
|
| 43 | + { |
|
| 44 | +} |
|
| 41 | 45 | |
| 42 | 46 | // Misc |
| 43 | 47 | abstract public function getEcapedString($string); |
@@ -103,7 +103,8 @@ |
||
| 103 | 103 | touch($pokedex_rarity_file); |
| 104 | 104 | // update pokedex rarity |
| 105 | 105 | include_once(SYS_PATH.'/core/cron/pokedex_rarity.cron.php'); |
| 106 | -} elseif ( (file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400) ) { # extra update 12h after migration |
|
| 106 | +} elseif ( (file_update_ago($nests_parks_file) >= 43200) && (time() - $migration >= 43200) && (time() - $migration < 86400) ) { |
|
| 107 | +# extra update 12h after migration |
|
| 107 | 108 | if (is_file($nests_parks_file)) { |
| 108 | 109 | $prevNestTime = filemtime($nests_parks_file); |
| 109 | 110 | } else { |
@@ -25,7 +25,8 @@ |
||
| 25 | 25 | $minLongitude = $totalMinLon + $iLng * 0.5; |
| 26 | 26 | $maxLongitude = min($minLongitude + 0.5 ,$totalMaxLon); |
| 27 | 27 | |
| 28 | - if ($manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total == 0) { //Skip empty areas |
|
| 28 | + if ($manager->getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude)->total == 0) { |
|
| 29 | +//Skip empty areas |
|
| 29 | 30 | $iLng++; |
| 30 | 31 | continue; |
| 31 | 32 | } |
@@ -181,7 +181,8 @@ discard block |
||
| 181 | 181 | // |
| 182 | 182 | // Retruns max depth of array |
| 183 | 183 | ######################################################################## |
| 184 | -function get_depth($arr) { |
|
| 184 | +function get_depth($arr) |
|
| 185 | +{ |
|
| 185 | 186 | $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr)); |
| 186 | 187 | $depth = 0; |
| 187 | 188 | foreach ($it as $v) { |
@@ -199,12 +200,16 @@ discard block |
||
| 199 | 200 | // |
| 200 | 201 | // Return all pokemon with data at a certain tree depth |
| 201 | 202 | ######################################################################## |
| 202 | -function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0) { |
|
| 203 | - if ($depth == $currentDepth) { // Found depth |
|
| 203 | +function get_tree_at_depth($trees, $depth, $max_pokemon, $currentDepth = 0) |
|
| 204 | +{ |
|
| 205 | + if ($depth == $currentDepth) { |
|
| 206 | +// Found depth |
|
| 204 | 207 | return tree_remove_bellow($trees, $max_pokemon); |
| 205 | - } else { // Go deeper |
|
| 208 | + } else { |
|
| 209 | +// Go deeper |
|
| 206 | 210 | $arr = array(); |
| 207 | - foreach ($trees as $temp) { // Go into all trees |
|
| 211 | + foreach ($trees as $temp) { |
|
| 212 | +// Go into all trees |
|
| 208 | 213 | $tree = $temp->evolutions; |
| 209 | 214 | $results = tree_remove_bellow(get_tree_at_depth($tree, $depth, $max_pokemon, $currentDepth + 1), $max_pokemon); |
| 210 | 215 | $arr = tree_check_array($results, $arr, $depth - $currentDepth == 1); |
@@ -216,12 +221,16 @@ discard block |
||
| 216 | 221 | ######################################################################## |
| 217 | 222 | // used in get_tree_at_depth |
| 218 | 223 | ######################################################################## |
| 219 | -function tree_check_array($array_check, $array_add, $correct_arrow) { |
|
| 224 | +function tree_check_array($array_check, $array_add, $correct_arrow) |
|
| 225 | +{ |
|
| 220 | 226 | $count = count($array_check); |
| 221 | 227 | $i = 0; |
| 222 | - if (!is_null($array_check)) { // check if exists |
|
| 223 | - foreach ($array_check as $res) { // Check if above, equal or bellow center |
|
| 224 | - if ($count != 1 && $correct_arrow) { // only add arrow once |
|
| 228 | + if (!is_null($array_check)) { |
|
| 229 | +// check if exists |
|
| 230 | + foreach ($array_check as $res) { |
|
| 231 | +// Check if above, equal or bellow center |
|
| 232 | + if ($count != 1 && $correct_arrow) { |
|
| 233 | +// only add arrow once |
|
| 225 | 234 | $num = $i / ($count - 1); |
| 226 | 235 | if ($num < 0.5) { |
| 227 | 236 | $res->array_sufix = "_up"; |
@@ -249,7 +258,8 @@ discard block |
||
| 249 | 258 | return null; |
| 250 | 259 | } |
| 251 | 260 | $arr = array(); |
| 252 | - foreach ($tree as $item) { // Check if above, equal or bellow center |
|
| 261 | + foreach ($tree as $item) { |
|
| 262 | +// Check if above, equal or bellow center |
|
| 253 | 263 | if ($item->id <= $max_pokemon) { |
| 254 | 264 | $arr[] = $item; |
| 255 | 265 | } |
@@ -283,7 +293,8 @@ discard block |
||
| 283 | 293 | ######################################################################## |
| 284 | 294 | // check if point is inside porygon |
| 285 | 295 | ######################################################################## |
| 286 | -function pointIsInsidePolygon($lat, $lng, $geos, $bounds) { |
|
| 296 | +function pointIsInsidePolygon($lat, $lng, $geos, $bounds) |
|
| 297 | +{ |
|
| 287 | 298 | if ($lat >= $bounds["minlat"] && $lat <= $bounds["maxlat"] && $lng >= $bounds["minlon"] && $lng <= $bounds["maxlon"]) { |
| 288 | 299 | |
| 289 | 300 | $intersections = 0; |
@@ -292,15 +303,18 @@ discard block |
||
| 292 | 303 | for ($i = 1; $i < $geos_count; $i++) { |
| 293 | 304 | $geo1 = $geos[$i - 1]; |
| 294 | 305 | $geo2 = $geos[$i]; |
| 295 | - if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { // On one of the coords |
|
| 306 | + if ($geo1['lng'] == $lng && $geo1['lat'] == $lat) { |
|
| 307 | +// On one of the coords |
|
| 296 | 308 | return true; |
| 297 | 309 | } |
| 298 | - 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 |
|
| 310 | + if ($geo1['lng'] == $geo2['lng'] and $geo1['lng'] == $lng and $lat > min($geo1['lat'], $geo2['lat']) and $lat < max($geo1['lat'], $geo2['lat'])) { |
|
| 311 | +// Check if point is on an horizontal polygon boundary |
|
| 299 | 312 | return true; |
| 300 | 313 | } |
| 301 | 314 | 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']) { |
| 302 | 315 | $xinters = ($lng - $geo1['lng']) * ($geo2['lat'] - $geo1['lat']) / ($geo2['lng'] - $geo1['lng']) + $geo1['lat']; |
| 303 | - if ($xinters == $lat) { // Check if point is on the polygon boundary (other than horizontal) |
|
| 316 | + if ($xinters == $lat) { |
|
| 317 | +// Check if point is on the polygon boundary (other than horizontal) |
|
| 304 | 318 | return true; |
| 305 | 319 | } |
| 306 | 320 | if ($geo1['lat'] == $geo2['lat'] || $lat <= $xinters) { |
@@ -322,7 +336,8 @@ discard block |
||
| 322 | 336 | ######################################################################## |
| 323 | 337 | // check if $boundsIn is inside (or equal to) $boundsOut |
| 324 | 338 | ######################################################################## |
| 325 | -function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut) { |
|
| 339 | +function polyIsInsidePolygon($geoIn, $boundsIn, $geoOut, $boundsOut) |
|
| 340 | +{ |
|
| 326 | 341 | if ($boundsIn["minlat"] >= $boundsOut["minlat"] && $boundsIn["maxlat"] <= $boundsOut["maxlat"] && $boundsIn["minlon"] >= $boundsOut["minlon"] && $boundsIn["maxlon"] <= $boundsOut["maxlon"]) { |
| 327 | 342 | $insideCount = 0; |
| 328 | 343 | foreach ($geoIn as $coord) { |
@@ -339,7 +354,8 @@ discard block |
||
| 339 | 354 | ######################################################################## |
| 340 | 355 | // compine outer ways into porygon |
| 341 | 356 | ######################################################################## |
| 342 | -function combineOuter($outers) { |
|
| 357 | +function combineOuter($outers) |
|
| 358 | +{ |
|
| 343 | 359 | $polygons = array(); |
| 344 | 360 | $index = 0; |
| 345 | 361 | $count = 0; |
@@ -372,7 +388,7 @@ discard block |
||
| 372 | 388 | |
| 373 | 389 | $firstElePoly = $polygons[$index][0]; |
| 374 | 390 | $lastElePoly = $polygons[$index][count($polygons[$index]) - 1]; |
| 375 | - if ($firstElePoly == $lastElePoly){ |
|
| 391 | + if ($firstElePoly == $lastElePoly) { |
|
| 376 | 392 | $index++; |
| 377 | 393 | } |
| 378 | 394 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | * @return array Sorted list of "accept" options |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -$sortAccept = function ($header) { |
|
| 29 | +$sortAccept = function ($header) |
|
| 30 | +{ |
|
| 30 | 31 | $matches = array(); |
| 31 | 32 | foreach (explode(',', $header) as $option) { |
| 32 | 33 | $option = array_map('trim', explode(';', $option)); |
@@ -59,7 +60,8 @@ discard block |
||
| 59 | 60 | * |
| 60 | 61 | * @return string|NULL a matched option, or NULL if no match |
| 61 | 62 | */ |
| 62 | -$matchAccept = function ($header, $supported) use ($sortAccept) { |
|
| 63 | +$matchAccept = function ($header, $supported) use ($sortAccept) |
|
| 64 | +{ |
|
| 63 | 65 | $matches = $sortAccept($header); |
| 64 | 66 | foreach ($matches as $key => $q) { |
| 65 | 67 | if (isset($supported[$key])) { |
@@ -90,7 +92,8 @@ discard block |
||
| 90 | 92 | * |
| 91 | 93 | * @return string The negotiated language result or the supplied default. |
| 92 | 94 | */ |
| 93 | -$negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept) { |
|
| 95 | +$negotiateLanguage = function ($supported, $default = 'en-US') use ($matchAccept) |
|
| 96 | +{ |
|
| 94 | 97 | $supp = array(); |
| 95 | 98 | foreach ($supported as $lang => $isSupported) { |
| 96 | 99 | if ($isSupported) { |
@@ -6,13 +6,16 @@ discard block |
||
| 6 | 6 | * Time: 02:26 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql { |
|
| 9 | +class QueryManagerPostgresqlMonocleAlternate extends QueryManagerPostgresql |
|
| 10 | +{ |
|
| 10 | 11 | |
| 11 | - public function __construct() { |
|
| 12 | + public function __construct() |
|
| 13 | + { |
|
| 12 | 14 | parent::__construct(); |
| 13 | 15 | } |
| 14 | 16 | |
| 15 | - public function __destruct() { |
|
| 17 | + public function __destruct() |
|
| 18 | + { |
|
| 16 | 19 | parent::__destruct(); |
| 17 | 20 | } |
| 18 | 21 | |
@@ -20,7 +23,8 @@ discard block |
||
| 20 | 23 | // Tester |
| 21 | 24 | /////////// |
| 22 | 25 | |
| 23 | - function testTotalPokemon() { |
|
| 26 | + function testTotalPokemon() |
|
| 27 | + { |
|
| 24 | 28 | $req = "SELECT COUNT(*) as total FROM sightings"; |
| 25 | 29 | $result = pg_query($this->db, $req); |
| 26 | 30 | if ($result === false) { |
@@ -36,7 +40,8 @@ discard block |
||
| 36 | 40 | return 0; |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | - function testTotalGyms() { |
|
| 43 | + function testTotalGyms() |
|
| 44 | + { |
|
| 40 | 45 | $req = "SELECT COUNT(*) as total FROM forts"; |
| 41 | 46 | $result = pg_query($this->db, $req); |
| 42 | 47 | if ($result === false) { |
@@ -52,7 +57,8 @@ discard block |
||
| 52 | 57 | return 0; |
| 53 | 58 | } |
| 54 | 59 | |
| 55 | - function testTotalPokestops() { |
|
| 60 | + function testTotalPokestops() |
|
| 61 | + { |
|
| 56 | 62 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 57 | 63 | $result = pg_query($this->db, $req); |
| 58 | 64 | if ($result === false) { |
@@ -73,26 +79,30 @@ discard block |
||
| 73 | 79 | // Homepage |
| 74 | 80 | ///////////// |
| 75 | 81 | |
| 76 | - function getTotalPokemon() { |
|
| 82 | + function getTotalPokemon() |
|
| 83 | + { |
|
| 77 | 84 | $req = "SELECT COUNT(*) AS total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW())"; |
| 78 | 85 | $result = pg_query($this->db, $req); |
| 79 | 86 | $data = pg_fetch_object($result); |
| 80 | 87 | return $data; |
| 81 | 88 | } |
| 82 | 89 | |
| 83 | - function getTotalLures() { |
|
| 90 | + function getTotalLures() |
|
| 91 | + { |
|
| 84 | 92 | $data = (object) array("total" => 0); |
| 85 | 93 | return $data; |
| 86 | 94 | } |
| 87 | 95 | |
| 88 | - function getTotalGyms() { |
|
| 96 | + function getTotalGyms() |
|
| 97 | + { |
|
| 89 | 98 | $req = "SELECT COUNT(*) AS total FROM forts"; |
| 90 | 99 | $result = pg_query($this->db, $req); |
| 91 | 100 | $data = pg_fetch_object($result); |
| 92 | 101 | return $data; |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | - function getTotalRaids() { |
|
| 104 | + function getTotalRaids() |
|
| 105 | + { |
|
| 96 | 106 | $req = "SELECT COUNT(*) AS total FROM raids WHERE time_battle <= EXTRACT(EPOCH FROM NOW()) AND time_end >= EXTRACT(EPOCH FROM NOW())"; |
| 97 | 107 | $result = pg_query($this->db, $req); |
| 98 | 108 | $data = pg_fetch_object($result); |
@@ -100,7 +110,8 @@ discard block |
||
| 100 | 110 | } |
| 101 | 111 | |
| 102 | 112 | |
| 103 | - function getTotalGymsForTeam($team_id) { |
|
| 113 | + function getTotalGymsForTeam($team_id) |
|
| 114 | + { |
|
| 104 | 115 | $req = "SELECT COUNT(*) AS total |
| 105 | 116 | FROM forts f |
| 106 | 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)) |
@@ -110,7 +121,8 @@ discard block |
||
| 110 | 121 | return $data; |
| 111 | 122 | } |
| 112 | 123 | |
| 113 | - function getRecentAll() { |
|
| 124 | + function getRecentAll() |
|
| 125 | + { |
|
| 114 | 126 | $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, |
| 115 | 127 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 116 | 128 | FROM sightings |
@@ -126,7 +138,8 @@ discard block |
||
| 126 | 138 | return $data; |
| 127 | 139 | } |
| 128 | 140 | |
| 129 | - function getRecentMythic($mythic_pokemon) { |
|
| 141 | + function getRecentMythic($mythic_pokemon) |
|
| 142 | + { |
|
| 130 | 143 | $req = "SELECT pokemon_id, encounter_id, TO_TIMESTAMP(expire_timestamp) AS disappear_time, TO_TIMESTAMP(updated) AS last_modified, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, |
| 131 | 144 | lat AS latitude, lon AS longitude, cp, atk_iv AS individual_attack, def_iv AS individual_defense, sta_iv AS individual_stamina |
| 132 | 145 | FROM sightings |
@@ -147,7 +160,8 @@ discard block |
||
| 147 | 160 | // Single Pokemon |
| 148 | 161 | /////////////////// |
| 149 | 162 | |
| 150 | - function getGymsProtectedByPokemon($pokemon_id) { |
|
| 163 | + function getGymsProtectedByPokemon($pokemon_id) |
|
| 164 | + { |
|
| 151 | 165 | $req = "SELECT COUNT(f.id) AS total |
| 152 | 166 | FROM forts f |
| 153 | 167 | 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)) |
@@ -157,7 +171,8 @@ discard block |
||
| 157 | 171 | return $data; |
| 158 | 172 | } |
| 159 | 173 | |
| 160 | - function getPokemonLastSeen($pokemon_id) { |
|
| 174 | + function getPokemonLastSeen($pokemon_id) |
|
| 175 | + { |
|
| 161 | 176 | $req = "SELECT TO_TIMESTAMP(expire_timestamp) AS expire_timestamp, TO_TIMESTAMP(expire_timestamp) AS disappear_time_real, lat AS latitude, lon AS longitude |
| 162 | 177 | FROM sightings |
| 163 | 178 | WHERE pokemon_id = '".$pokemon_id."' |
@@ -168,7 +183,8 @@ discard block |
||
| 168 | 183 | return $data; |
| 169 | 184 | } |
| 170 | 185 | |
| 171 | - function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) { |
|
| 186 | + function getTop50Pokemon($pokemon_id, $top_order_by, $top_direction) |
|
| 187 | + { |
|
| 172 | 188 | $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, |
| 173 | 189 | cp, atk_iv as individual_attack, def_iv as individual_defense, sta_iv as individual_stamina, |
| 174 | 190 | ROUND(100*(atk_iv+def_iv+sta_iv)/45,1) AS \"IV\", move_1 as move_1, move_2, form |
@@ -184,7 +200,8 @@ discard block |
||
| 184 | 200 | return $top; |
| 185 | 201 | } |
| 186 | 202 | |
| 187 | - function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) { |
|
| 203 | + function getTop50Trainers($pokemon_id, $best_order_by, $best_direction) |
|
| 204 | + { |
|
| 188 | 205 | $trainer_blacklist = ""; |
| 189 | 206 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 190 | 207 | $trainer_blacklist = " AND owner_name NOT IN ('" . implode("','", self::$config->system->trainer_blacklist) . "')"; |
@@ -205,7 +222,8 @@ discard block |
||
| 205 | 222 | return $toptrainer; |
| 206 | 223 | } |
| 207 | 224 | |
| 208 | - public function getPokemonHeatmap($pokemon_id, $start, $end) { |
|
| 225 | + public function getPokemonHeatmap($pokemon_id, $start, $end) |
|
| 226 | + { |
|
| 209 | 227 | $where = " WHERE pokemon_id = ".$pokemon_id." " |
| 210 | 228 | . "AND TO_TIMESTAMP(expire_timestamp) BETWEEN '".$start."' AND '".$end."'"; |
| 211 | 229 | $req = "SELECT lat AS latitude, lon AS longitude FROM sightings".$where." LIMIT 100000"; |
@@ -217,7 +235,8 @@ discard block |
||
| 217 | 235 | return $points; |
| 218 | 236 | } |
| 219 | 237 | |
| 220 | - public function getPokemonGraph($pokemon_id) { |
|
| 238 | + public function getPokemonGraph($pokemon_id) |
|
| 239 | + { |
|
| 221 | 240 | $req = "SELECT COUNT(*) AS total, EXTRACT(HOUR FROM disappear_time) AS disappear_hour |
| 222 | 241 | FROM (SELECT TO_TIMESTAMP(expire_timestamp) as disappear_time FROM sightings WHERE pokemon_id = '".$pokemon_id."' LIMIT 100000) AS pokemonFiltered |
| 223 | 242 | GROUP BY disappear_hour |
@@ -233,7 +252,8 @@ discard block |
||
| 233 | 252 | return $array; |
| 234 | 253 | } |
| 235 | 254 | |
| 236 | - public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) { |
|
| 255 | + public function getPokemonLive($pokemon_id, $ivMin, $ivMax, $inmap_pokemons) |
|
| 256 | + { |
|
| 237 | 257 | $inmap_pkms_filter = ""; |
| 238 | 258 | $where = " WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) AND pokemon_id = " . $pokemon_id; |
| 239 | 259 | |
@@ -268,21 +288,24 @@ discard block |
||
| 268 | 288 | return $spawns; |
| 269 | 289 | } |
| 270 | 290 | |
| 271 | - public function getPokemonSliderMinMax() { |
|
| 291 | + public function getPokemonSliderMinMax() |
|
| 292 | + { |
|
| 272 | 293 | $req = "SELECT TO_TIMESTAMP(MIN(expire_timestamp)) AS min, TO_TIMESTAMP(MAX(expire_timestamp)) AS max FROM sightings"; |
| 273 | 294 | $result = pg_query($this->db, $req); |
| 274 | 295 | $data = pg_fetch_object($result); |
| 275 | 296 | return $data; |
| 276 | 297 | } |
| 277 | 298 | |
| 278 | - public function getMapsCoords() { |
|
| 299 | + public function getMapsCoords() |
|
| 300 | + { |
|
| 279 | 301 | $req = "SELECT MAX(lat) AS max_latitude, MIN(lat) AS min_latitude, MAX(lon) AS max_longitude, MIN(lon) as min_longitude FROM spawnpoints"; |
| 280 | 302 | $result = pg_query($this->db, $req); |
| 281 | 303 | $data = pg_fetch_object($result); |
| 282 | 304 | return $data; |
| 283 | 305 | } |
| 284 | 306 | |
| 285 | - public function getPokemonCount($pokemon_id) { |
|
| 307 | + public function getPokemonCount($pokemon_id) |
|
| 308 | + { |
|
| 286 | 309 | $req = "SELECT count, last_seen, latitude, longitude |
| 287 | 310 | FROM pokemon_stats |
| 288 | 311 | WHERE pid = ".$pokemon_id; |
@@ -291,7 +314,8 @@ discard block |
||
| 291 | 314 | return $data; |
| 292 | 315 | } |
| 293 | 316 | |
| 294 | - public function getRaidCount($pokemon_id) { |
|
| 317 | + public function getRaidCount($pokemon_id) |
|
| 318 | + { |
|
| 295 | 319 | $req = "SELECT count, last_seen, latitude, longitude |
| 296 | 320 | FROM raid_stats |
| 297 | 321 | WHERE pid = ".$pokemon_id; |
@@ -306,14 +330,16 @@ discard block |
||
| 306 | 330 | ////////////// |
| 307 | 331 | |
| 308 | 332 | |
| 309 | - function getTotalPokestops() { |
|
| 333 | + function getTotalPokestops() |
|
| 334 | + { |
|
| 310 | 335 | $req = "SELECT COUNT(*) as total FROM pokestops"; |
| 311 | 336 | $result = pg_query($this->db, $req); |
| 312 | 337 | $data = pg_fetch_object($result); |
| 313 | 338 | return $data; |
| 314 | 339 | } |
| 315 | 340 | |
| 316 | - public function getAllPokestops() { |
|
| 341 | + public function getAllPokestops() |
|
| 342 | + { |
|
| 317 | 343 | $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"; |
| 318 | 344 | $result = pg_query($this->db, $req); |
| 319 | 345 | $pokestops = array(); |
@@ -328,7 +354,8 @@ discard block |
||
| 328 | 354 | // Gyms |
| 329 | 355 | ///////// |
| 330 | 356 | |
| 331 | - function getTeamGuardians($team_id) { |
|
| 357 | + function getTeamGuardians($team_id) |
|
| 358 | + { |
|
| 332 | 359 | $req = "SELECT COUNT(*) AS total, guard_pokemon_id |
| 333 | 360 | FROM forts f |
| 334 | 361 | 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)) |
@@ -343,7 +370,8 @@ discard block |
||
| 343 | 370 | return $datas; |
| 344 | 371 | } |
| 345 | 372 | |
| 346 | - function getOwnedAndPoints($team_id) { |
|
| 373 | + function getOwnedAndPoints($team_id) |
|
| 374 | + { |
|
| 347 | 375 | $req = "SELECT COUNT(f.id) AS total, ROUND(AVG(fs.total_cp))AS average_points |
| 348 | 376 | FROM forts f |
| 349 | 377 | 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)) |
@@ -353,7 +381,8 @@ discard block |
||
| 353 | 381 | return $data; |
| 354 | 382 | } |
| 355 | 383 | |
| 356 | - function getAllGyms() { |
|
| 384 | + function getAllGyms() |
|
| 385 | + { |
|
| 357 | 386 | $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 |
| 358 | 387 | FROM forts f |
| 359 | 388 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id))"; |
@@ -365,7 +394,8 @@ discard block |
||
| 365 | 394 | return $gyms; |
| 366 | 395 | } |
| 367 | 396 | |
| 368 | - public function getGymData($gym_id) { |
|
| 397 | + public function getGymData($gym_id) |
|
| 398 | + { |
|
| 369 | 399 | $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 |
| 370 | 400 | FROM forts f |
| 371 | 401 | LEFT JOIN fort_sightings fs ON (fs.fort_id = f.id AND fs.last_modified = (SELECT MAX(last_modified) FROM fort_sightings fs2 WHERE fs2.fort_id=f.id)) |
@@ -376,7 +406,8 @@ discard block |
||
| 376 | 406 | return $data; |
| 377 | 407 | } |
| 378 | 408 | |
| 379 | - public function getGymDefenders($gym_id) { |
|
| 409 | + public function getGymDefenders($gym_id) |
|
| 410 | + { |
|
| 380 | 411 | $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 |
| 381 | 412 | FROM gym_defenders |
| 382 | 413 | WHERE fort_id='".$gym_id."' |
@@ -502,7 +533,8 @@ discard block |
||
| 502 | 533 | // Raids |
| 503 | 534 | /////////// |
| 504 | 535 | |
| 505 | - public function getAllRaids($page) { |
|
| 536 | + public function getAllRaids($page) |
|
| 537 | + { |
|
| 506 | 538 | $limit = " LIMIT 10 OFFSET ". ($page * 10); |
| 507 | 539 | $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 |
| 508 | 540 | FROM forts f |
@@ -523,7 +555,8 @@ discard block |
||
| 523 | 555 | // Trainers |
| 524 | 556 | ////////////// |
| 525 | 557 | |
| 526 | - public function getTrainers($trainer_name, $team, $page, $rankingNumber) { |
|
| 558 | + public function getTrainers($trainer_name, $team, $page, $rankingNumber) |
|
| 559 | + { |
|
| 527 | 560 | $ranking = $this->getTrainerLevelRanking(); |
| 528 | 561 | $where = ""; |
| 529 | 562 | if (!empty(self::$config->system->trainer_blacklist)) { |
@@ -575,7 +608,8 @@ discard block |
||
| 575 | 608 | return $trainers; |
| 576 | 609 | } |
| 577 | 610 | |
| 578 | - public function getTrainerLevelRanking() { |
|
| 611 | + public function getTrainerLevelRanking() |
|
| 612 | + { |
|
| 579 | 613 | $exclue = ""; |
| 580 | 614 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 581 | 615 | $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -596,7 +630,8 @@ discard block |
||
| 596 | 630 | return $levelData; |
| 597 | 631 | } |
| 598 | 632 | |
| 599 | - public function getActivePokemon($trainer_name) { |
|
| 633 | + public function getActivePokemon($trainer_name) |
|
| 634 | + { |
|
| 600 | 635 | $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 |
| 601 | 636 | FROM gym_defenders |
| 602 | 637 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NOT NULL |
@@ -609,7 +644,8 @@ discard block |
||
| 609 | 644 | return $pokemon; |
| 610 | 645 | } |
| 611 | 646 | |
| 612 | - public function getInactivePokemon($trainer_name) { |
|
| 647 | + public function getInactivePokemon($trainer_name) |
|
| 648 | + { |
|
| 613 | 649 | $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 |
| 614 | 650 | FROM gym_defenders |
| 615 | 651 | WHERE owner_name = '".$trainer_name."' AND fort_id IS NULL |
@@ -622,7 +658,8 @@ discard block |
||
| 622 | 658 | return $pokemon; |
| 623 | 659 | } |
| 624 | 660 | |
| 625 | - public function getTrainerLevelCount($team_id) { |
|
| 661 | + public function getTrainerLevelCount($team_id) |
|
| 662 | + { |
|
| 626 | 663 | $exclue = ""; |
| 627 | 664 | if (!empty(self::$config->system->trainer_blacklist)) { |
| 628 | 665 | $exclue .= " AND owner_name NOT IN ('".implode("','", self::$config->system->trainer_blacklist)."')"; |
@@ -648,7 +685,8 @@ discard block |
||
| 648 | 685 | // Cron |
| 649 | 686 | ///////// |
| 650 | 687 | |
| 651 | - public function getPokemonCountsActive() { |
|
| 688 | + public function getPokemonCountsActive() |
|
| 689 | + { |
|
| 652 | 690 | $req = "SELECT pokemon_id, COUNT(*) as total FROM sightings WHERE expire_timestamp >= EXTRACT(EPOCH FROM NOW()) GROUP BY pokemon_id"; |
| 653 | 691 | $result = pg_query($this->db, $req); |
| 654 | 692 | $counts = array(); |
@@ -658,7 +696,8 @@ discard block |
||
| 658 | 696 | return $counts; |
| 659 | 697 | } |
| 660 | 698 | |
| 661 | - public function getPokemonCountsLastDay() { |
|
| 699 | + public function getPokemonCountsLastDay() |
|
| 700 | + { |
|
| 662 | 701 | $req = "SELECT pokemon_id, COUNT(*) AS spawns_last_day |
| 663 | 702 | FROM sightings |
| 664 | 703 | WHERE expire_timestamp >= (SELECT MAX(expire_timestamp) - 86400 FROM sightings) |
@@ -673,14 +712,16 @@ discard block |
||
| 673 | 712 | } |
| 674 | 713 | |
| 675 | 714 | |
| 676 | - public function getCaptchaCount() { |
|
| 715 | + public function getCaptchaCount() |
|
| 716 | + { |
|
| 677 | 717 | $req = " SELECT COUNT(*) as total FROM accounts WHERE captchaed IS NOT NULL AND reason IS NULL"; |
| 678 | 718 | $result = pg_query($this->db, $req); |
| 679 | 719 | $data = pg_fetch_object($result); |
| 680 | 720 | return $data; |
| 681 | 721 | } |
| 682 | 722 | |
| 683 | - public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 723 | + public function getNestData($time, $minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 724 | + { |
|
| 684 | 725 | $pokemon_exclude_sql = ""; |
| 685 | 726 | if (!empty(self::$config->system->nest_exclude_pokemon)) { |
| 686 | 727 | $pokemon_exclude_sql = "AND p.pokemon_id NOT IN (" . implode(",", self::$config->system->nest_exclude_pokemon) . ")"; |
@@ -702,7 +743,8 @@ discard block |
||
| 702 | 743 | return $nests; |
| 703 | 744 | } |
| 704 | 745 | |
| 705 | - public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) { |
|
| 746 | + public function getSpawnpointCount($minLatitude, $maxLatitude, $minLongitude, $maxLongitude) |
|
| 747 | + { |
|
| 706 | 748 | $req = "SELECT COUNT(*) as total |
| 707 | 749 | FROM spawnpoints |
| 708 | 750 | WHERE lat >= ".$minLatitude." AND lat < ".$maxLatitude." AND lon >= ".$minLongitude." AND lon < ".$maxLongitude; |