-
Notifications
You must be signed in to change notification settings - Fork 344
/
index.php
171 lines (157 loc) · 5.59 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
declare(strict_types=1);
use Psr\Container\ContainerInterface;
require __DIR__ . '/src/common.php';
/** @var ContainerInterface $container */
$router = $container->get(Bramus\Router\Router::class);
// define routes
// all users
$router->get('/', function() use ($container): void {
// json
$container->get(controllers\Index::class)->home();
});
$router->get('/api/about', function() use ($container): void {
// json
$container->get(controllers\About::class)->about();
});
$router->post('/api/private/hash-password', function() use ($container): void {
// json
$container->get(controllers\Helpers\HashPassword::class)->hash();
});
$router->get('/login', function() use ($container): void {
// json, deprecated
$container->get(controllers\Authentication::class)->login();
});
$router->post('/login', function() use ($container): void {
// json
$container->get(controllers\Authentication::class)->login();
});
$router->get('/logout', function() use ($container): void {
// json, deprecated
$container->get(controllers\Authentication::class)->logout();
});
$router->delete('/api/session/current', function() use ($container): void {
// json
$container->get(controllers\Authentication::class)->logout();
});
$router->get('/update', function() use ($container): void {
// text
$container->get(controllers\Sources\Update::class)->updateAll();
});
// only for loggedin users or on public mode
$router->get('/rss', function() use ($container): void {
// rss
$container->get(controllers\Rss::class)->rss();
});
$router->get('/feed', function() use ($container): void {
// rss
$container->get(controllers\Rss::class)->rss();
});
$router->get('/items', function() use ($container): void {
// json
$container->get(controllers\Items::class)->listItems();
});
$router->get('/tags', function() use ($container): void {
// json
$container->get(controllers\Tags::class)->listTags();
});
$router->get('/stats', function() use ($container): void {
// json
$container->get(controllers\Items\Stats::class)->stats();
});
$router->get('/items/sync', function() use ($container): void {
// json
$container->get(controllers\Items\Sync::class)->sync();
});
$router->get('/sources/stats', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->stats();
});
// only loggedin users
$router->post('/mark/([0-9]+)', function(string $itemId) use ($container): void {
// json
$container->get(controllers\Items::class)->mark($itemId);
});
$router->post('/mark', function() use ($container): void {
// json
$container->get(controllers\Items::class)->mark();
});
$router->post('/unmark/([0-9]+)', function(string $itemId) use ($container): void {
// json
$container->get(controllers\Items::class)->unmark($itemId);
});
$router->post('/starr/([0-9]+)', function(string $itemId) use ($container): void {
// json
$container->get(controllers\Items::class)->starr($itemId);
});
$router->post('/unstarr/([0-9]+)', function(string $itemId) use ($container): void {
// json
$container->get(controllers\Items::class)->unstarr($itemId);
});
$router->post('/items/sync', function() use ($container): void {
// json
$container->get(controllers\Items\Sync::class)->updateStatuses();
});
$router->get('/source/params', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->params();
});
$router->get('/sources', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->show();
});
$router->get('/source', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->add();
});
$router->get('/sources/list', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->listSources();
});
$router->post('/source/((?:new-)?[0-9]+)', function(string $id) use ($container): void {
// json
$container->get(controllers\Sources\Write::class)->write($id);
});
$router->post('/source', function() use ($container): void {
// json
$container->get(controllers\Sources\Write::class)->write();
});
$router->delete('/source/([0-9]+)', function(string $id) use ($container): void {
// json
$container->get(controllers\Sources::class)->remove($id);
});
$router->post('/source/delete/([0-9]+)', function(string $id) use ($container): void {
// json, deprecated
$container->get(controllers\Sources::class)->remove($id);
});
$router->post('/source/([0-9]+)/update', function(string $id) use ($container): void {
// json
$container->get(controllers\Sources\Update::class)->update($id);
});
$router->get('/sources/spouts', function() use ($container): void {
// json
$container->get(controllers\Sources::class)->spouts();
});
$router->post('/tags/color', function() use ($container): void {
// json
$container->get(controllers\Tags::class)->color();
});
$router->post('/opml', function() use ($container): void {
// json
$container->get(controllers\Opml\Import::class)->add();
});
$router->get('/opmlexport', function() use ($container): void {
// xml
$container->get(controllers\Opml\Export::class)->export();
});
// Client side routes need to be directed to index.html.
$router->get('/sign/in|/opml|/password|/manage/sources(/add)?|/(newest|unread|starred)(/(all|tag-[^/]+|source-[0-9]+)(/[0-9]+)?)?', function() use ($container): void {
// html
$container->get(controllers\Index::class)->home();
});
$router->set404(function(): void {
header('HTTP/1.1 404 Not Found');
echo 'Page not found.';
});
// dispatch
$router->run();