-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.php
113 lines (97 loc) · 2.85 KB
/
api.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
<?php
/**
*
*/
use App\I18n;
use App\Snipe;
use App\User;
/**
*
*
* @author Knut Kohl <[email protected]>
* @copyright (c) 2016 Knut Kohl
* @licence MIT License - http://opensource.org/licenses/MIT
*/
if (empty($_GET['api'])) {
return;
}
$GET = filter_input_array(
INPUT_GET,
[
'api' => FILTER_SANITIZE_STRING,
'token' => FILTER_SANITIZE_STRING
],
true
);
$result = '';
if (isset($snipes) && $snipe = $snipes->find($GET['token'])) {
switch ($GET['api']) {
// ---------------
case 'edit':
$snipe->stop();
$result = ['name' => $snipe->name, 'data' => $snipe->data ];
break;
// ---------------
case 'stop':
$result = $snipe->stop();
break;
// ---------------
case 'delete':
$result = $snipe->delete();
break;
// ---------------
case 'log':
$result = $snipe->log;
break;
} // switch
// Auction group related actions return always JSON content
header('Content-Type: application/json');
$result = json_encode($result);
} else {
// Merge add. parameters in
$GET = array_merge($GET, filter_input_array(
INPUT_GET,
[
'bug' => FILTER_SANITIZE_STRING,
'name' => FILTER_SANITIZE_STRING,
'item' => FILTER_SANITIZE_STRING,
'price' => FILTER_SANITIZE_STRING,
'ship' => FILTER_SANITIZE_STRING,
'bid' => FILTER_SANITIZE_STRING
],
true
));
switch ($GET['api']) {
// ---------------
case 'bug':
// Bug file contents
$bug = User::$dir.'/'.$GET['bug'];
if (is_file($bug)) {
$result = file_get_contents($bug);
}
break;
// ---------------
case 'bookmark':
// Need user for snipe instance to have a data path
User::init($GET['token'], null);
// Ebay uses " as quotes in auction names
$name = str_replace('"', '"', urldecode($GET['name']));
$snipe = new Snipe(
trim($name),
'# ' . I18N::_('actual_bid') . ': ' . urldecode($GET['price']) . PHP_EOL .
'# ' . I18N::_('shipping_costs') . ': ' . urldecode($GET['ship']) . PHP_EOL .
$GET['item'] . ' ' . $GET['bid']
);
if ($snipe->save()) {
$msg = I18N::_('group_added', $name);
$_SESSION['new'][$snipe->getHash()] = true;
} else {
$msg = I18N::_('group_add_failed');
}
$result = '<html><body style="padding:1rem;font-family:sans-serif">'
. $msg
. '</body></html>';
break;
} // switch
}
die($result);