index.php ➔ safe_string()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
require dirname(dirname(__FILE__)).'/vendor/autoload.php';
3
use morphos\Gender;
4
use morphos\Russian\CardinalNumeralGenerator;
5
use morphos\Russian\Cases;
6
use morphos\Russian\NounDeclension;
7
use morphos\Russian\GeographicalNamesInflection;
8
use morphos\Russian\NounPluralization;
9
use morphos\Russian\OrdinalNumeralGenerator;
10
11
function safe_string($string) {
12
	return preg_replace('~[^А-Яа-яЁё -]~u', null, trim($string));
13
}
14
15
foreach (array('name', 'noun', 'geographical-name') as $field) {
16
	if (isset($_POST[$field])) {
17
		$_POST[$field] = safe_string($_POST[$field]);
18
	}
19
}
20
21
$gender_labels = array(Gender::MALE => 'мужской', Gender::FEMALE => 'женский', Gender::NEUTER => 'средний');
22
23
?><html>
24
<head>
25
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
26
	<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
27
	<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
28
	<title>Morphos Testing Script</title>
29
	<style>
30
	.demo-layout-transparent {
31
	}
32
	.demo-layout-transparent .mdl-layout__header,
33
	.demo-layout-transparent .mdl-layout__drawer-button {
34
	  /* This background is dark, so we set text to white. Use 87% black instead if
35
	     your background is light. */
36
	  color: white;
37
	  background-color: #0B5A78;
38
	}
39
	</style>
40
</head>
41
<body>
42
	<div class="demo-layout-transparent mdl-layout mdl-js-layout">
43
		<header class="mdl-layout__header mdl-layout__header--transparent">
44
			<div class="mdl-layout__header-row">
45
				<!-- Title -->
46
				<span class="mdl-layout-title">Morphos Testing Script</span>
47
				<!-- Add spacer, to align navigation to the right -->
48
				<div class="mdl-layout-spacer"></div>
49
				<!-- Navigation -->
50
				<!-- <nav class="mdl-navigation">
51
					<a class="mdl-navigation__link" href="">Link</a>
52
					<a class="mdl-navigation__link" href="">Link</a>
53
					<a class="mdl-navigation__link" href="">Link</a>
54
					<a class="mdl-navigation__link" href="">Link</a>
55
				</nav> -->
56
			</div>
57
		</header>
58
		<div class="mdl-layout__drawer">
59
			<span class="mdl-layout-title">Useful links</span>
60
				<nav class="mdl-navigation">
61
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos">GitHub</a>
62
				<a class="mdl-navigation__link" href="https://packagist.org/packages/wapmorgan/morphos">Packagist</a>
63
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos-Blade">Blade adapter</a>
64
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos-Twig">Twig adapter</a>
65
			</nav>
66
		</div>
67
		<main class="mdl-layout__content">
68
69
			<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
70
				<div class="mdl-tabs__tab-bar">
71
			      <a href="#personal-names" class="mdl-tabs__tab is-active">Склонение имен собственных</a>
72
			      <a href="#geographical-names" class="mdl-tabs__tab">Склонение географических названий</a>
73
			      <a href="#nouns" class="mdl-tabs__tab">Склонение существительных</a>
74
			      <a href="#numerals" class="mdl-tabs__tab">Генерация числительных</a>
75
				</div>
76
77
				<div class="mdl-tabs__panel" id="nouns">
78
					<div class="mdl-grid">
79
						<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
80
							<form method="post" action="#nouns">
81
								<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
82
									<tbody>
83
										<tr>
84
											<td class="mdl-data-table__cell--non-numeric">
85
												<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
86
													<input name="noun" value="<?= isset($_POST['noun']) ? $_POST['noun'] : null ?>" class="mdl-textfield__input" id="noun-input">
87
													<label class="mdl-textfield__label" for="noun-input">Существительное</label>
88
											</td>
89
										</tr>
90
										<tr>
91
											<td class="mdl-data-table__cell--non-numeric"><label><input type="checkbox" name="animate" <?= isset($_POST['animate']) ? "checked='checked'" : null ?> /> Одушевлённое</label></td>
92
										</tr>
93
										<tr>
94
											<td class="mdl-data-table__cell--non-numeric"><input type="submit" value="Просклонять"/> <input name="count" type="submit" value="Посчитать до 100"/></td>
95
										</tr>
96
									</tbody>
97
								</table>
98
							</form>
99
						</div>
100
						<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
101
<?php if (isset($_POST['noun'])): ?>
102
	<?php
103
	$animate = !empty($_POST['animate']);
104
	$noun = $_POST['noun'];
105
	?>
106
	<?php if (!isset($_POST['count'])): ?>
107
	<?php
108
	$cases = NounDeclension::getCases($noun, $animate);
109
	?>
110
		<table>
111
			<tr>
112
				<td>
113
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
114
							<tbody>
115
								<tr>
116
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?= $noun ?> (<?=NounDeclension::getDeclension($noun)?> склонение)</td>
117
								</tr>
118 View Code Duplication
								<?php foreach(array(Cases::IMENIT => 'Именительный', Cases::RODIT => 'Родительный', Cases::DAT => 'Дательный', Cases::VINIT => 'Винительный', Cases::TVORIT => 'Творительный', Cases::PREDLOJ => 'Предложный') as $case => $name): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
119
									<tr>
120
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
121
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
122
									</tr>
123
								<?php endforeach; ?>
124
							</tbody>
125
						</table>
126
				</td>
127
				<td>
128
	<?php
129
	$cases = NounPluralization::getCases($noun, $animate);
130
	?>
131
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
132
							<tbody>
133
								<tr>
134
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$_POST['noun']?> (<?=NounDeclension::getDeclension($noun)?> склонение) во множественном числе</td>
135
								</tr>
136 View Code Duplication
								<?php foreach(array(Cases::IMENIT => 'Именительный', Cases::RODIT => 'Родительный', Cases::DAT => 'Дательный', Cases::VINIT => 'Винительный', Cases::TVORIT => 'Творительный', Cases::PREDLOJ => 'Предложный') as $case => $name): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
137
									<tr>
138
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
139
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
140
									</tr>
141
								<?php endforeach; ?>
142
							</tbody>
143
						</table>
144
				</td>
145
			</tr>
146
		</table>
147
			<?php else: ?>
148
				<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
149
					<tbody>
150
						<tr>
151
							<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$noun?> (<?=NounDeclension::getDeclension($noun)?> склонение)</td>
152
						</tr>
153
						<?php for ($i = 1; $i <= 20; $i++): ?>
154
							<tr>
155
								<td class="mdl-data-table__cell--non-numeric"><?=$i.' '.NounPluralization::pluralize($noun, $i, $animate)?></td>
156
								<td class="mdl-data-table__cell--non-numeric"><?=($i+20).' '.NounPluralization::pluralize($noun, $i + 20, $animate)?></td>
157
								<td class="mdl-data-table__cell--non-numeric"><?=($i+40).' '.NounPluralization::pluralize($noun, $i + 40, $animate)?></td>
158
								<td class="mdl-data-table__cell--non-numeric"><?=($i+60).' '.NounPluralization::pluralize($noun, $i + 60, $animate)?></td>
159
								<td class="mdl-data-table__cell--non-numeric"><?=($i+80).' '.NounPluralization::pluralize($noun, $i + 80, $animate)?></td>
160
							</tr>
161
						<?php endfor; ?>
162
					</tbody>
163
				</table>
164
			<?php endif; ?>
165
		<?php endif; ?>
166
						</div>
167
					</div>
168
				</form>
169
			</div>
170
171
			<div class="mdl-tabs__panel" id="geographical-names">
172
				<div class="mdl-grid">
173
					<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
174
						<form method="post" action="#geographical-names">
175
							<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
176
								<tbody>
177
									<tr>
178
										<td class="mdl-data-table__cell--non-numeric">
179
											<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
180
											<input name="geographical-name" value="<?= isset($_POST['geographical-name']) ? $_POST['geographical-name'] : null ?>" class="mdl-textfield__input" id="geographical-name-input">
181
											<label class="mdl-textfield__label" for="geographical-name-input">Город, страна</label>
182
											</div>
183
										</td>
184
									</tr>
185
									<tr>
186
										<td class="mdl-data-table__cell--non-numeric">
187
											<input type="submit" value="Просклонять"/>
188
										</td>
189
									</tr>
190
								</tbody>
191
							</table>
192
						</form>
193
					</div>
194
					<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
195
			<?php if (isset($_POST['geographical-name'])): ?>
196
	<?php
197
	$geographical_name = $_POST['geographical-name'];
198
	$cases = GeographicalNamesInflection::getCases($geographical_name);
199
	?>
200
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
201
							<tbody>
202
								<tr>
203
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$geographical_name?></td>
204
								</tr>
205 View Code Duplication
								<?php foreach(array(Cases::IMENIT => 'Именительный', Cases::RODIT => 'Родительный', Cases::DAT => 'Дательный', Cases::VINIT => 'Винительный', Cases::TVORIT => 'Творительный', Cases::PREDLOJ => 'Предложный') as $case => $name): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
206
									<tr>
207
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
208
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
209
									</tr>
210
								<?php endforeach; ?>
211
							</tbody>
212
						</table>
213
		<?php endif; ?>
214
					</div>
215
				</div>
216
			</div>
217
218
			<div class="mdl-tabs__panel is-active" id="personal-names">
219
				<div class="mdl-grid">
220
					<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
221
						<form method="post" action="#personal-names">
222
							<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
223
								<tbody>
224
									<tr>
225
										<td class="mdl-data-table__cell--non-numeric">
226
											<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
227
												<input name="name" value="<?= isset($_POST['name']) ? $_POST['name'] : null ?>" class="mdl-textfield__input" id="name-input">
228
												<label class="mdl-textfield__label" for="name-inpuy">Фамилия Имя [Отчество]</label>
229
											</div>
230
										</td>
231
									</tr>
232
									<tr>
233
										<td class="mdl-data-table__cell--non-numeric">
234
											Выберите пол:
235
											<label><input type="radio" name="gender" value="" <?= !isset($_POST['gender']) || !in_array($_POST['gender'], array(Gender::MALE, Gender::FEMALE)) ? "checked='checked'" : null ?> /> Автоматически </label>
236
											<label><input type="radio" name="gender" value="<?=morphos\Gender::MALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::MALE ? "checked='checked'" : null ?> /> Мужской </label>
237
											<label><input type="radio" name="gender" value="<?=morphos\Gender::FEMALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::FEMALE ? "checked='checked'" : null ?> /> Женский </label>
238
										</td>
239
									</tr>
240
									<tr>
241
										<td class="mdl-data-table__cell--non-numeric">
242
											<input type="submit" value="Просклонять"/>
243
										</td>
244
									</tr>
245
								</tbody>
246
							</table>
247
						</form>
248
					</div>
249
					<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
250
<?php if (isset($_POST['name'])): ?>
251
	<?php
252
	$name = $_POST['name'];
253
	$gender = !empty($_POST['gender']) ? $_POST['gender'] : morphos\Russian\detectGender($name);
254
	$cases = morphos\Russian\inflectName($name, null, $gender);
255
	if ($cases !== false):
256
	?>
257
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
258
							<tbody>
259
								<tr>
260
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$name?> (<?= isset($gender_labels[$gender]) ? $gender_labels[$gender] : 'неопределенный' ?> пол)</td>
261
								</tr>
262 View Code Duplication
								<?php foreach(array(Cases::IMENIT => 'Именительный', Cases::RODIT => 'Родительный', Cases::DAT => 'Дательный', Cases::VINIT => 'Винительный', Cases::TVORIT => 'Творительный', Cases::PREDLOJ => 'Предложный') as $case => $name): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
263
									<tr>
264
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
265
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
266
									</tr>
267
								<?php endforeach; ?>
268
							</tbody>
269
						</table>
270
		<?php endif; ?>
271
		<?php endif; ?>
272
					</div>
273
				</div>
274
			</div>
275
276
			<div class="mdl-tabs__panel" id="numerals">
277
					<div class="mdl-grid">
278
						<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
279
							<form method="post" action="#numerals">
280
								<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
281
									<tbody>
282
										<tr>
283
											<td class="mdl-data-table__cell--non-numeric">
284
												<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
285
													<input name="number" value="<?= isset($_POST['number']) ? intval($_POST['number']) : null ?>" class="mdl-textfield__input" id="number-input">
286
													<label class="mdl-textfield__label" for="number-input">Число</label>
287
												</div>
288
											</td>
289
										</tr>
290
										<tr>
291
											<td class="mdl-data-table__cell--non-numeric">
292
												Выберите пол связанного числительного:
293
												<label><input type="radio" name="gender" value="<?=morphos\Gender::NEUTER?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::NEUTER ? "checked='checked'" : null ?> /> Средний </label>
294
												<label><input type="radio" name="gender" value="<?=morphos\Gender::MALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::MALE ? "checked='checked'" : null ?> /> Мужской </label>
295
												<label><input type="radio" name="gender" value="<?=morphos\Gender::FEMALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::FEMALE ? "checked='checked'" : null ?> /> Женский </label>
296
											</td>
297
										</tr>
298
										<tr>
299
											<td class="mdl-data-table__cell--non-numeric"><input type="submit" name="ordinal" value="Сгенерировать числительные"/></td>
300
										</tr>
301
									</tbody>
302
								</table>
303
							</form>
304
						</div>
305
						<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
306
<?php if (isset($_POST['number'])): ?>
307
	<?php
308
	$number = intval($_POST['number']);
309
	$gender = isset($_POST['gender']) ? $_POST['gender'] : morphos\Gender::MALE;
310
	$cardinal = CardinalNumeralGenerator::getCases($number, $gender);
311
  $ordinal = OrdinalNumeralGenerator::getCases($number, $gender);
312
	?>
313
	<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
314
		<thead>
315
				<th class="mdl-data-table__cell--non-numeric" style="text-align: center;"><?=$number?> (<?= $gender_labels[$gender] ?> род)</th>
316
				<th class="mdl-data-table__cell--non-numeric" style="text-align: center;">Количественное</th>
317
				<th class="mdl-data-table__cell--non-numeric" style="text-align: center;">Порядковое</th>
318
		</thead>
319
		<tbody>
320 View Code Duplication
			<?php foreach(array(Cases::IMENIT => 'Именительный', Cases::RODIT => 'Родительный', Cases::DAT => 'Дательный', Cases::VINIT => 'Винительный', Cases::TVORIT => 'Творительный', Cases::PREDLOJ => 'Предложный') as $case => $name): ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
321
				<tr>
322
					<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
323
					<td class="mdl-data-table__cell--non-numeric"><?=$cardinal[$case]?></td>
324
					<td class="mdl-data-table__cell--non-numeric"><?=$ordinal[$case]?></td>
325
				</tr>
326
			<?php endforeach; ?>
327
		</tbody>
328
	</table>
329
		<?php endif; ?>
330
						</div>
331
					</div>
332
				</form>
333
			</div>
334
335
		</main>
336
	</div>
337
</body>
338
</html>