-
Notifications
You must be signed in to change notification settings - Fork 0
/
phproofreading.class.php
57 lines (45 loc) · 1.27 KB
/
phproofreading.class.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
<?php
/**
* PHProofreading
*
* @package PHProofreading
* @author Hamid Samak <[email protected]>
* @link http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class PHProofReading{
public $languages_cache_file = '.languages';
private function request($url, $post_data = []) {
$context = null;
if (count($post_data) > 0) {
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($post_data)
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$context = stream_context_create($options);
}
return file_get_contents($url, false, $context);
}
public function languages() {
if (file_exists($this->languages_cache_file))
$data = file_get_contents($this->languages_cache_file);
else {
$data = $this->request('https://languagetool.org/api/v2/languages');
file_put_contents($this->languages_cache_file, $data);
}
$languages = json_decode($data, true);
return $languages;
}
public function check($text, $language = 'auto') {
$data = $this->request('https://languagetool.org/api/v2/check', ['text' => $text, 'language' => $language]);
$check = json_decode($data, true);
return $check;
}
}
?>