/
rest.php
64 lines (64 loc) · 1.25 KB
/
rest.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
<?php
header('Content-Type: application/json');
$total = 500;
$id_prefix = '';
if(isset($_GET['parent'])){
$parent = ($_GET['parent']);
if ($parent === "undefined") {
$id_prefix = "";
} else {
$id_prefix = ($_GET['parent'])."-";
}
}else{
$id_prefix = 0;
}
usleep(rand(0,500000));
$start = 0;
$end = 0;
$limit = '';
$debug = '';
foreach($_GET as $param => $value){
if(strpos($param, 'limit') === 0){
$limit = $param;
break;
}
}
if($limit){
preg_match('/(\d+),*(\d+)*/', $limit, $matches);
if(count($matches) > 2){
$start = $matches[2];
$end = $matches[1] + $start;
}else{
$end = $matches[1];
}
}else{
$range = '';
if(isset($_SERVER['HTTP_RANGE'])){
$range = $_SERVER['HTTP_RANGE'];
}elseif(isset($_SERVER['HTTP_X_RANGE'])){
$range = $_SERVER['HTTP_X_RANGE'];
}
if($range){
preg_match('/(\d+)-(\d+)/', $range, $matches);
$start = $matches[1];
$end = $matches[2] + 1;
}
}
if($end){
if($end > $total){
$end = $total;
}
}else{
$start = 0;
$end = 40;
}
header('Content-Range: ' . 'items '.$start.'-'.($end-1).'/'.$total);
echo '[';
for ($i = $start; $i < $end; $i++) {
if($i != $start){
echo ',';
}
echo '{"id":"'.$id_prefix.$i.'","name":"Item '.$i.'","comment":"hello"}';
}
echo ']';
?>