-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart.php
More file actions
152 lines (138 loc) · 4.94 KB
/
Copy pathpart.php
File metadata and controls
152 lines (138 loc) · 4.94 KB
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
<?php
require_once('php/DataHandler.php');
require_once('php/DataFilter.php');
$method = $_SERVER['REQUEST_METHOD'];
$request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
$dataFileName = "parts";
switch($method)
{
case 'GET':
{
if(isset($_GET['bools']))
{
$bs = DataEntry::$bools;
if(isset($_GET['proj']) )
{
$proj = (string)html_entity_decode($_GET['proj']);
if(!empty($proj))
$bs = DataEntry::allBoolsAt($proj);
}
$json = json_encode($bs);
if($json === false || $json === true || $json === "null")
$json = "{}";
echo $json;
}
else if(isset($_GET['tags']))
{
$dh = new DataHandler($dataFileName);
$dh->read();
$json = json_encode($dh->getAllTags()->toArray());
if($json === false || $json === true || $json === "null")
$json = "{}";
echo $json;
}
else if(isset($_GET['key']))
{
$key = json_decode('"' . html_entity_decode($_GET['key']) . '"');
//echo "getting....";
$dh = new DataHandler($dataFileName);
$dh->read();
$json = json_encode($dh->getEntry($key));
if($json === false || $json === true || $json === "null")
$json = "{}";
//var_dump($json);
echo $json;
}
else if(isset($_GET['q']) || isset($_GET['t0']) || isset($_GET['t1']) || isset($_GET['b0']) || isset($_GET['b1']))
{
//var_dump($_GET['t0']);
//var_dump($_GET['t1']);
$filter = new DataFilter();
if(isset($_GET['q']))
$filter->q = json_decode('"' . html_entity_decode($_GET['q']) . '"');
if(isset($_GET['t0']))
$filter->t0 = (array)json_decode(html_entity_decode($_GET['t0']));
if(isset($_GET['t1']))
$filter->t1 = (array)json_decode(html_entity_decode($_GET['t1']));
if(isset($_GET['b0']))
$filter->b0 = (array)json_decode(html_entity_decode($_GET['b0']));
if(isset($_GET['b1']))
$filter->b1 = (array)json_decode(html_entity_decode($_GET['b1']));
if(isset($_GET['c0']))
$filter->c0 = (array)json_decode(html_entity_decode($_GET['c0']));
if(isset($_GET['c1']))
$filter->c1 = (array)json_decode(html_entity_decode($_GET['c1']));
if(isset($_GET['proj']))
$filter->proj = (string)html_entity_decode($_GET['proj']);
$dh = new DataHandler($dataFileName);
$dh->read();
$json = json_encode($dh->filter($filter));
if($json === false || $json === true || $json === "null")
$json = "{}";
//var_dump($filter);
echo $json;
}
else
{
die("must specify key to lookup part: /url?key={key}, <br> one or more of following filter properties: /url?q={query}?t0={[(!)tag]}?t1={![(!)tag]}?b0={[(!)bool]}?b1={![(!)bool]}, <br> empty query for all: /url?q=\"\", <br> bools: /url?bools");
}
break;
}
case 'PUT':
{
/*parse_str(file_get_contents("php://input"), $_PUT);
foreach ($_PUT as $key => $value)
{
unset($_PUT[$key]);
$_PUT[str_replace('amp;', '', $key)] = $value;
}
$_REQUEST = array_merge($_REQUEST, $_PUT);*/
if(isset($_REQUEST['key']) && isset($_REQUEST['val']))
{
$dh = new DataHandler($dataFileName);
$dh->read();
$key = (string)json_decode('"' . (string)html_entity_decode($_GET['key']) . '"');
$val = (object)json_decode(html_entity_decode($_REQUEST['val']));
$de = ($dh->hasEntry($key) ? $dh->getEntry($key) : new DataEntry())->fromObj($val);
$missing = $de->missingProperties();
if(count($missing) == 0)
{
$return = $dh->setEntry($key, $de);
$dh->write();
echo json_encode($return);
}
else
{
echo json_encode($missing);
}
}
else
{
die("must specify key and val to set part: /url?key={key}&val={{values}}");
}
break;
}
case 'DELETE':
{
if(isset($_REQUEST['key']))
{
$dh = new DataHandler($dataFileName);
$dh->read();
$key = (string)json_decode('"' . (string)html_entity_decode($_GET['key']) . '"');
$return = $dh->deleteEntry($key);
$dh->write();
echo json_encode($return);
}
else
{
die("must specify key to delete part: /url?key={key}");
}
break;
}
default:
{
//handle_error($request);
break;
}
}
?>