-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
183 lines (151 loc) · 4.93 KB
/
Copy pathindex.php
File metadata and controls
183 lines (151 loc) · 4.93 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* Created by PhpStorm.
* User: mauro
* Date: 14/09/2018
* Time: 12:56
*/
// These lines are for DEVELOPMENT only.
// You should never display errors
// in a production environment.
// TODO comment following two lines
// error_reporting(E_ALL);
// ini_set('display_errors', '1');
// setlocale(LC_ALL, '');
require './vendor/autoload.php';
require './controller/SearchController.php';
require './test/ReviewWrapperTest.php';
require './test/AmazonWrapperTest.php';
require './test/GoogleWrapperTest.php';
require './test/KoboWrapperTest.php';
require './test/AudibleWrapperTest.php';
require './test/NarratoreWrapperTest.php';
require './test/MediatorTest.php';
require './test/BookTest.php';
require './test/ReviewTest.php';
require './test/UTF8LevenshteinTest.php';
require './test/DBManagerTest.php';
require './test/TokenizerTest.php';
use \controller\SearchController;
// Flight configuration
Flight::set('flight.log_errors', true);
Flight::set('flight.views.path', './view');
// Flight::set('flight.base_url', './');
// handle errors
Flight::map('error', function (Throwable $th) {
// Handle error
// echo $th->getTraceAsString();
// echo "An error occurred in {$th->getFile()}, check server logs";
echo $th->getMessage();
error_log(
"An error occurred: {$th->getMessage()}" .
" in {$th->getFile()}" .
" line {$th->getLine()}" .
" (code {$th->getCode()})."
);
});
// redirect non-existing page to main page
Flight::map('notFound', function () {
// echo 'Whoops! Seems like there\'s no page like that!';
// \sleep(5);
Flight::redirect('/');
});
// Flight routes
Flight::route('/', function () {
Flight::render('index.php');
});
Flight::route('/ebooks', function () {
Flight::render('ebooks.php');
});
Flight::route('/audiobooks', function () {
Flight::render('audiobooks.php');
});
Flight::route('/reviews', function () {
Flight::render('reviews.php');
});
Flight::route('/contacts', function () {
Flight::render('contact.php');
});
Flight::route('/about', function () {
Flight::render('about.php');
});
Flight::route('/search/news', function () {
(new SearchController)->searchNews();
});
Flight::route('/search/book', function () {
// retrieve request
$request = Flight::request();
// extract data from request
$search = $request->query['search'];
$keyword = $request->query['keyword'];
$depth = $request->query['depth'];
$ajax = $request->ajax;
// manage data if they exist
if ($search && $keyword)
{
$controller = new SearchController;
$controller->searchEBooks($search, $keyword, $depth, $ajax);
}
else
{
Flight::redirect('/');
}
});
Flight::route('/search/audioBook', function () {
// retrieve request
$request = Flight::request();
// extract data from request
$search = $request->query['search'];
$keyword = $request->query['keyword'];
$depth = $request->query['depth'];
$ajax = $request->ajax;
// manage data if they exist
if ($search && $keyword)
{
$controller = new SearchController;
$controller->searchAudioBooks($search, $keyword, $depth, $ajax);
}
else
{
Flight::redirect('/');
}
});
// tests
Flight::route('/test/book', function () {
(new \test\BookTest)->test();
});
flight::route('/test/review', function () {
(new \test\ReviewTest)->test();
});
Flight::route('/test/qreview', function () {
(new \test\ReviewWrapperTest)->test();
});
Flight::route('/test/amazonbook', function () {
(new \test\AmazonWrapperTest)->test();
});
Flight::route('/test/googlebook', function () {
(new \test\GoogleWrapperTest)->test();
});
Flight::route('/test/kobobook', function () {
(new \test\KoboWrapperTest)->test();
});
Flight::route('/test/audiobook', function () {
(new \test\AudibleWrapperTest)->test();
});
Flight::route('/test/narratore', function () {
(new \test\NarratoreWrapperTest)->test();
});
Flight::route('/test/mediator', function () {
(new \test\MediatorTest)->test();
});
Flight::route('/test/levenshtein', function () {
(new \test\UTF8LevenshteinTest)->test();
});
Flight::route('/test/dbmanager', function () {
(new \test\DBManagerTest)->test();
});
Flight::route('/test/tokenizer', function () {
(new \test\TokenizerTest)->test();
});
// run Fight router
Flight::start();