Completed
Push — master ( 5a986f...26b628 )
by f
01:45
created

index.php ➔ safe_string()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
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\Russian\CardinalNumeral;
4
use morphos\Russian\Cases;
5
use morphos\Russian\GeneralDeclension;
6
use morphos\Russian\GeographicalNamesDeclension;
7
use morphos\Russian\Plurality;
8
use morphos\Russian\OrdinalNumeral;
9
10
function safe_string($string) {
11
	return preg_replace('~[^А-Яа-яЁё ]~u', null, trim($string));
12
}
13
14
foreach (array('name', 'noun', 'geographical-name') as $field) {
15
	if (isset($_POST[$field])) {
16
		$_POST[$field] = safe_string($_POST[$field]);
17
		var_dump($_POST[$field]);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($_POST[$field]); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
18
	}
19
}
20
21
?><html>
22
<head>
23
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
24
	<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
25
	<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
26
	<title>Morphos Testing Script</title>
27
	<style>
28
	.demo-layout-transparent {
29
	}
30
	.demo-layout-transparent .mdl-layout__header,
31
	.demo-layout-transparent .mdl-layout__drawer-button {
32
	  /* This background is dark, so we set text to white. Use 87% black instead if
33
	     your background is light. */
34
	  color: white;
35
	  background-color: #0B5A78;
36
	}
37
	</style>
38
</head>
39
<body>
40
	<div class="demo-layout-transparent mdl-layout mdl-js-layout">
41
		<header class="mdl-layout__header mdl-layout__header--transparent">
42
			<div class="mdl-layout__header-row">
43
				<!-- Title -->
44
				<span class="mdl-layout-title">Morphos Testing Script</span>
45
				<!-- Add spacer, to align navigation to the right -->
46
				<div class="mdl-layout-spacer"></div>
47
				<!-- Navigation -->
48
				<!-- <nav class="mdl-navigation">
49
					<a class="mdl-navigation__link" href="">Link</a>
50
					<a class="mdl-navigation__link" href="">Link</a>
51
					<a class="mdl-navigation__link" href="">Link</a>
52
					<a class="mdl-navigation__link" href="">Link</a>
53
				</nav> -->
54
			</div>
55
		</header>
56
		<div class="mdl-layout__drawer">
57
			<span class="mdl-layout-title">Useful links</span>
58
				<nav class="mdl-navigation">
59
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos">GitHub</a>
60
				<a class="mdl-navigation__link" href="https://packagist.org/packages/wapmorgan/morphos">Packagist</a>
61
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos-Blade">Blade adapter</a>
62
				<a class="mdl-navigation__link" href="https://github.com/wapmorgan/Morphos-Twig">Twig adapter</a>
63
			</nav>
64
		</div>
65
		<main class="mdl-layout__content">
66
67
			<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
68
				<div class="mdl-tabs__tab-bar">
69
			      <a href="#personal-names" class="mdl-tabs__tab is-active">Склонение имен собственных</a>
70
			      <a href="#geographical-names" class="mdl-tabs__tab">Склонение географических названий</a>
71
			      <a href="#nouns" class="mdl-tabs__tab">Склонение существительных</a>
72
			      <a href="#numerals" class="mdl-tabs__tab">Генерация числительных</a>
73
				</div>
74
75
				<div class="mdl-tabs__panel" id="nouns">
76
					<div class="mdl-grid">
77
						<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
78
							<form method="post" action="#nouns">
79
								<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
80
									<tbody>
81
										<tr>
82
											<td class="mdl-data-table__cell--non-numeric">Введите имя существительное: <input name="noun" value="<?= isset($_POST['noun']) ? $_POST['noun'] : null ?>"></td>
83
										</tr>
84
										<tr>
85
											<td class="mdl-data-table__cell--non-numeric"><label><input type="checkbox" name="animate" <?= isset($_POST['animate']) ? "checked='checked'" : null ?> /> Одушевлённое</label></td>
86
										</tr>
87
										<tr>
88
											<td class="mdl-data-table__cell--non-numeric"><input type="submit" value="Просклонять"/> <input name="count" type="submit" value="Посчитать до 100"/></td>
89
										</tr>
90
									</tbody>
91
								</table>
92
							</form>
93
						</div>
94
						<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
95
<?php if (isset($_POST['noun'])): ?>
96
	<?php
97
	$animate = !empty($_POST['animate']);
98
	$noun = $_POST['noun'];
99
	?>
100
	<?php if (!isset($_POST['count'])): ?>
101
	<?php
102
	$cases = GeneralDeclension::getCases($noun, $animate);
103
	?>
104
		<table>
105
			<tr>
106
				<td>
107
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
108
							<tbody>
109
								<tr>
110
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?= $noun ?> (<?=GeneralDeclension::getDeclension($noun)?> склонение)</td>
111
								</tr>
112 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...
113
									<tr>
114
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
115
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
116
									</tr>
117
								<?php endforeach; ?>
118
							</tbody>
119
						</table>
120
				</td>
121
				<td>
122
	<?php
123
	$cases = Plurality::getCases($noun, $animate);
124
	?>
125
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
126
							<tbody>
127
								<tr>
128
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$_POST['noun']?> (<?=GeneralDeclension::getDeclension($noun)?> склонение) во множественном числе</td>
129
								</tr>
130 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...
131
									<tr>
132
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
133
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
134
									</tr>
135
								<?php endforeach; ?>
136
							</tbody>
137
						</table>
138
				</td>
139
			</tr>
140
		</table>
141
			<?php else: ?>
142
				<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
143
					<tbody>
144
						<tr>
145
							<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$noun?> (<?=GeneralDeclension::getDeclension($noun)?> склонение)</td>
146
						</tr>
147
						<?php for ($i = 1; $i <= 20; $i++): ?>
148
							<tr>
149
								<td class="mdl-data-table__cell--non-numeric"><?=$i.' '.PLurality::pluralize($noun, $i, $animate)?></td>
150
								<td class="mdl-data-table__cell--non-numeric"><?=($i+20).' '.PLurality::pluralize($noun, $i + 20, $animate)?></td>
151
								<td class="mdl-data-table__cell--non-numeric"><?=($i+40).' '.PLurality::pluralize($noun, $i + 40, $animate)?></td>
152
								<td class="mdl-data-table__cell--non-numeric"><?=($i+60).' '.PLurality::pluralize($noun, $i + 60, $animate)?></td>
153
								<td class="mdl-data-table__cell--non-numeric"><?=($i+80).' '.PLurality::pluralize($noun, $i + 80, $animate)?></td>
154
							</tr>
155
						<?php endfor; ?>
156
					</tbody>
157
				</table>
158
			<?php endif; ?>
159
		<?php endif; ?>
160
						</div>
161
					</div>
162
				</form>
163
			</div>
164
165
			<div class="mdl-tabs__panel" id="geographical-names">
166
				<div class="mdl-grid">
167
					<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
168
						<form method="post" action="#geographical-names">
169
							<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
170
								<tbody>
171
									<tr>
172
										<td class="mdl-data-table__cell--non-numeric">
173
											<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
174
											<input name="geographical-name" value="<?= isset($_POST['geographical-name']) ? $_POST['geographical-name'] : null ?>" class="mdl-textfield__input" id="geographical-name-input">
175
											<label class="mdl-textfield__label" for="name-inpuy">Улица, город, страна</label>
176
											</div>
177
										</td>
178
									</tr>
179
									<tr>
180
										<td class="mdl-data-table__cell--non-numeric">
181
											<input type="submit" value="Просклонять"/>
182
										</td>
183
									</tr>
184
								</tbody>
185
							</table>
186
						</form>
187
					</div>
188
					<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
189
			<?php if (isset($_POST['geographical-name'])): ?>
190
	<?php
191
	$geographical_name = $_POST['geographical-name'];
192
	$cases = GeographicalNamesDeclension::getCases($geographical_name);
193
	?>
194
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
195
							<tbody>
196
								<tr>
197
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$geographical_name?></td>
198
								</tr>
199 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...
200
									<tr>
201
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
202
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
203
									</tr>
204
								<?php endforeach; ?>
205
							</tbody>
206
						</table>
207
		<?php endif; ?>
208
					</div>
209
				</div>
210
			</div>
211
212
			<div class="mdl-tabs__panel is-active" id="personal-names">
213
				<div class="mdl-grid">
214
					<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
215
						<form method="post" action="#personal-names">
216
							<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
217
								<tbody>
218
									<tr>
219
										<td class="mdl-data-table__cell--non-numeric">
220
											<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
221
												<input name="name" value="<?= isset($_POST['name']) ? $_POST['name'] : null ?>" class="mdl-textfield__input" id="name-input">
222
												<label class="mdl-textfield__label" for="name-inpuy">Фамилия Имя [Отчество]</label>
223
											</div>
224
										</td>
225
									</tr>
226
									<tr>
227
										<td class="mdl-data-table__cell--non-numeric">
228
											Выберите пол:
229
											<label><input type="radio" name="gender" value="" <?= isset($_POST['gender']) && $_POST['gender'] == '' ? "checked='checked'" : null ?> /> Автоматически </label>
230
											<label><input type="radio" name="gender" value="<?=morphos\Gender::MALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::MALE ? "checked='checked'" : null ?> /> Мужской </label>
231
											<label><input type="radio" name="gender" value="<?=morphos\Gender::FEMALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::FEMALE ? "checked='checked'" : null ?> /> Женский </label>
232
										</td>
233
									</tr>
234
									<tr>
235
										<td class="mdl-data-table__cell--non-numeric">
236
											<input type="submit" value="Просклонять"/>
237
										</td>
238
									</tr>
239
								</tbody>
240
							</table>
241
						</form>
242
					</div>
243
					<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
244
<?php if (isset($_POST['name'])): ?>
245
	<?php
246
	$name = $_POST['name'];
247
	$gender = !empty($_POST['gender']) ? $_POST['gender'] : morphos\Russian\detectGender($name);
248
	$cases = morphos\Russian\name($name, null, $gender);
249
	if ($cases !== false):
250
	?>
251
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
252
							<tbody>
253
								<tr>
254
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$name?> (<?=$gender?>)</td>
255
								</tr>
256 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...
257
									<tr>
258
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
259
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
260
									</tr>
261
								<?php endforeach; ?>
262
							</tbody>
263
						</table>
264
		<?php endif; ?>
265
		<?php endif; ?>
266
					</div>
267
				</div>
268
			</div>
269
270
			<div class="mdl-tabs__panel" id="numerals">
271
					<div class="mdl-grid">
272
						<div class="mdl-cell mdl-cell--6-col" style="text-align: right;">
273
							<form method="post" action="#numerals">
274
								<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="margin: 0 0 0 auto;">
275
									<tbody>
276
										<tr>
277
											<td class="mdl-data-table__cell--non-numeric">Введите число: <input name="number" value="<?= isset($_POST['number']) ? intval($_POST['number']) : null ?>"></td>
278
										</tr>
279
										<tr>
280
											<td class="mdl-data-table__cell--non-numeric"><input type="submit" value="Сгенерировать количественные числительные"/></td>
281
										</tr>
282
										<tr>
283
											<td class="mdl-data-table__cell--non-numeric">
284
												Выберите пол связанного числительного:
285
												<label><input type="radio" name="gender" value="<?=morphos\Gender::NEUTER?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::NEUTER ? "checked='checked'" : null ?> /> Средний </label>
286
												<label><input type="radio" name="gender" value="<?=morphos\Gender::MALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::MALE ? "checked='checked'" : null ?> /> Мужской </label>
287
												<label><input type="radio" name="gender" value="<?=morphos\Gender::FEMALE?>" <?= isset($_POST['gender']) && $_POST['gender'] == morphos\Gender::FEMALE ? "checked='checked'" : null ?> /> Женский </label>
288
											</td>
289
										</tr>
290
										<tr>
291
											<td class="mdl-data-table__cell--non-numeric"><input type="submit" name="ordinal" value="Сгенерировать порядковые числительные"/></td>
292
										</tr>
293
									</tbody>
294
								</table>
295
							</form>
296
						</div>
297
						<div class="mdl-cell mdl-cell--6-col" style="text-align: left;">
298
<?php if (isset($_POST['number'])): ?>
299
	<?php
300
	$number = intval($_POST['number']);
301
	?>
302
	<?php
303
	if (!isset($_POST['ordinal'])):
304
	$cases = CardinalNumeral::getCases($number);
305
	?>
306
		<table>
307
			<tr>
308
				<td>
309
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
310
							<tbody>
311
								<tr>
312
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$number?></td>
313
								</tr>
314 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...
315
									<tr>
316
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
317
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
318
									</tr>
319
								<?php endforeach; ?>
320
							</tbody>
321
						</table>
322
				</td>
323
				<td>
324
	<?php
325
	else:
326
	$gender = isset($_POST['gender']) ? $_POST['gender'] : morphos\Gender::MALE;
327
	$cases = OrdinalNumeral::getCases($number, $gender);
328
	?>
329
						<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
330
							<tbody>
331
								<tr>
332
									<td class="mdl-data-table__cell--non-numeric" colspan="2" style="text-align: center;"><?=$number?> (<?=$gender?>)</td>
333
								</tr>
334 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...
335
									<tr>
336
										<td class="mdl-data-table__cell--non-numeric"><?=$name?></td>
337
										<td class="mdl-data-table__cell--non-numeric"><?=$cases[$case]?></td>
338
									</tr>
339
								<?php endforeach; ?>
340
							</tbody>
341
						</table>
342
				</td>
343
			</tr>
344
		</table>
345
			<?php endif; ?>
346
		<?php endif; ?>
347
						</div>
348
					</div>
349
				</form>
350
			</div>
351
352
		</main>
353
	</div>
354
</body>
355
</html>