Skip to content

Commit

Permalink
lib cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
whitewillem committed May 31, 2019
1 parent ffd585f commit 25c3cd8
Show file tree
Hide file tree
Showing 11 changed files with 2,135 additions and 2,258 deletions.
57 changes: 0 additions & 57 deletions lib/Monocle_MAD.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,6 @@ public function get_gym($gymId)
$gyms = $this->query_gyms($conds, $params);
$gym = $gyms[0];

$select = "gd.pokemon_id, gd.cp AS pokemon_cp, gd.move_1, gd.move_2, gd.nickname, gd.atk_iv AS iv_attack, gd.def_iv AS iv_defense, gd.sta_iv AS iv_stamina, gd.cp AS pokemon_cp";
global $noTrainerName, $noTrainerLevel;
if (!$noTrainerName) {
$select .= ", gd.owner_name AS trainer_name";
}
if (!$noTrainerLevel) {
$select .= ", gd.owner_level AS trainer_level";
}
$gym["pokemon"] = $this->query_gym_defenders($gymId, $select);
return $gym;
}

Expand Down Expand Up @@ -433,54 +424,6 @@ public function query_gyms($conds, $params)
return $data;
}

private function query_gym_defenders($gymId, $select)
{
global $db;


$query = "SELECT :select
FROM gym_defenders gd
LEFT JOIN forts f ON gd.fort_id = f.id
WHERE f.external_id = :gymId";

$query = str_replace(":select", $select, $query);
$gym_defenders = $db->query($query, [":gymId" => $gymId])->fetchAll(\PDO::FETCH_ASSOC);

$data = array();
$i = 0;

foreach ($gym_defenders as $defender) {
$pid = $defender["pokemon_id"];
if ($defender['nickname']) {
// If defender has nickname, eg Pippa, put it alongside poke
$defender["pokemon_name"] = i8ln($this->data[$pid]["name"]) . "<br><small style='font-size: 70%;'>(" . $defender['nickname'] . ")</small>";
} else {
$defender["pokemon_name"] = i8ln($this->data[$pid]["name"]);
}
$defender["iv_attack"] = floatval($defender["iv_attack"]);
$defender["iv_defense"] = floatval($defender["iv_defense"]);
$defender["iv_stamina"] = floatval($defender["iv_stamina"]);

$defender['move_1_name'] = i8ln($this->moves[$defender['move_1']]['name']);
$defender['move_1_damage'] = $this->moves[$defender['move_1']]['damage'];
$defender['move_1_energy'] = $this->moves[$defender['move_1']]['energy'];
$defender['move_1_type']['type'] = i8ln($this->moves[$defender['move_1']]['type']);
$defender['move_1_type']['type_en'] = $this->moves[$defender['move_1']]['type'];

$defender['move_2_name'] = i8ln($this->moves[$defender['move_2']]['name']);
$defender['move_2_damage'] = $this->moves[$defender['move_2']]['damage'];
$defender['move_2_energy'] = $this->moves[$defender['move_2']]['energy'];
$defender['move_2_type']['type'] = i8ln($this->moves[$defender['move_2']]['type']);
$defender['move_2_type']['type_en'] = $this->moves[$defender['move_2']]['type'];

$data[] = $defender;

unset($gym_defenders[$i]);
$i++;
}
return $data;
}

public function get_spawnpoints($swLat, $swLng, $neLat, $neLng, $tstamp = 0, $oSwLat = 0, $oSwLng = 0, $oNeLat = 0, $oNeLng = 0)
{
$conds = array();
Expand Down
59 changes: 0 additions & 59 deletions lib/RocketMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,6 @@ public function get_gym($gymId)
$gyms = $this->query_gyms($conds, $params);
$gym = $gyms[0];

$select = "gymmember.gym_id, pokemon_id, cp AS pokemon_cp, move_1, move_2, iv_attack, iv_defense, iv_stamina";
global $noTrainerName;
if (!$noTrainerName) {
$select .= ", trainer_name, level AS trainer_level";
}
$gym["pokemon"] = $this->query_gym_defenders($gymId, $select);
return $gym;
}

Expand All @@ -464,7 +458,6 @@ public function query_gyms($conds, $params)
longitude,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00', @@global.time_zone)) AS last_scanned,
team_id,
Expand Down Expand Up @@ -521,58 +514,6 @@ public function query_gyms($conds, $params)
return $data;
}

public function query_gym_defenders($gymId, $select)
{
global $db;


$query = "SELECT :select
FROM gymmember
JOIN gympokemon
ON gymmember.pokemon_uid = gympokemon.pokemon_uid
JOIN trainer
ON gympokemon.trainer_name = trainer.name
JOIN gym
ON gym.gym_id = gymmember.gym_id
WHERE gymmember.last_scanned > gym.last_modified
AND gymmember.gym_id IN ( :gymId )
GROUP BY name
ORDER BY gympokemon.cp DESC";

$query = str_replace(":select", $select, $query);
$gym_defenders = $db->query($query, [":gymId" => $gymId])->fetchAll(\PDO::FETCH_ASSOC);

$data = array();
$i = 0;

foreach ($gym_defenders as $defender) {
$pid = $defender["pokemon_id"];
$defender["pokemon_name"] = i8ln($this->data[$pid]["name"]);

$defender["iv_attack"] = floatval($defender["iv_attack"]);
$defender["iv_defense"] = floatval($defender["iv_defense"]);
$defender["iv_stamina"] = floatval($defender["iv_stamina"]);

$defender['move_1_name'] = i8ln($this->moves[$defender['move_1']]['name']);
$defender['move_1_damage'] = $this->moves[$defender['move_1']]['damage'];
$defender['move_1_energy'] = $this->moves[$defender['move_1']]['energy'];
$defender['move_1_type']['type'] = i8ln($this->moves[$defender['move_1']]['type']);
$defender['move_1_type']['type_en'] = $this->moves[$defender['move_1']]['type'];

$defender['move_2_name'] = i8ln($this->moves[$defender['move_2']]['name']);
$defender['move_2_damage'] = $this->moves[$defender['move_2']]['damage'];
$defender['move_2_energy'] = $this->moves[$defender['move_2']]['energy'];
$defender['move_2_type']['type'] = i8ln($this->moves[$defender['move_2']]['type']);
$defender['move_2_type']['type_en'] = $this->moves[$defender['move_2']]['type'];

$data[] = $defender;

unset($gym_defenders[$i]);
$i++;
}
return $data;
}

public function get_weather_by_cell_id($cell_id)
{
global $db;
Expand Down
7 changes: 0 additions & 7 deletions lib/RocketMap_MAD.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ public function get_gym($gymId)
$gyms = $this->query_gyms($conds, $params);
$gym = $gyms[0];

$select = "gymmember.gym_id, pokemon_id, cp AS pokemon_cp, move_1, move_2, iv_attack, iv_defense, iv_stamina";
global $noTrainerName;
if (!$noTrainerName) {
$select .= ", trainer_name, level AS trainer_level";
}
$gym["pokemon"] = $this->query_gym_defenders($gymId, $select);
return $gym;
}

Expand All @@ -97,7 +91,6 @@ public function query_gyms($conds, $params)
longitude,
guard_pokemon_id,
slots_available,
total_cp,
Unix_timestamp(Convert_tz(last_modified, '+00:00', @@global.time_zone)) AS last_modified,
Unix_timestamp(Convert_tz(gym.last_scanned, '+00:00', @@global.time_zone)) AS last_scanned,
team_id,
Expand Down
110 changes: 55 additions & 55 deletions lib/search/Search.monocle_mad.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public function search_reward($lat, $lon, $term)
{
global $db, $defaultUnit, $maxSearchResults, $maxSearchNameLength;

$conds = array();
$params = array();
$conds = array();
$params = array();

$params[':lat'] = $lat;
$params[':lon'] = $lon;
$params[':lat'] = $lat;
$params[':lon'] = $lon;

$pjson = file_get_contents( 'static/dist/data/pokemon.min.json' );
$prewardsjson = json_decode( $pjson, true );
Expand All @@ -33,46 +33,46 @@ public function search_reward($lat, $lon, $term)
$iresids[] = $i;
}
}
if (!empty($presids)) {
$conds[] = "tq.quest_pokemon_id IN (" . implode(',',$presids) . ")";
}
if (!empty($iresids)) {
$conds[] = "tq.quest_item_id IN (" . implode(',',$iresids) . ")";
}
$query = "SELECT p.external_id AS id,
p.name,
p.lat,
p.lon,
p.url,
tq.quest_type,
tq.quest_pokemon_id,
tq.quest_item_id,
json_extract(json_extract(`quest_reward`,'$[*].pokemon_encounter.pokemon_display.form_value'),'$[0]') AS quest_pokemon_formid,
ROUND(( 3959 * acos( cos( radians(:lat) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(:lon) ) + sin( radians(:lat) ) * sin( radians( lat ) ) ) ),2) AS distance
FROM pokestops p
LEFT JOIN trs_quest tq ON tq.GUID = p.external_id
WHERE (:conditions) AND DATE(FROM_UNIXTIME(tq.quest_timestamp)) = CURDATE()
ORDER BY distance LIMIT " . $maxSearchResults . "";

$query = str_replace(":conditions", join(" OR ", $conds), $query);

$rewards = $db->query($query, $params)->fetchAll(\PDO::FETCH_ASSOC);

$data = array();

foreach($rewards as $reward){
if (!empty($presids)) {
$conds[] = "tq.quest_pokemon_id IN (" . implode(',',$presids) . ")";
}
if (!empty($iresids)) {
$conds[] = "tq.quest_item_id IN (" . implode(',',$iresids) . ")";
}
$query = "SELECT p.external_id AS id,
p.name,
p.lat,
p.lon,
p.url,
tq.quest_type,
tq.quest_pokemon_id,
tq.quest_item_id,
json_extract(json_extract(`quest_reward`,'$[*].pokemon_encounter.pokemon_display.form_value'),'$[0]') AS quest_pokemon_formid,
ROUND(( 3959 * acos( cos( radians(:lat) ) * cos( radians( lat ) ) * cos( radians( lon ) - radians(:lon) ) + sin( radians(:lat) ) * sin( radians( lat ) ) ) ),2) AS distance
FROM pokestops p
LEFT JOIN trs_quest tq ON tq.GUID = p.external_id
WHERE (:conditions) AND DATE(FROM_UNIXTIME(tq.quest_timestamp)) = CURDATE()
ORDER BY distance LIMIT " . $maxSearchResults . "";

$query = str_replace(":conditions", join(" OR ", $conds), $query);

$rewards = $db->query($query, $params)->fetchAll(\PDO::FETCH_ASSOC);

$data = array();

foreach($rewards as $reward){
$reward['pokemon_name'] = !empty($reward['pokemon_name']) ? $prewardsjson[$reward['quest_pokemon_id']]['name'] : null;
$reward['quest_pokemon_id'] = intval($reward['quest_pokemon_id']);
$reward['quest_pokemon_id'] = intval($reward['quest_pokemon_id']);
$reward['quest_pokemon_formid'] = intval($reward['quest_pokemon_formid']);
$reward['item_name'] = !empty($reward['item_name']) ? $irewardsjson[$reward['quest_item_id']]['name'] : null;
$reward['quest_item_id'] = intval($reward['quest_item_id']);
$reward['url'] = str_replace("http://", "https://images.weserv.nl/?url=", $reward['url']);
$reward['name'] = ($maxSearchNameLength > 0) ? htmlspecialchars(substr($reward['name'], 0, $maxSearchNameLength)) : htmlspecialchars($reward['name']);
if($defaultUnit === "km"){
$reward['distance'] = round($reward['distance'] * 1.60934,2);
}
$data[] = $reward;
}
$reward['quest_item_id'] = intval($reward['quest_item_id']);
$reward['url'] = str_replace("http://", "https://images.weserv.nl/?url=", $reward['url']);
$reward['name'] = ($maxSearchNameLength > 0) ? htmlspecialchars(substr($reward['name'], 0, $maxSearchNameLength)) : htmlspecialchars($reward['name']);
if($defaultUnit === "km"){
$reward['distance'] = round($reward['distance'] * 1.60934,2);
}
$data[] = $reward;
}
return $data;
}

Expand All @@ -84,7 +84,7 @@ public function search_nests($lat, $lon, $term)
$mons = json_decode( $json, true );
$resids = [];
foreach($mons as $k => $mon){
if( $k > 386){
if( $k > 493){
break;
}
if(strpos(strtolower(i8ln($mon['name'])), strtolower($term)) !== false){
Expand All @@ -109,7 +109,7 @@ public function search_nests($lat, $lon, $term)
if($defaultUnit === "km"){
$data[$k]['distance'] = round($data[$k]['distance'] * 1.60934,2);
}
}
}
return $data;
}

Expand All @@ -124,17 +124,17 @@ public function search_portals($lat, $lon, $term)
}
$searches = $manualdb->query( $query, [ ':name' => "%" . strtolower( $term ) . "%", ':lat' => $lat, ':lon' => $lon ] )->fetchAll();

$data = array();
$i = 0;
$data = array();
$i = 0;

foreach($searches as $search){
$search['url'] = str_replace("http://", "https://images.weserv.nl/?url=", $search['url']);
if($defaultUnit === "km"){
$search['distance'] = round($search['distance'] * 1.60934,2);
}
$data[] = $search;
unset($searches[$i]);
$i++;
}
$data[] = $search;
unset($searches[$i]);
$i++;
}
return $data;
}
Expand All @@ -150,17 +150,17 @@ public function search($dbname, $lat, $lon, $term)
}
$searches = $db->query( $query, [ ':name' => "%" . strtolower( $term ) . "%", ':lat' => $lat, ':lon' => $lon ] )->fetchAll();

$data = array();
$i = 0;
$data = array();
$i = 0;

foreach($searches as $search){
$search['url'] = str_replace("http://", "https://images.weserv.nl/?url=", $search['url']);
if($defaultUnit === "km"){
$search['distance'] = round($search['distance'] * 1.60934,2);
}
$data[] = $search;
unset($searches[$i]);
$i++;
}
$data[] = $search;
unset($searches[$i]);
$i++;
}
return $data;
}
Expand Down
Loading

0 comments on commit 25c3cd8

Please sign in to comment.