-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
126 lines (108 loc) · 3.02 KB
/
index.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
114
115
116
117
118
119
<?php
use infrajs\router\Router;
use infrajs\ans\Ans;
use infrajs\rest\Rest;
use infrajs\load\Load;
use infrajs\path\Path;
use drakon5999\gdoc2article\GoogleDocs;
if (!is_file('vendor/autoload.php')) {
chdir('../../../');
require_once('vendor/autoload.php');
Router::init();
}
return Rest::get( function () {
$id = Ans::GET('id');
if (!$id) {
$html = GoogleDocs::html('WHAT');
} else {
$html = GoogleDocs::getArticle($id);
if ($html === false) {
http_response_code(404);
}
}
return Ans::html($html);
}, 'folder', [function () {
$html = GoogleDocs::html('WHAT');
return Ans::html($html);
}, function ($type, $id) {
$list = GoogleDocs::getFolder($id);
return Ans::ret($list);
}], 'table', [function () {
$html = GoogleDocs::html('WHAT');
return Ans::html($html);
}, [ function () {
$html = GoogleDocs::html('WHAT');
return Ans::html($html);
}, function ($type, $id, $range) {
$data = GoogleDocs::getTable($id, $range);
if ($data && isset($_GET['reverse'])) {
$data['data'] = array_reverse($data['data']);
}
$ans = array();
$ans['data'] = $data;
return Ans::ret($ans);
}]], 'public', [function () {
$ans = array();
$public = GoogleDocs::$conf['public'];
$ans['data'] = $public;
return Ans::ret($ans);
}, [ function ($t, $pub) {
$ans = array();
$public = GoogleDocs::$conf['public'];
if (empty($public[$pub])) return Ans::err($ans,'Ключ '.$pub.' не зарегистрирован');
$id = $public[$pub];
$data = GoogleDocs::getPublicFolder($pub, $id);
$order = Ans::GET('order',['ascending','descending'], 'descending');
Load::sort($data, $order);
$list = array();
foreach ($data as $k => $v) {
unset($data[$k]['body']);
$list[$v['id']] = $v;
//$list[$k] = $v['body'];
}
$lim = Ans::GET('lim','string','0,200');
list($start, $count) = explode(',', $lim);
$list = array_slice($list, $start, $count);
$ans['data'] = $list;
return Ans::ret($ans);
}, [ function ($t, $pub, $name) {
$ans = array();
$public = GoogleDocs::$conf['public'];
if (empty($public[$pub])) {
return Ans::err($ans,'Ключ '.$pub.' не зарегистрирован');
}
$id = $public[$pub];
$list = GoogleDocs::getPublicFolder($pub, $id);
if (empty($list[$name])) {
http_response_code(404);
$ans['data'] = array(
'id' => $name
);
return Ans::err($ans);
} else {
unset($list[$name]['body']);
$ans['data'] = $list[$name];
return Ans::ret($ans);
}
}, 'body', function ($t, $pub, $name, $prop) {
$ans = array();
$public = GoogleDocs::$conf['public'];
if (empty($public[$pub])) {
return Ans::err($ans,'Ключ '.$pub.' не зарегистрирован');
}
$id = $public[$pub];
$list = GoogleDocs::getPublicFolder($pub, $id);
if (empty($list[$name])) {
http_response_code(404);
return;
}
return Ans::html($list[$name][$prop]);
}]]],
function ($id) {
$html = GoogleDocs::getArticle($id);
if ($html === false) {
http_response_code(404);
return;
}
return Ans::html($html);
});