forked from antonmedv/homer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·47 lines (35 loc) · 1.18 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
<?php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
$app = new Silex\Application();
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['debug'] = false;
$app['db'] = $app->share(function () {
return new PDO(HOMER_DNS);
});
$app['queue'] = $app->share(function () use ($app) {
return new Homer\Queue($app['db']);
});
$app['search'] = $app->share(function () use ($app) {
return new Homer\Search($app['db']);
});
$app->get('/', function () use ($app) {
$search = $app['request']->get('search', false);
$result = $app['search']->search($search, 20);
ob_start();
include 'view/index.phtml';
return ob_get_clean();
})->bind('search');
$app->post('/add', function () use ($app) {
$url = filter_var($app['request']->get('url', ''), FILTER_VALIDATE_URL);
if ($url) {
$app['queue']->push($url, HOMER_DEEP);
}
return $app->redirect($app['url_generator']->generate('search', ['success' => $url !== false]));
})->bind('add');
$app->get('/statistic', function () use ($app) {
ob_start();
include 'view/statistic.phtml';
return ob_get_clean();
})->bind('statistic');
$app->run();