-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.php
215 lines (192 loc) · 8.82 KB
/
move.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
require_once 'init.php';
require_once CLASSES_PATH . "/KLogger.php";
require FUNCTIONS_PATH . "/formatNum.php";
$logger = new KLogger(LOG_PATH . "/log.txt", KLogger::DEBUG);
//get total pokemon
$url = "https://pokeapi.co/api/v2/item";
$count = json_decode(file_get_contents($url))->count;
//check if invalid national dex entry # in query
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = (int) $_GET['id'];
if($id > $count)
{
$id = 1;
}
}
else
{
$id = 1;
}
$url = sprintf("https://pokeapi.co/api/v2/move?offset=%u&limit=%u", ($id-2 < 0 ? 0 : $id-2) , 3);
$moves = file_get_contents($url);
$moves = json_decode($moves);
//get info of pokemon and their species
$moveInfo = file_get_contents(sprintf("https://pokeapi.co/api/v2/move/%u", $id));
$moveInfo = json_decode($moveInfo);
?>
<html>
<head>
<title>Pokésearch | Move</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/item.css">
<script src='js/changeBarStats.js'></script>
<?php require_once 'layouts/favicon.php'; ?>
</head>
<body>
<?php require_once 'layouts/mininav.php'; ?>
<div class="content">
<?php require_once 'layouts/header.php'; ?>
<span class="content-body">
<?php
include FUNCTIONS_PATH . '/cacheStart.php';
echo '<div class="nav">';
if(!$cache)
{
//prev move
if($id == 1)
{
echo '<p id="prev" class="hidden">← #???: ???</p>';
}
else
{
echo sprintf('<a href="%s?id=%u"><p id="prev">← %s</p></a>', $_SERVER['PHP_SELF'], ($id - 1), ucwords(str_replace("-", " ", $moves->results[0]->name)));
}
echo '<span class="current-item">';
echo '<h1>'. ucwords(str_replace("-", " ", $moveInfo->name)) . '</h1>';
echo '</span>';
//next move
if($id == $count)
{
echo '<p id="next" class="hidden">#???: ??? →</p>';
}
else
{
if($id == 1)
{
echo sprintf('<a href="%s?id=%u"><p id="next">%s →</p></a>', $_SERVER['PHP_SELF'], ($id + 1), ucwords(str_replace("-", " ", $moves->results[1]->name)));
}
else
{
echo sprintf('<a href="%s?id=%u"><p id="next">%s →</p></a>', $_SERVER['PHP_SELF'], ($id + 1), ucwords(str_replace("-", " ", $moves->results[2]->name)));
}
}
echo '</div>';
echo '<p><i>"' . $moveInfo->flavor_text_entries[0]->flavor_text . '"</i></p>';
echo '<div class="info">';
echo '<div class="col" id="left">';
echo '<h2>Move Information</h2>';
echo '<div class="stat">';
echo '<span class="key">Type</span>';
echo '<span class="value">' . ucfirst($moveInfo->type->name) . '</span>';
echo '</div>';
echo '<div class="stat">';
echo '<span class="key">Power</span>';
echo '<span class="value">' . $moveInfo->power . '</span>';
echo '</div>';
echo '<div class="stat">';
echo '<span class="key">Accuracy</span>';
echo '<span class="value">' . $moveInfo->accuracy . '</span>';
echo '</div>';
echo '<div class="stat">';
echo '<span class="key">PP</span>';
echo '<span class="value">' . $moveInfo->pp . '</span>';
echo '</div>';
echo '<div class="stat">';
echo '<span class="key">Damage Class</span>';
echo '<span class="value">' . ucfirst($moveInfo->damage_class->name) . '</span>';
echo '</div>';
echo '<div class="stat">';
echo '<span class="key">Effect Chance</span>';
echo '<span class="value">' . ($moveInfo->effect_chance == null ? "N/A" : $moveInfo->effect_chance . "%") . '</span>';
echo '</div>';
echo '<div class="stat-list">';
echo '<span class="name"><h3>Target</h3></span>';
echo '<span class="list">';
echo '<h2>' . ucwords(str_replace("-", " ", $moveInfo->target->name) . "</h2>");
$targetPage = json_decode(file_get_contents($moveInfo->target->url));
foreach($targetPage->descriptions as $description)
{
if($description->language->name == "en")
{
echo '<p>' . $description->description . '</p>';
}
}
echo '</span>';
echo '</div>';
echo '<div class="stat-list">';
echo '<span class="name"><h3>Move Effects</h3></span>';
echo '<span class="list">';
echo '<ul>';
foreach($moveInfo->effect_entries as $effect)
{
if($effect->language->name == "en")
{
echo '<li>' . str_replace('$effect_chance', $moveInfo->effect_chance, $effect->short_effect) . '</li>';
}
}
echo '</ul>';
echo '</span>';
echo '</div>';
echo '<div class="stat-list">';
echo '<span class="name"><h3>Stat Changes</h3></span>';
echo '<span class="list">';
if(count($moveInfo->stat_changes) == 0)
{
echo '<p>No changes.</p>';
}
else
{
echo '<ul>';
foreach($moveInfo->stat_changes as $stat)
{
echo sprintf("<li>%s %s</li>", $stat->change, ucfirst($stat->stat->name));
}
echo '</ul>';
}
echo '</span>';
echo '</div>';
echo '</div>';
echo '<div class="col" id="right">';
echo '<h2>Pokémon that can learn this move:</h2>';
if(count($moveInfo->learned_by_pokemon) == 0)
{
echo '<p>No Pokémon learns this move.</p>';
}
else
{
echo '<span class="pkmn-list">';
$pkmnToShow = count($moveInfo->learned_by_pokemon) > 20 ? 20 : count($moveInfo->learned_by_pokemon);
for($i = 0; $i < $pkmnToShow; $i++)
{
$pokemon = $moveInfo->learned_by_pokemon[$i];
$pkmnPage = json_decode(file_get_contents($pokemon->url));
$pkmnSpPage = json_decode(file_get_contents($pkmnPage->species->url));
echo '<div class="pokemon">';
echo '<a href="pokemon.php?id=' . $pkmnSpPage->id . '">';
echo '<span class="icon">';
echo '<img src="' . $pkmnPage->sprites->front_default . '">';
echo '</span>';
echo '<span class="info">';
echo '<h3>'. ucfirst($pkmnSpPage->name) . '</h3>';
echo '<h3>'. formatNum($pkmnSpPage->id) . '</h3>';
echo '</span>';
echo '</a>';
echo '</div>';
}
if($pkmnToShow == 20)
{
echo sprintf('<p><i>and %u more...</i></p>', count($moveInfo->learned_by_pokemon) - 20);
}
echo '</span>';
}
echo '</div>';
echo '</div>';
echo '</div>';
include FUNCTIONS_PATH . '/cacheEnd.php';
}
?>
</div>
<?php require_once 'layouts/footer.php'; ?>
</body>
</html>