forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
insert_word_wellknown.php
155 lines (143 loc) · 4.17 KB
/
insert_word_wellknown.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
<?php
/**
* \file
* \brief Ignore single word (new term with status 99)
*
* Call: insert_word_wellknown.php?tid=[textid]&ord=[textpos]
*
* PHP version 8.1
*
* @category Helper_Frame
* @package Lwt
* @author LWT Project <[email protected]>
* @since 1.0.3
*/
require_once 'inc/session_utility.php';
/**
* Return the word at a specific position in a text.
*
* @param string $textid ID of the text
* @param string $textpos Position of the word in the text.
*
* @return string A word
*
* @global string $tbpref
*/
function get_word($textid, $textpos): string
{
global $tbpref;
$word = (string)get_first_value(
"SELECT Ti2Text AS value
FROM " . $tbpref . "textitems2
WHERE Ti2WordCount = 1 AND Ti2TxID = " . $textid . " AND Ti2Order = " . $textpos
);
return $word;
}
/**
* Edit the database to add the word.
*
* @param string $textif ID of the text
* @param string $word Word to add
*
* @return int Word ID
*
* @global string $tbpref
*/
function insert_word_wellknown_to_database($textid, $word)
{
global $tbpref;
$wordlc = mb_strtolower($word, 'UTF-8');
$langid = get_first_value(
"SELECT TxLgID AS value
FROM " . $tbpref . "texts
WHERE TxID = " . $textid
);
runsql(
'INSERT INTO ' . $tbpref . 'words (
WoLgID, WoText, WoTextLC, WoStatus, WoWordCount, WoStatusChanged,' . make_score_random_insert_update('iv') . '
) values( ' .
$langid . ', ' .
convert_string_to_sqlsyntax($word) . ', ' .
convert_string_to_sqlsyntax($wordlc) . ', 99, 1, NOW(), ' .
make_score_random_insert_update('id') . '
)',
'Term added'
);
$wid = get_last_key();
do_mysqli_query(
"UPDATE " . $tbpref . "textitems2
SET Ti2WoID = " . $wid . "
WHERE Ti2LgID = " . $langid . " AND lower(Ti2Text) = " . convert_string_to_sqlsyntax($wordlc)
);
return $wid;
}
/**
* Make the well-known word as no longer marked.
*
* @param string $word New well-known word
* @param string|int $wid New well-known word ID
* @param string $hex Hexadecimal version of the lowercase word.
* @param string|int $textid ID of the text.
*
* @global string $tbpref
*
* @return void
*/
function insert_word_wellknown_javascript($word, $wid, $hex, $textid)
{
?>
<script type="text/javascript">
//<![CDATA[
var context = window.parent.document.getElementById('frame-l');
var contexth = window.parent.document.getElementById('frame-h');
var title = make_tooltip(<?php echo prepare_textdata_js($word); ?>,'*','','99');
$('.TERM<?php echo $hex; ?>', context)
.removeClass('status0')
.addClass('status99 word<?php echo $wid; ?>')
.attr('data_status','99')
.attr('data_wid','<?php echo $wid; ?>')
.attr('title',title);
$('#learnstatus', contexth).html('<?php echo addslashes(todo_words_content((int) $textid)); ?>');
cleanupRightFrames();
//]]>
</script>
<?php
}
/**
* Echoes a complete HTML page, with JavaScript content.
*
* @param string $word New well-known word
* @param string|int $wid New well-known word ID
* @param string $hex Hexadecimal version of the lowercase word.
* @param string|int $textid ID of the text.
*
* @return void
*/
function show_page_insert_word_wellknown($word, $wid, $hex, $textid)
{
pagestart("Term: " . $word, false);
echo "<p>OK, you know this term well!</p>";
insert_word_wellknown_javascript($word, $wid, $hex, $textid);
pageend();
}
/**
* Main function to insert a new word with display and JS action.
*
* @param string $textid ID of the text
* @param string $textpos Position of the word in the text.
*
* @return void
*
* @since 2.0.4-fork
*/
function do_insert_word_wellknown($textid, $textpos)
{
$word = get_word($textid, $textpos);
$wid = insert_word_wellknown_to_database($textid, $word);
$hex = strToClassName(mb_strtolower($word, 'UTF-8'));
show_page_insert_word_wellknown($word, $wid, $hex, $textid);
}
if (getreq('tid') != '' && getreq('ord') != '') {
do_insert_word_wellknown(getreq('tid'), getreq('ord'));
}
?>