-
Notifications
You must be signed in to change notification settings - Fork 0
/
morphapi_post.php
66 lines (60 loc) · 1.48 KB
/
morphapi_post.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
<?php
include('morphapi.php');
$functionName;
$arguments;
$result = "";
$api = new MorphAPI();
if (isset($_POST["f"])) {
$functionName = $_POST["f"];
if (isset($_POST["a"])) {
$arguments = $_POST["a"];
}
}
if (isset($_GET["f"])) {
$functionName = $_GET["f"];
if (isset($_GET["a"])) {
$arguments = $_GET["a"];
}
}
$failed = false;
if (isset($functionName)) {
if ($functionName == "getDeck") {
$result = $api->getDeck();
}
if ($functionName == "getCard") {
$result = $api->getCard();
}
if ($functionName == "giveCardToUser") {
$result = $api->giveCardToUser($arguments);
}
if ($functionName == "getUserDeck") {
$result = $api->getUserDeck($arguments);
}
if ($functionName == "clearUserDeck") {
$result = $api->clearUserDeck($arguments);
}
if ($functionName == "removeCardFromDeck") {
$result = $api->removeCardFromDeck($arguments);
}
if ($functionName == "giveRandomDeckToUser") {
$result = $api->getDeck();
$results = $result->getResults();
for ($i=0; $i < count($results); $i++) {
$result = $api->giveCardToUser('{"idUser":"'.$arguments.'","idCard":"'.$results[$i]["idCard"].'"}');
}
}
if (!$result->getSuccess()) {
$failed = true;
echo $result->getMessage();
echo "Function '$functionName' not valid, check your query string.";
}
} else {
$failed = true;
echo "Post variable 'f' not defined, check your query string.";
}
if (!$failed) {
header('Content-Type: application/json; charset=utf-8', true,200);
}
echo $result->getJsonResults();
unset($api);
?>