-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
102 lines (97 loc) · 2.89 KB
/
example.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
<?php
/* used to load pages using cURL */
function loadPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/* load page, decode it and create a variable to store all powers */
$page = loadPage('https://xatproject.com/fairtrade/api.php?action=powers');
$json = json_decode($page, true);
$powers = [];
/* get information of each power category */
foreach ($json['powers'] as $i => $p)
{
if ($p['is_ep']) { $powers['everypower'][] = $p; }
if ($p['is_epic']) { $powers['epic'][] = $p; }
if ($p['is_allp']) { $powers['allpowers'][] = $p; }
if ($p['is_group']) { $powers['group'][] = $p; }
if ($p['limited'] == 1) { $powers['limited'][] = $p; }
if ($p['limited'] != 1) { $powers['unlimited'][] = $p; }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Fairtrade</title>
<style>
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; }
tr:hover {background-color:#f5f5f5;}
</style>
</head>
<body>
<div align="center"> <h2>Total prices</h2> </div>
<table>
<tr>
<th>Type</th>
<th>Xats</th>
<th>Days</th>
<th>Powers</th>
</tr>
<?php
/* list total prices xats, days and amount of powers */
foreach ($powers as $t => $v):
?>
<tr>
<td><?php echo ucfirst($t); ?></td>
<td><?php echo array_sum(array_column($v, 'min_xats')) . '-' . array_sum(array_column($v, 'max_xats')); ?></td>
<td><?php echo array_sum(array_column($v, 'min_days')) . '-' . array_sum(array_column($v, 'max_days')); ?></td>
<td><?php echo count($v); ?></td>
</tr>
<?php endforeach; ?>
</table>
<div align="center"> <h2>Power list</h2> </div>
<table>
<tr>
<th>Name</th>
<th>Title</th>
<th>Store</th>
<th>Xats</th>
<th>Days</th>
<th>Limited</th>
<th>Unlimited</th>
<th>Game</th>
<th>Group</th>
<th>Hug</th>
<th>Epic</th>
<th>Allpowers</th>
</tr>
<?php
/* list all powers prices and info */
foreach ($powers['everypower'] as $i => $p):
?>
<tr>
<td><?php echo ucfirst($p['name']); ?></td>
<td><?php echo $p['title']; ?></td>
<td><?php echo $p['store']; ?></td>
<td><?php echo $p['min_xats'] . '-' . $p['max_xats']; ?></td>
<td><?php echo $p['min_days'] . '-' . $p['max_days']; ?></td>
<td><?php echo $p['limited'] == 1 ? 'Yes' : 'No'; ?></td>
<td><?php echo $p['limited'] == 1 ? 'No' : 'Yes'; ?></td>
<td><?php echo $p['is_game'] == 1 ? 'Yes' : 'No'; ?></td>
<td><?php echo $p['is_group'] == 1 ? 'Yes' : 'No'; ?></td>
<td><?php echo $p['is_hug'] == 1 ? 'Yes' : 'No'; ?></td>
<td><?php echo $p['is_epic'] == 1 ? 'Yes' : 'No'; ?></td>
<td><?php echo $p['is_allp'] == 1 ? 'Yes' : 'No'; ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>