forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
set_text_mode.php
174 lines (156 loc) · 5.82 KB
/
set_text_mode.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
<?php
/**
* \file
* \brief Change the text display mode
*
* Call: set_text_mode.php?text=[textid]&mode=0/1&showLeaning=0/1
*
* PHP version 8.1
*
* @category Helper_Frame
* @package Lwt
* @author LWT Project <[email protected]>
* @since 1.0.3.1
*/
require_once 'inc/session_utility.php';
/**
* Save text mode settings.
*
* @param int $showAll Whether all word should be shown
* @param int $showLearning Whether to show translation of learning words
*
* @return int If show learning were previously true (1) or false (0)
*
* @psalm-return 0|1
*/
function text_mode_save_settings($showAll, $showLearning): int
{
saveSetting('showallwords', $showAll);
$oldShowLearning = getSettingZeroOrOne('showlearningtranslations', 1);
saveSetting('showlearningtranslations', $showLearning);
return $oldShowLearning;
}
/**
* Do the JavaScript action to change the display of translations.
*
* @param int $showLearning Whether to show translation of learning words
* @param int $oldShowLearning If show learning was previously true (1) or false (0)
*
* @return void
*/
function text_annotations_mode_javascript($showLearning, $oldShowLearning)
{
?>
<script type="text/javascript">
//<![CDATA[
/** @var {boolean} showLearningChanged hide all translations status has changed */
const showLearningChanged = <?php echo json_encode($showLearning != $oldShowLearning); ?>; // 0 (jquery) or 1 (reload)
const showLearning = <?php echo json_encode($showLearning) ?>;
/**
* Hide translations for words being learned. Doesn't work.
*
* @param {object} context Window containing words
*/
function hideAnnotations(context) {
$('.mword',context)
.removeClass('wsty')
.addClass('mwsty')
.each(function(){
const c = ' ' + $(this).attr('data_code') + ' ';
$(this).html(c);
});
$('span',context).not('#totalcharcount').removeClass('hide');
}
/**
* Hide translations for all words. Doesn't work.
*
* @param {object} context Window containing words
*/
function showAnnotations(context) {
$('.mword',context)
.removeClass('mwsty')
.addClass('wsty')
.each(function(){
const c = $(this).attr('data_text');
$(this).text(c);
if($(this).not('.hide').length){
let u = parseInt($(this).attr('data_code')) *2 + parseInt($(this).attr('data_order')) -1;
$(this).nextUntil('[id^="ID-' + u + '-"]',context).addClass('hide');
}
});
}
/* Doesn't work
if (showLearningChanged) {
window.parent.location.reload(true);
} else {
const context = window.parent.document.getElementById('frame-l');
if (showLearning) {
showAnnotations(context);
} else {
hideAnnotations(context);
}
}
*/
$('#waiting').html('<b>OK -- </b>');
//]]>
</script>
<?php
}
/**
* Do the main page content when chaning display of translations.
*
* @param int $showAll Whether all word should be shown
* @param int $showLearning Whether to show translation of learning words
* @param int $oldShowLearning If show learning was previously true (1) or false (0)
*
* @return void
*/
function text_mode_page_content($showAll, $showLearning, $oldShowLearning)
{
pagestart("Text Display Mode changed", false);
echo '<p><span id="waiting"><img src="' .
get_file_path('icn/waiting.gif') .
'" alt="Please wait" title="Please wait" /> Please wait ...</span>';
flush();
text_annotations_mode_javascript($showLearning, $oldShowLearning);
if ($showAll == 1) {
echo '<b><i>Show All</i></b> is set to <b>ON</b>.
<br /><br />ALL terms are now shown, and all multi-word terms are shown as superscripts before the first word. The superscript indicates the number of words in the multi-word term.
<br /><br />To concentrate more on the multi-word terms and to display them without superscript, set <i>Show All</i> to OFF.</p>';
} else {
echo '<b><i>Show All</i></b> is set to <b>OFF</b>.
<br /><br />Multi-word terms now hide single words and shorter or overlapping multi-word terms. The creation and deletion of multi-word terms can be a bit slow in long texts.
<br /><br />To manipulate ALL terms, set <i>Show All</i> to ON.</p>';
}
echo "<br /><br />";
if ($showLearning == 1) {
echo '<b><i>Learning Translations</i></b> is set to <b>ON</b>.
<br /><br />Terms that have Learning Level 1 will show their translations beneath the term in the reading mode.
<br /><br />To hide the translations, set <i>Learning Translations</i> to OFF.</p>';
} else {
echo '<b><i>Learning Translations</i></b> is set to <b>OFF</b>.
<br /><br />No translations will be shown directly in the reading window.
<br /><br />To see translations for terms with Learning Level 1 underneath the terms in the reading window, set <i>Learning Translations</i> to ON.</p>';
}
pageend();
}
/**
* Complete workflow for changing text mode.
* It edits the settings in the database, show the success message
* and do JavaScript action to change its display.
*
* @param int $textid ID of the current text
* @param int $showAll Whether all word should be shown
* @param int $showLearning Whether to show translation of learning words
*
* @return void
*/
function change_text_mode($textid, $showAll, $showLearning)
{
$oldShowLearning = text_mode_save_settings($showAll, $showLearning);
text_mode_page_content($showAll, $showLearning, $oldShowLearning);
}
if (getreq('text') != '') {
change_text_mode((int)getreq('text'), (int)getreq('mode'), (int)getreq('showLearning'));
}
?>