1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Example of usage Yandex\Speller package |
4
|
|
|
* |
5
|
|
|
* @author Dmitriy Savchenko |
6
|
|
|
* @created 06.11.15 16:33 |
7
|
|
|
*/ |
8
|
|
|
$settings = require_once '../settings.php'; |
9
|
|
|
|
10
|
|
|
use Yandex\Speller\SpellerClient; |
11
|
|
|
|
12
|
|
|
?> |
13
|
|
|
<!doctype html> |
14
|
|
|
<html lang="en-US"> |
15
|
|
|
<head> |
16
|
|
|
<meta charset="UTF-8"> |
17
|
|
|
<title>Yandex PHP Library: Speller Demo</title> |
18
|
|
|
<link rel="stylesheet" href="//yandex.st/bootstrap/3.0.0/css/bootstrap.min.css"> |
19
|
|
|
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> |
20
|
|
|
<link rel="stylesheet" href="/examples/Disk/css/style.css"> |
21
|
|
|
</head> |
22
|
|
|
<body> |
23
|
|
|
<div class="container"> |
24
|
|
|
<div class="jumbotron"> |
25
|
|
|
<h2><span class="glyphicon glyphicon-search"></span> Пример работы с Яндекс Спеллер</h2> |
26
|
|
|
</div> |
27
|
|
|
<div class="col-md-8"> |
28
|
|
|
<ol class="breadcrumb"> |
29
|
|
|
<li><a href="/examples">Examples</a></li> |
30
|
|
|
<li><a href="/examples/Speller">Speller</a></li> |
31
|
|
|
<li class="active">checkTexts</li> |
32
|
|
|
</ol> |
33
|
|
|
<h3>checkTexts</h3> |
34
|
|
|
<form class="form-horizontal" method="post"> |
35
|
|
|
<div class="form-group"> |
36
|
|
|
<label for="text0" class="col-sm-2 control-label">text</label> |
37
|
|
|
<div class="col-sm-10"> |
38
|
|
|
<textarea id="text0" |
39
|
|
|
name="text0" |
40
|
|
|
class="form-control" |
41
|
|
|
rows="3" |
42
|
|
|
placeholder="Text to check" |
43
|
|
|
required><?= isset($_POST['text0']) ? $_POST['text0'] : ''; ?></textarea> |
44
|
|
|
</div> |
45
|
|
|
</div> |
46
|
|
|
<div class="form-group"> |
47
|
|
|
<label for="text1" class="col-sm-2 control-label">text</label> |
48
|
|
|
<div class="col-sm-10"> |
49
|
|
|
<textarea id="text1" |
50
|
|
|
name="text1" |
51
|
|
|
class="form-control" |
52
|
|
|
rows="3" |
53
|
|
|
placeholder="Text to check" |
54
|
|
|
required><?= isset($_POST['text1']) ? $_POST['text1'] : ''; ?></textarea> |
55
|
|
|
</div> |
56
|
|
|
</div> |
57
|
|
|
<div class="form-group"> |
58
|
|
|
<label for="lang" class="col-sm-2 control-label">lang</label> |
59
|
|
|
<div class="col-sm-10"> |
60
|
|
|
<input type="text" |
61
|
|
|
class="form-control" |
62
|
|
|
id="lang" |
63
|
|
|
name="lang" |
64
|
|
|
placeholder="ru,en" |
65
|
|
|
value="<?= isset($_POST['lang']) ? $_POST['lang'] : SpellerClient::LANGUAGE_DEFAULT; ?>"> |
66
|
|
|
</div> |
67
|
|
|
</div> |
68
|
|
|
<div class="form-group"> |
69
|
|
|
<label for="options" class="col-sm-2 control-label">options</label> |
70
|
|
|
<div class="col-sm-10"> |
71
|
|
|
<input type="number" |
72
|
|
|
class="form-control" |
73
|
|
|
id="options" |
74
|
|
|
name="options" |
75
|
|
|
placeholder="0" |
76
|
|
|
value="<?= isset($_POST['options']) ? $_POST['options'] : SpellerClient::OPTION_DEFAULT; ?>"> |
77
|
|
|
</div> |
78
|
|
|
</div> |
79
|
|
|
<div class="form-group"> |
80
|
|
|
<label for="format" class="col-sm-2 control-label">format</label> |
81
|
|
|
<div class="col-sm-10"> |
82
|
|
|
<select class="form-control" id="format" name="format"> |
83
|
|
|
<option <?php if (isset($_POST['format']) && $_POST['format'] === SpellerClient::CHECK_TEXT_FORMAT_PLAIN) { ?> selected <?php } ?> ><?=SpellerClient::CHECK_TEXT_FORMAT_PLAIN?></option> |
84
|
|
|
<option <?php if (isset($_POST['format']) && $_POST['format'] === SpellerClient::CHECK_TEXT_FORMAT_HTML) { ?> selected <?php } ?>><?=SpellerClient::CHECK_TEXT_FORMAT_HTML?></option> |
85
|
|
|
</select> |
86
|
|
|
</div> |
87
|
|
|
</div> |
88
|
|
|
<div class="form-group"> |
89
|
|
|
<label for="callback" class="col-sm-2 control-label">callback</label> |
90
|
|
|
<div class="col-sm-10"> |
91
|
|
|
<input type="text" |
92
|
|
|
class="form-control" |
93
|
|
|
id="callback" |
94
|
|
|
name="callback" |
95
|
|
|
placeholder="your callback function name here" |
96
|
|
|
value="<?= isset($_POST['callback'])?$_POST['callback']:''; ?>"> |
97
|
|
|
</div> |
98
|
|
|
</div> |
99
|
|
|
<div class="form-group"> |
100
|
|
|
<label for="ie" class="col-sm-2 control-label">ie</label> |
101
|
|
|
<div class="col-sm-10"> |
102
|
|
|
<select class="form-control" id="ie" name="ie"> |
103
|
|
|
<option <?php if (isset($_POST['ie']) && $_POST['ie'] === 'utf-8') { ?> selected <?php } ?> >utf-8</option> |
104
|
|
|
<option <?php if (isset($_POST['ie']) && $_POST['ie'] === '1251') { ?> selected <?php } ?>>1251</option> |
105
|
|
|
</select> |
106
|
|
|
</div> |
107
|
|
|
</div> |
108
|
|
|
<div class="form-group"> |
109
|
|
|
<div class="col-sm-offset-2 col-sm-10"> |
110
|
|
|
<button type="submit" name="submit" class="btn btn-default">Invoke</button> |
111
|
|
|
</div> |
112
|
|
|
</div> |
113
|
|
|
</form> |
114
|
|
|
<h4>Result</h4> |
115
|
|
|
<?php |
116
|
|
|
$result = []; |
117
|
|
|
|
118
|
|
View Code Duplication |
if (isset($_POST['submit'])) { |
|
|
|
|
119
|
|
|
$spellerClient = new SpellerClient(); |
120
|
|
|
|
121
|
|
|
$result = $spellerClient->checkTexts( |
122
|
|
|
[ |
123
|
|
|
$_POST['text0'], |
124
|
|
|
$_POST['text1'], |
125
|
|
|
], |
126
|
|
|
[ |
127
|
|
|
'lang' => $_POST['lang'], |
128
|
|
|
'options' => $_POST['options'], |
129
|
|
|
'format' => $_POST['format'], |
130
|
|
|
'callback' => $_POST['callback'], |
131
|
|
|
'ie' => $_POST['ie'], |
132
|
|
|
] |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
$resultString = json_encode($result, JSON_PRETTY_PRINT); |
136
|
|
|
?> |
137
|
|
|
<pre><?=$resultString?></pre> |
138
|
|
|
</div> |
139
|
|
|
</div> |
140
|
|
|
</body> |
141
|
|
|
</html> |
142
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.