-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate.php
339 lines (301 loc) · 9.91 KB
/
generate.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
// Some php functions for generating the site
if (!defined('TLB'))
die('No direct access...');
/* Get the first part of the syllable: Either a consonant or a consonant cluster
* Does not take into consideration that it is possible to open a Na'vi syllable with no consonant
*/
function getInitial() {
$type;
$result;
/* 70% of the time, the syllable will start with single letter
* 30% of the time, the syllable will start with a consonant cluster
*/
if (rand(0,100) <= 70) {
$type="single";
} else {
$type="cluster";
}
/* single consonant starts the syllable
* The way this is done, it appears that as we go down this list, they get more common
*/
if ($type == "single") {
$rn = rand(0, 100);
if ($rn <= 4) { $result = "px"; }
else if ($rn <= 8) { $result = "tx"; }
else if ($rn <= 12) { $result = "kx"; }
else if ($rn <= 17) { $result = "p"; }
else if ($rn <= 22) { $result = "t"; }
else if ($rn <= 27) { $result = "k"; }
else if ($rn <= 32) { $result = "ts"; }
else if ($rn <= 37) { $result = "f"; }
else if ($rn <= 42) { $result = "s"; }
else if ($rn <= 47) { $result = "h"; }
else if ($rn <= 52) { $result = "v"; }
else if ($rn <= 57) { $result = "z"; }
else if ($rn <= 62) { $result = "m"; }
else if ($rn <= 67) { $result = "n"; }
else if ($rn <= 72) { $result = "ng"; }
else if ($rn <= 77) { $result = "r"; }
else if ($rn <= 82) { $result = "l"; }
else if ($rn <= 87) { $result = "w"; }
else if ($rn <= 92) { $result = "n"; }
else { $result = "'"; }
// consonant cluster starts the syllable
} else {
$ro = rand(1, 3);
// start with f
if ($ro == 1) {
$rp = rand(1, 100);
if ($rp <= 5) { $result = "fpx"; }
else if ($rp <= 11) { $result = "fkx"; }
else if ($rp <= 16) { $result = "ftx"; }
else if ($rp <= 25) { $result = "ft"; }
else if ($rp <= 33) { $result = "fp"; }
else if ($rp <= 42) { $result = "fk"; }
else if ($rp <= 50) { $result = "fm"; }
else if ($rp <= 57) { $result = "fn"; }
else if ($rp <= 63) { $result = "fng"; }
else if ($rp <= 70) { $result = "fr"; }
else if ($rp <= 78) { $result = "fl"; }
else if ($rp <= 86) { $result = "fw"; }
else if ($rp <= 94) { $result = "fy"; }
else { $result = "fr"; }
// start with s
} else if ($ro == 2) {
$rp = rand(1, 100);
if ($rp <= 5) { $result = "spx"; }
else if ($rp <= 11) { $result = "skx"; }
else if ($rp <= 16) { $result = "stx"; }
else if ($rp <= 25) { $result = "st"; }
else if ($rp <= 33) { $result = "sp"; }
else if ($rp <= 42) { $result = "sk"; }
else if ($rp <= 50) { $result = "sm"; }
else if ($rp <= 57) { $result = "sn"; }
else if ($rp <= 63) { $result = "sng"; }
else if ($rp <= 70) { $result = "sr"; }
else if ($rp <= 78) { $result = "sl"; }
else if ($rp <= 86) { $result = "sw"; }
else if ($rp <= 94) { $result = "sy"; }
else { $result = "sr"; }
// start with ts
} else if ($ro == 3) {
$rp = rand(1, 100);
if ($rp <= 5) { $result = "tspx"; }
else if ($rp <= 11) { $result = "tskx"; }
else if ($rp <= 16) { $result = "tstx"; }
else if ($rp <= 25) { $result = "tst"; }
else if ($rp <= 33) { $result = "tsp"; }
else if ($rp <= 42) { $result = "tsk"; }
else if ($rp <= 50) { $result = "tsm"; }
else if ($rp <= 57) { $result = "tsn"; }
else if ($rp <= 63) { $result = "tsng"; }
else if ($rp <= 70) { $result = "tsr"; }
else if ($rp <= 78) { $result = "tsl"; }
else if ($rp <= 86) { $result = "tsw"; }
else if ($rp <= 94) { $result = "tsy"; }
else {$result = "tsr";}
}
}
return $result;
}
// Get a vowel or diphthong as the center of the syllable
function getNucleus() {
$isDiphthong;
$result;
//randomly select whether vowel or diphthong
if (rand(0,100) > 20) {
$isDiphthong="kehe";
} else {
$isDiphthong="srane";
}
// randomly select a diphthong
if ($isDiphthong == "srane") {
$rx = rand(0, 100);
if ($rx <= 25) { $result = "ew"; }
else if ($rx <= 50) { $result = "aw"; }
else if ($rx <= 75) { $result = "ay"; }
else if ($rx <= 100) { $result = "ey"; }
// randomly select a vowel
} else {
$ry = rand(1, 100);
if ($ry <= 25) { $result = "a"; }
else if ($ry <= 40) { $result = "e"; }
else if ($ry <= 55) { $result = "o"; }
else if ($ry <= 70) { $result = "u"; }
else if ($ry <= 80) { $result = "ì"; }
else if ($ry <= 85) { $result = "ä"; }
else { $result = "a"; }
}
return $result;
}
// Get a consonant (or not) to end the syllable with
function getCoda() {
$result;
$rz = rand(0, 320);
if ($rz <= 4) { $result = "px"; }
else if ($rz <= 8) { $result = "tx"; }
else if ($rz <= 12) { $result = "kx"; }
else if ($rz <= 20) { $result = "p"; }
else if ($rz <= 28) { $result = "t"; }
else if ($rz <= 44) { $result = "k"; }
else if ($rz <= 49) { $result = "k"; }
else if ($rz <= 58) { $result = "m"; }
else if ($rz <= 70) { $result = "n"; }
else if ($rz <= 76) { $result = "ng"; }
else if ($rz <= 80) { $result = "r"; }
else if ($rz <= 85) { $result = "l"; }
else { $result=""; } // syllable will end with the vowel from getNucleus()
return $result;
}
/* Validate the input vars from the URL - No ridiculousness this time -- at all. :P
* Acceptable Ranges:
* 1 ≤ $a, $b, $c ≤ 4
* 1 ≤ $k ≤ 100
*/
function valid($a, $b, $c, $k) {
/* a, b, c, k not set, usually a fresh referal from index.php
* Requiring at least index.php?page=generator&a=1&b=1&c=1&k=1 is so lame. So having unset abck is valid
* Also happens if any or all elements in form are not selected and submitted. Should also be valid
*/
if (!isset($a) || !isset($b) || !isset($c) || !isset($k)) {
return true;
}
// They all need to be integers
if (!preg_match('/^\d+$/' , $a . $b . $c . $k))
{
return false;
}
// disallow generating HRH.gif amounts of names
if ($k > 100) {
return false;
}
// lolwut, zero syllables? Negative syllables?
if ($a < 1 || $b < 1 || $c < 1 || $k < 1) {
return false;
// Probably Vawmataw or someone trying to be funny by generating HRH.gif amounts of syllables
} else if ($a > 4 || $b > 4 || $c > 4) {
return false;
// they are all set and with values between and including 1 thru 4
} else {
return true;
}
}
/* Main function to generate the names
* Echo a generated name and the user form and footer
* Get vars from URL or form to generate another name
*/
function name_gen()
{
global $txt;
echo '<h2>';
$a = isset($_REQUEST["a"]) ? $_REQUEST["a"] : 1; // number of syllables in the First name
$b = isset($_REQUEST["b"]) ? $_REQUEST["b"] : 1; // number of syllables in the Family name
$c = isset($_REQUEST["c"]) ? $_REQUEST["c"] : 1; // number of syllables in the Parent's name
$k = isset($_REQUEST["k"]) ? $_REQUEST["k"] : 1; // number of names to be generated
// No funny business, y'all. :P
if (!valid($a, $b, $c, $_REQUEST["k"])) {
echo $txt['g_n_try'], ' </h2>';
} else {
$mk=0;
while ($mk < $k) { // Do entire generator process k times
$i=0;
// BUILD FIRST NAME
echo ucfirst(getInitial().getNucleus()); // echo First syllable: CV
while ($i <= $a - 2) {
echo getInitial().getNucleus(); // echo some more CV until $a syllables
$i++;
}
echo getCoda(); // Maybe end the syllable with something, maybe not
$i=0; // reset counter back to 0 for next part of the name
echo " te ";
// BUILD FAMILY NAME
echo ucfirst(getInitial().getNucleus()); // CV
while ($i <= $b - 2) {
echo getInitial().getNucleus(); // CV
$i++;
}
echo getCoda(); // C or None
$i=0; // reset again for last part of name
echo " ";
// BUILD PARENT'S NAME
echo ucfirst(getInitial().getNucleus());
while ($i <= $c - 2) {
echo getInitial().getNucleus();
$i++;
}
echo getCoda();$i=0;
echo "'it";
// 50/50 chance of male/female name; TODO: Possibly make this something that the user can choose?
if (rand(0,1)==0) {
echo "an";
} else {
echo "e";
}
echo "<br />"; // Need this to ensure each name generated is on its own line
$mk++; // Increment number of times entire process finished
}
echo '</h2>'; // close h2 tag enclosing generated names
}
// echo the user input form and generator info footer
echo '
<br />
<hr>
<style>select{display:block;}</style>
<div class="row">
<form class="col s12" name="sform" action="index.php" method="get">
<input type="hidden" name="p" value="generator">
<div class="row">
<div class="input-field col s12 l4">
<select name="a">
<option value="" disabled selected>', $txt['g_first_name'], '</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="row">
<div class="input-field col s12 l4">
<select name="b">
<option value="" disabled selected>', $txt['g_family_name'], '</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="row">
<div class="input-field col s12 l4">
<select name="c">
<option value="" disabled selected>', $txt['g_parent_name'], '</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="row">
<div class="input-field col s12 l4">
<select name="k">
<option value="" disabled selected>', $txt['g_number_of_name'], '</option>
<option value="1">1</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
</div>
<button class="btn waves-effect waves-light amber black-text" type="submit">
', $txt['g_generate'], '
<i class="material-icons right">send</i>
</button>
</form>
</div>
<div style="margin-top: 18px; text-align: center; border-top: 1px solid #eeeeee; padding-top: 5px; ">', $txt['g_credits'], '</div>';
}
?>