forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
check_text.php
122 lines (112 loc) · 3.57 KB
/
check_text.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
<?php
/**
* \file
* \brief Check (parse & split) a Text (into sentences/words)
*
* Call: check_text.php?...
* op=Check ... do the check
*
* PHP version 8.1
*
* @category User_Interface
* @package Lwt
* @author LWT Project <[email protected]>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/php/files/check-text.html
* @since 1.0.3
*/
namespace Lwt\Interface\Check_Text;
require_once 'inc/session_utility.php';
/**
* Do the check text operation.
*
* @param string $text Text to check.
* @param int $lgid Language ID.
*
* @return void
*/
function do_operation($text, $lgid)
{
echo '<p><input type="button" value="<< Back" onclick="history.back();" /></p>';
if (strlen(prepare_textdata($text)) > 65000) {
echo "<p>Error: Text too long, must be below 65000 Bytes.</p>";
} else {
splitCheckText($text, $lgid, -1);
}
echo '<p><input type="button" value="<< Back" onclick="history.back();" /></p>';
}
/**
* Display the main form for the check text page.
*
* @global string $tbpref
*
* @return void
*/
function display_form()
{
global $tbpref;
$sql = "SELECT LgID, LgGoogleTranslateURI FROM {$tbpref}languages
WHERE LgGoogleTranslateURI<>''";
$res = do_mysqli_query($sql);
$return = array();
while ($lg_record = mysqli_fetch_assoc($res)) {
$url = $lg_record["LgGoogleTranslateURI"];
$return[$lg_record["LgID"]] = langFromDict($url);
}
$languages_option = get_languages_selectoptions(
getSetting('currentlanguage'),
'[Choose...]'
);
?>
<script type="text/javascript" charset="utf-8">
/**
* Change the language of inputs for text and title based on selected
* language.
*
* @returns {undefined}
*/
function change_textboxes_language() {
const lid = document.getElementById("TxLgID").value;
const language_data = <?php echo json_encode($return); ?>;
$('#TxTitle').attr('lang', language_data[lid]);
$('#TxText').attr('lang', language_data[lid]);
}
$(document).ready(lwtFormCheck.askBeforeExit);
$(document).ready(change_textboxes_language);
</script>
<form class="validate" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table class="tab3" cellspacing="0" cellpadding="5">
<tr>
<td class="td1 right">Language:</td>
<td class="td1">
<select name="TxLgID" id="TxLgID" class="notempty setfocus" onchange="change_textboxes_language();">
<?php echo $languages_option;?>
</select>
<img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right">Text:<br /><br />(max.<br />65,000<br />bytes)</td>
<td class="td1">
<textarea name="TxText" id="TxText" class="notempty checkbytes checkoutsidebmp" data_maxlength="65000" data_info="Text" cols="60" rows="20"></textarea>
<img src="icn/status-busy.png" title="Field must not be empty" alt="Field must not be empty" />
</td>
</tr>
<tr>
<td class="td1 right" colspan="2">
<input type="button" value="<< Back" onclick="location.href='index.php';" />
<input type="submit" name="op" value="Check" />
</td>
</tr>
</table>
</form>
<?php
}
pagestart('Check a Text', true);
if (isset($_REQUEST['op'])) {
do_operation((string)$_REQUEST['TxText'], (int)$_REQUEST['TxLgID']);
} else {
display_form();
}
pageend();
?>