forked from Gyvastis/article-rewriter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
46 lines (38 loc) · 1.58 KB
/
index.php
File metadata and controls
46 lines (38 loc) · 1.58 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
<?php
require_once 'vendor/autoload.php';
$app = new Slim\App();
$app->post('/rewrite', function(\Slim\Http\Request $request, \Slim\Http\Response $response){
$response_params = [
'success' => false,
'message' => '',
'data' => []
];
if( ! $request->getContentType() == 'application/json'){
$response_params['message'] = "Request Content-Type must be 'application/json'";
}
else{
$request_params = $request->getParsedBody();
if(empty($request_params)){
$response_params['message'] = "Request params missing";
}
else if( ! isset($request_params['text']) OR empty($request_params['text'])){
$response_params['message'] = "Request params 'text' is empty or missing";
}
else{
$request_text = $request_params['text'];
// $request_text = preg_replace('/[^0-9a-z-\.,\?!\(\)\s\n\r]/i', '', $request_text);
$request_include_capitalized = isset($response_params['include_capitalized']) ? $response_params['include_capitalized'] : false;
$rewritten_text = spin_article($request_text, $request_include_capitalized);
if( ! $rewritten_text){
$response_params['message'] = 'Rewriting failed';
}
else{
$response_params['success'] = true;
$response_params['message'] = 'Text rewritten successfully';
$response_params['data']['rewritten_text'] = $rewritten_text;
}
}
}
return $response->withJson($response_params);
});
$app->run();