-
Notifications
You must be signed in to change notification settings - Fork 1
/
diCrunch.php
556 lines (365 loc) · 12.6 KB
/
diCrunch.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<?PHP
/*
#####################################################################
## diCrunch - Indic language diacritic and script converter
## Copyright (C) 2006-2008 Ananda Loponen
## Online at http://wiki.gaudiyakutir.com/gkWiki:DiCrunch
## Send bug reports and inquiries to ananda[DOT]loponen[AT]gmail[DOT]com
########################################################################
The gkWiki:diCrunch engine is released under GNU General Public License. This document contains a human-readable summary of the full GPL text along with the full GPL text.
A summary of the license is also available online at http://creativecommons.org/licenses/GPL/2.0/. The full GPL text is available online at http://www.gnu.org/copyleft/gpl.html.
Please read the diCrunch_license.txt file for the full texts.
*/
include "./diCrunch/diCrunch_config.php";
include "./diCrunch/diCrunch_functions.php";
$version = "v2.0.1";
$download_size = 35;
/* Permitted file list */
$exts = implode(", ", $permitted_files);
$exts = strtoupper($exts);
/* Some preference and option variables */
$more = "none";
$checked = " checked=\"checked\"";
/* Get user preferences */
if (!empty($_COOKIE['diCrunch_config'])) {
$pref = explode("|||", $_COOKIE['diCrunch_config']);
$textarea = "";
if (!empty($pref[3])) {
$textarea .= "font-family: {$pref[3]};";
}
if (!empty($pref[11])) {
$textarea .= "font-size: {$pref[11]};";
}
if (!empty($pref[4])) {
$textarea .= "width: {$pref[4]}; ";
}
if (!empty($pref[5])) {
$textarea .= "height: {$pref[5]};";
}
}
else {
$pref[0] = "unicode";
$pref[1] = "devanagari";
$pref[2] = "";
$pref[3] = "";
$pref[4] = "";
$pref[5] = "";
$pref[6] = "";
$pref[7] = "";
$pref[8] = "";
$pref[9] = "";
$pref[10] = "";
$pref[11] = "";
$pref[12] = "";
$pref[13] = "";
$pref[14] = "";
$textarea = "";
}
if (empty($pref[0])) {
$pref[0] = "hk";
}
if (empty($pref[1])) {
$pref[1] = "unicode";
}
/* Some more preference settings for checkboxes */
$fileoutput_sel = "";
$vtob_sel = "";
$removedot_sel = "";
$swapy_sel = "";
$splitbox_sel = "";
$mstyle_sel = "";
if (!empty($_POST['fileoutput']) || (empty($_POST['convert']) && empty($_POST['fileoutput']) && $pref[6] == 1)) {
$fileoutput_sel = $checked;
}
if (!empty($_POST['vtob']) || (empty($_POST['convert']) && empty($_POST['vtob']) && $pref[7] == 1)) {
$vtob_sel = $checked;
$more = "block";
}
if (!empty($_POST['removedot']) || (empty($_POST['convert']) && empty($_POST['removedot']) && $pref[8] == 1)) {
$removedot_sel = $checked;
$more = "block";
}
if (!empty($_POST['swapy']) || (empty($_POST['convert']) && empty($_POST['swapy']) && $pref[9] == 1)) {
$swapy_sel = $checked;
$more = "block";
}
if (!empty($_POST['splitbox']) || (empty($_POST['convert']) && empty($_POST['splitbox']) && $pref[10] == 1)) {
$splitbox_sel = $checked;
//$more = "block";
}
if (!empty($_POST['mstyle']) || (empty($_POST['convert']) && empty($_POST['mstyle']) && $pref[14] == 1)) {
$mstyle_sel = $checked;
$more = "block";
}
$search_c_display = "none";
if (isset($_POST['c_search'])) {
$pref[12] = $_POST['c_search'];
}
if (isset($_POST['c_replace'])) {
$pref[13] = $_POST['c_replace'];
}
if (strlen($pref[12]) > 0) {
$search_c_display = "block";
$more = "block";
}
/* DECIDE INPUT */
//print_r($_FILES);
/* If file input */
if (!empty($_FILES['fileinput']['name'])) {
$ext = explode(".", $_FILES['fileinput']['name']);
$ext = array_pop($ext);
if (in_array($ext, $permitted_files)) {
$text = utf8_encode(file_get_contents($_FILES['fileinput']['tmp_name']));
}
else {
$text = "this file type ({$ext}) is not permitted - permitted file extensions are: ";
foreach ($permitted_files as $val) {
$text .= "{$val}";
if (next($permitted_files)) {
$text .= ", ";
}
}
$_POST['fileoutput'] = 0;
}
}
/* If form input */
elseif (!empty($_POST['source'])) {
$text = $_POST['source'];
}
/* Or else */
else {
$text = "";
$_POST['source'] = "";
}
$op = ""; // Echo output is buffered into this variable
if (empty($_POST['src'])) {
$_POST['src'] = $pref[0];
}
if (empty($_POST['tgt'])) {
$_POST['tgt'] = $pref[1];
}
include "./diCrunch/diCrunch_charsets.php";
include "./diCrunch/diCrunch_preprocess.php";
$text = stripslashes($text);
if (!empty($text)) {
$text = str_replace($ch[$_POST['src']], $ch[$_POST['tgt']], $text);
unset($intro_text);
}
else {
$_POST['source'] = $intro_text;
$text = $intro_text;
}
include "./diCrunch/diCrunch_postprocess.php";
/* Script cruncher */
$_POST['src'] = clean_for_path($_POST['src']);
$_POST['tgt'] = clean_for_path($_POST['tgt']);
if (in_array($_POST['src'], $indic_scripts) && empty($intro_text)) {
include "./diCrunch/diCrunch_{$_POST['src']}.php";
include "./diCrunch/diCrunch_indic_source.php";
$text = str_replace($ch['hk'], $ch[$_POST['tgt']], $text);
}
if (in_array($_POST['tgt'], $indic_scripts) && empty($intro_text)) {
include "./diCrunch/diCrunch_{$_POST['tgt']}.php";
include "./diCrunch/diCrunch_indic_target.php";
}
/* Grab custom preferences */
if (!empty($pref[2])) {
$stylesheet = $pref[2];
}
else {
$stylesheet = "diCrunch/diCrunch.css";
}
$op .= <<<CWS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>diCrunch {$version} - Diacritic and Indic Script Conversion</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="diCrunch is a conversion tool for converting Indic transliteration and scripts (Devanagari etc.). Convert transliteration to script, convert between transliterations, convert one script to another, or convert script to romanized transliteration." />
<link rel="stylesheet" href="{$stylesheet}" type="text/css" />
<script language="javascript" type="text/javascript">
function changeView(section) {
if (document.getElementById(section).style.display == "block") {
document.getElementById(section).style.display = "none";
}
else {
document.getElementById(section).style.display = "block";
}
return;
}
</script>
</head>
<body>
<div class="container">
CWS;
/* PREFERENCE EDITOR */
if (!empty($_GET['act']) && $_GET['act'] == "config") {
include "./diCrunch/diCrunch_preferences.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "help") {
include "./diCrunch/diCrunch_help.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "license") {
include "./diCrunch/diCrunch_license.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "changelog") {
include "./diCrunch/diCrunch_changelog.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "tools") {
include "./diCrunch/diCrunch_tools.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "macro") {
include "./diCrunch/diCrunch_macro.php";
}
if (!empty($_GET['act']) && $_GET['act'] == "feedback") {
include "./diCrunch/diCrunch_feedback.php";
}
/* DEFAULT SCREEN */
if (empty($_GET['act'])){
$op .= <<<CWS
<form name="conform" enctype="multipart/form-data" action="{$_SERVER['PHP_SELF']}" method="post">
<div class="wrapper">
<h2>Diacritic and Indic Script Conversion · diCrunch {$version}</h2>
<div class="options">
<div style="float:right; padding-right: 10px; padding-top: 2px;">
<b>
<a href="{$_SERVER['PHP_SELF']}?act=config">Preferences</a>
·
<a href="{$_SERVER['PHP_SELF']}?act=tools">Tools</a>
·
<a href="{$_SERVER['PHP_SELF']}?act=help">Help</a>
</b>
</div>
Source: <select name="src">
CWS;
foreach ($convs as $key => $value) {
$op .= "<option value=\"$key\"";
if ($_POST['src'] == $key) {
$op .= " selected=\"selected\"";
}
$op .= ">» {$value}</option>\n";
}
$op .= <<<CWS
</select>
Target: <select name="tgt">
CWS;
foreach ($convs as $key => $value) {
$op .= "<option value=\"$key\"";
if ($_POST['tgt'] == $key) {
$op .= " selected=\"selected\"";
}
$op .= ">» {$value}</option>\n";
}
$op .= <<<CWS
</select>
<input type="button" class="button" onclick="changeView('moreoptions');" value="Options" />
</div>
</div>
<div class="wrapper" id="moreoptions" style="padding-top: 0px; display: {$more};">
<div class="preferencefield" style="border-top: 0px; margin-bottom: 0px;">
<acronym title="When converting to Bengali script, if V was used in transliteration.">V to B</acronym> <input type="checkbox" name="vtob"{$vtob_sel} value="1" style="vertical-align: middle;" />
<b>·</b>
<acronym title="If you used periods for breaking compound words and are converting to Indic script.">Remove period</acronym> <input type="checkbox" name="removedot"{$removedot_sel} value="1" style="vertical-align: bottom;" />
<b>·</b>
<acronym title="If you want to use .y instead of y in Bengali transliteration.">Swap Y</acronym> <input type="checkbox" name="swapy"{$swapy_sel} value="1" style="vertical-align: bottom;" />
<b>·</b>
<acronym title="Convert to ṃ instead of ṁ.">Use ṃ</acronym> <input type="checkbox" name="mstyle"{$mstyle_sel} value="1" style="vertical-align: bottom;" />
<b>·</b>
<acronym title="Remove separate input and output text areas.">Single box</acronym> <input type="checkbox" name="splitbox"{$splitbox_sel} value="1" style="vertical-align: bottom;" />
<b>·</b>
<acronym title="Custom search and replace preceding the conversion." style="cursor: pointer;" onclick="changeView('searchreplace');">Search - Replace</acronym> »
<div id="searchreplace" style="display: {$search_c_display};">
<hr />
<acronym title="Separate multiple characters by colon ;">Search » Replace</acronym> <input name="c_search" value="{$pref[12]}" size="35" /> » <input name="c_replace" value="{$pref[13]}" size="35" />
</div>
</div>
</div>
<div class="wrapper">
<div class="textareabg">
CWS;
if (empty($splitbox_sel))
{
$op .= <<<CWS
<textarea id="source" cols="60" rows="10" style="{$textarea}" name="source">{$_POST['source']}</textarea>
<br />
CWS;
if (!empty($intro_text)) $text = ""; // null lower panel on default pageload
$op .= <<<CWS
<textarea id="target" cols="60" rows="10" style="{$textarea}" name="target">{$text}</textarea>
CWS;
}
else
{
$op .= <<<CWS
<textarea id="source" cols="60" rows="10" style="{$textarea}" name="source">{$text}</textarea>
CWS;
}
$op .= <<<CWS
<br />
<input type="submit" name="convert" value="click to convert / alt+c" accesskey="c" class="button" />
·
<acronym title="Click to access options for file input and output" style="cursor: pointer;" onclick="changeView('fileoptions');">File options</acronym>
</div>
</div>
CWS;
if (!empty($fileoutput_sel)) {
$fileoutput_display = "block";
}
else {
$fileoutput_display = "none";
}
$op .= <<<CWS
<div class="wrapper" id="fileoptions" style="padding-top: 0px; margin-top: -6px; display: {$fileoutput_display};">
<div class="options">
<acronym title="Input from a text file ({$exts})">Input from file</acronym> <input name="fileinput" type="file" size="30" />
<b> · </b>
<acronym title="You'll be prompted to download the file in TXT format.">Output to file</acronym> <input type="checkbox" name="fileoutput"{$fileoutput_sel} value="1" style="" />
</div>
</div>
</form>
CWS;
}
$y = date("Y");
$op .= <<<CWS
<!-- You may not remove this footer with copyright notice from the code. Thank you. -->
<div class="copyright">[
diCrunch {$version} © 2006-{$y} <a href="http://www.codesatori.com/" target="_blank">CodeSatori</a>
<b> · </b>
Download <a href="http://www.codewallah.com/diCrunch/diCrunch.zip">diCrunch.zip</a> ({$download_size} KB)
<b> · </b>
A <a href="http://www.granthamandira.com/" target="_blank">Grantha Mandira Resource</a>
<b> · </b>
<a href="http://www.wiccle.com/" target="_blank">Wiccle CMS Software</a> with Indic script support
]
</div>
</div>
</body>
</html>
CWS;
/* If output as a file */
if (!empty($_POST['fileoutput']) && !empty($_POST['convert'])) {
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=diCrunch_" . time() . "_{$_POST['src']}-{$_POST['tgt']}.txt");
echo $text;
exit;
}
/* The same for macros */
if (!empty($_POST['fileoutput']) && !empty($_POST['domacro'])) {
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=diCrunch_{$_POST['src']}_{$_POST['tgt']}.txt");
echo "{$installing}\n";
echo html_entity_decode(strip_tags($templates[$_POST['program']]['help'])) . "\n\n\n----------\n\n\n";
echo $macro;
exit;
}
/* Otherwise, regular output */
else {
echo $op; // Blurt out the output buffer
}
?>