Skip to content

Commit b56d956

Browse files
committed
Forgot to stage in last commit.
Preparing sounds for tests. Minor: do_te*t.php was rendering oddly with small texts. Moved the "custom" theme, because a new minifier is coming for themes.
1 parent a9d7982 commit b56d956

12 files changed

Lines changed: 203 additions & 94 deletions

File tree

‎do_test.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function do_test_desktop_page($property)
212212
<noframes><body><p>Sorry - your browser does not support frames.</p></body></noframes>
213213
</frameset>-->
214214

215-
<div style="width: 95%;" onclick="setTimeout(hideRightFrames, 1000);">
215+
<div style="width: 95%; height: 100%;" onclick="setTimeout(hideRightFrames, 1000);">
216216
<div id="frame-h">
217217
<?php
218218
require_once 'do_test_header.php';

‎do_test_test.php‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -510,20 +510,25 @@ function do_test_test_javascript($count)
510510
?>
511511
<script type="text/javascript">
512512
//<![CDATA[
513-
const waitTime = <?php echo (int)getSettingWithDefault('set-test-edit-frame-waiting-time') ?>;
514-
515-
$(document).ready( function() {
516-
window.parent.frames['ru'].location.href='empty.html';
517-
if (waitTime <= 0 ) {
518-
window.parent.frames['ro'].location.href='empty.html';
513+
const waitTime = <?php
514+
echo json_encode((int)getSettingWithDefault('set-test-edit-frame-waiting-time'))
515+
?>;
519516

520-
} else {
521-
setTimeout('window.parent.frames[\'ro\'].location.href=\'empty.html\';', waitTime);
522-
}
523-
new CountUp(<?php echo time() . ', ' . $_SESSION['teststart']; ?>,
524-
'timer', <?php echo ($count ? 0 : 1); ?>);
525-
}
526-
);
517+
$(document).ready(function() {
518+
window.parent.frames['ru'].location.href='empty.html';
519+
if (waitTime <= 0) {
520+
window.parent.frames['ro'].location.href='empty.html';
521+
} else {
522+
setTimeout(
523+
'window.parent.frames["ro"].location.href="empty.html";',
524+
waitTime
525+
);
526+
}
527+
new CountUp(
528+
<?php echo time() . ', ' . $_SESSION['teststart']; ?>,
529+
'timer', <?php echo ($count ? 0 : 1); ?>
530+
);
531+
});
527532
//]]>
528533
</script>
529534
<?php

‎do_text.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function do_text_desktop_content($audio) {
177177
</frameset>
178178
<noframes><body><p>Sorry - your browser does not support frames.</p></body></noframes>
179179
</frameset>-->
180-
<div style="width: 95%;" onclick="setTimeout(hideRightFrames, 1000);">
180+
<div style="width: 95%; height: 100%;" onclick="setTimeout(hideRightFrames, 1000);">
181181
<div id="frame-h">
182182
<?php do_text_header_content($_REQUEST['start'], true); ?>
183183
</div>

‎js/jq_pgm.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/pgm.js‎

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎set_test_status.php‎

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,63 @@
1616

1717
require_once 'inc/session_utility.php';
1818

19-
$status = (int)getreq('status');
20-
$wid = (int)getreq('wid');
21-
22-
$oldstatus = (int)get_first_value(
23-
"SELECT WoStatus AS value FROM " . $tbpref . "words
24-
WHERE WoID = " . $wid
25-
);
26-
27-
$oldscore = (int)get_first_value(
28-
'SELECT greatest(0,round(WoTodayScore,0)) AS value FROM ' . $tbpref . 'words
29-
WHERE WoID = ' . $wid
30-
);
31-
32-
if (getreq('stchange') != '') {
33-
$stchange = $status - $oldstatus;
34-
if ($stchange <= 0) {
35-
$stchange=-1;
36-
}
37-
if ($stchange > 0) {
38-
$stchange=1;
39-
}
40-
41-
} else {
42-
$stchange = (int)getreq('stchange');
43-
$status = $oldstatus + $stchange;
44-
if ($status < 1) {
45-
$status=1;
19+
20+
function start_set_text_status()
21+
{
22+
global $tbpref;
23+
24+
if (!is_numeric(getreq('status')) && !is_numeric(getreq('stchange'))) {
25+
my_die('status or stchange should be specified!');
4626
}
47-
if ($status > 5) {
48-
$status=5;
27+
28+
$wid = (int)getreq('wid');
29+
$oldstatus = (int)get_first_value(
30+
"SELECT WoStatus AS value FROM " . $tbpref . "words
31+
WHERE WoID = " . $wid
32+
);
33+
34+
if (!is_numeric(getreq('stchange'))) {
35+
$status = (int)getreq('status');
36+
$stchange = $status - $oldstatus;
37+
if ($stchange <= 0) {
38+
$stchange=-1;
39+
}
40+
if ($stchange > 0) {
41+
$stchange=1;
42+
}
43+
44+
} else {
45+
$stchange = (int)getreq('stchange');
46+
$status = $oldstatus + $stchange;
47+
if ($status < 1) {
48+
$status=1;
49+
}
50+
if ($status > 5) {
51+
$status=5;
52+
}
53+
4954
}
50-
55+
do_set_test_status_content($wid, $status, $oldstatus, $stchange);
5156
}
5257

53-
$word = get_first_value(
54-
"SELECT WoText AS value FROM " . $tbpref . "words
55-
WHERE WoID = " . $wid
56-
);
57-
pagestart("Term: " . $word, false);
58-
59-
runsql(
60-
'UPDATE ' . $tbpref . 'words SET WoStatus = ' .
61-
$status . ', WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . '
62-
WHERE WoID = ' . $wid,
63-
'Status changed'
64-
);
65-
66-
$newscore = (int)get_first_value(
67-
'SELECT greatest(0,round(WoTodayScore,0)) AS value
68-
FROM ' . $tbpref . 'words where WoID = ' . $wid
69-
);
70-
7158
function do_set_test_status_html($status, $oldstatus, $newscore, $oldscore)
7259
{
7360
if ($oldstatus == $status) {
7461
echo '<p>Status ' . get_colored_status_msg($status) . ' not changed.</p>';
7562
} else {
76-
echo '<p>Status changed from ' . get_colored_status_msg($oldstatus) . ' to ' . get_colored_status_msg($status) . '.</p>';
63+
echo '<p>
64+
Status changed from ' . get_colored_status_msg($oldstatus) .
65+
' to ' . get_colored_status_msg($status) . '
66+
.</p>';
67+
echo '<audio autoplay>
68+
<source src="themes/Lingocracy_Dark/' . (
69+
($status > $oldstatus) ? "success.mp3" : "failure.mp3"
70+
) . '" type="audio/mpeg" />
71+
Your browser does not support audio element!
72+
</audio>';
7773
}
7874

79-
echo "<p>Old score was " . $oldscore . ", new score is now " . $newscore . ".</p>";
75+
echo "<p>Old score was $oldscore, new score is now $newscore.</p>";
8076
}
8177

8278
function set_test_status_change_progress($stchange)
@@ -122,9 +118,39 @@ function do_set_test_status_javascript($wid, $status, $stchange)
122118
<?php
123119
}
124120

125-
do_set_test_status_html($status, $oldstatus, $newscore, $oldscore);
126-
set_test_status_change_progress($stchange);
127-
do_set_test_status_javascript($wid, $status, $stchange);
128-
pageend();
121+
122+
function do_set_test_status_content($wid, $status, $oldstatus, $stchange)
123+
{
124+
global $tbpref;
125+
$word = get_first_value(
126+
"SELECT WoText AS value FROM " . $tbpref . "words
127+
WHERE WoID = " . $wid
128+
);
129+
130+
$oldscore = (int)get_first_value(
131+
'SELECT greatest(0,round(WoTodayScore,0)) AS value FROM ' . $tbpref . 'words
132+
WHERE WoID = ' . $wid
133+
);
134+
135+
136+
runsql(
137+
'UPDATE ' . $tbpref . 'words SET WoStatus = ' .
138+
$status . ', WoStatusChanged = NOW(),' . make_score_random_insert_update('u') . '
139+
WHERE WoID = ' . $wid,
140+
'Status changed'
141+
);
142+
143+
$newscore = (int)get_first_value(
144+
'SELECT greatest(0,round(WoTodayScore,0)) AS value
145+
FROM ' . $tbpref . 'words where WoID = ' . $wid
146+
);
147+
pagestart("Term: " . $word, false);
148+
do_set_test_status_html($status, $oldstatus, $newscore, $oldscore);
149+
set_test_status_change_progress($stchange);
150+
do_set_test_status_javascript($wid, $status, $stchange);
151+
pageend();
152+
}
153+
154+
start_set_text_status();
129155

130156
?>

‎src/js/jq_pgm.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ function setTheFocus () {
313313
$('.setfocus').focus().select();
314314
}
315315

316+
/**
317+
* Prepare a dialog when the user clicks a word during a test.
318+
*
319+
* @returns false
320+
*/
316321
function word_click_event_do_test_test () {
317322
run_overlib_test(
318323
WBLINK1, WBLINK2, WBLINK3,
@@ -328,6 +333,12 @@ function word_click_event_do_test_test () {
328333
return false;
329334
}
330335

336+
/**
337+
* Handle keyboard interaction when testing a word.
338+
*
339+
* @param {object} e A keystroke object
340+
* @returns {bool} true if nothing was done, false otherwise
341+
*/
331342
function keydown_event_do_test_test (e) {
332343
if (e.which == 32 && OPENED == 0) { // space : show sol.
333344
$('.word').click();

‎src/js/pgm.js‎

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,25 @@ function run_overlib_multiword (wblink1, wblink2, wblink3, hints, txid, torder,
181181
);
182182
}
183183

184-
function run_overlib_test (wblink1, wblink2, wblink3, wid, txt, trans, roman, stat, sent, todo, oldstat) {
184+
/**
185+
* Make an overlib dialog so that the user can say if he knows the word or not.
186+
*
187+
* @param {string} wblink1 Dictionary 1 URI
188+
* @param {string} wblink2 Dictionary 2 URI
189+
* @param {string} wblink3 Google Translate URI
190+
* @param {*} wid Word ID
191+
* @param {string} txt Word text
192+
* @param {string} trans Word translation
193+
* @param {string} roman Word romanization
194+
* @param {string} stat Word learning status
195+
* @param {string} sent Lookup sentence in Google Translate
196+
* @param {int} todo If 1, the user should say if he knows the word.
197+
* @param {*} oldstat
198+
* @returns
199+
*/
200+
function run_overlib_test(
201+
wblink1, wblink2, wblink3, wid, txt, trans, roman, stat, sent, todo, oldstat
202+
) {
185203
const s = parseInt(stat, 10);
186204
let c = s + 1;
187205
if (c > 5) c = 5;
@@ -191,12 +209,11 @@ function run_overlib_test (wblink1, wblink2, wblink3, wid, txt, trans, roman, st
191209
if (c == s) cc = c;
192210
let ww = stat + ' ▶ ' + w;
193211
if (w == s) ww = w;
194-
return overlib(
195-
(
196-
todo == 1
197-
? '<center><hr noshade size=1 /><b>' +
198-
((stat >= 1 && stat <= 5)
199-
? (
212+
let overlib_string = '';
213+
if (todo == 1) {
214+
overlib_string += '<center><hr noshade size=1 /><b>';
215+
if (stat >= 1 && stat <= 5) {
216+
overlib_string +=
200217
make_overlib_link_change_status_test(
201218
wid,
202219
1,
@@ -208,23 +225,22 @@ function run_overlib_test (wblink1, wblink2, wblink3, wid, txt, trans, roman, st
208225
-1,
209226
'<img src="icn/thumb.png" title="Oops!" alt="Oops!" /> Oops! [' + ww + ']'
210227
) +
211-
'<hr noshade size=1 />'
212-
)
213-
: '') +
228+
'<hr noshade size=1 />';
229+
}
230+
overlib_string +=
214231
make_overlib_link_change_status_alltest(wid, stat) +
215-
'</b></center><hr noshade size=1 />'
216-
: '') +
217-
'<b>' + escape_html_chars(make_tooltip(txt, trans, roman, stat)) +
218-
'</b><br />' +
219-
' <a href="edit_tword.php?wid=' + wid +
220-
'" onclick="showRightFrames();">Edit term</a><br />' +
221-
createTheDictLink(wblink1, txt, 'Dict1', 'Lookup Term: ') +
222-
createTheDictLink(wblink2, txt, 'Dict2', '') +
223-
createTheDictLink(wblink3, txt, 'GTr', '') +
224-
createTheDictLink(wblink3, sent, 'GTr', '<br />Lookup Sentence:'),
225-
CAPTION,
226-
'Got it?'
227-
);
232+
'</b></center><hr noshade size=1 />';
233+
}
234+
overlib_string += '<b>' + escape_html_chars(make_tooltip(txt, trans, roman, stat)) +
235+
'</b><br />' +
236+
' <a href="edit_tword.php?wid=' + wid +
237+
'" onclick="showRightFrames();">Edit term</a><br />' +
238+
createTheDictLink(wblink1, txt, 'Dict1', 'Lookup Term: ') +
239+
createTheDictLink(wblink2, txt, 'Dict2', '') +
240+
createTheDictLink(wblink3, txt, 'GTr', '') +
241+
createTheDictLink(wblink3, sent, 'GTr', '<br />Lookup Sentence:');
242+
243+
return overlib(overlib_string, CAPTION, 'Got it?');
228244
}
229245

230246
/**

‎src/php/minifier.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ function minifyAllCSS()
109109
}
110110
}
111111

112+
/**
113+
* Regenerate all themes. CSS is minified while other files are copied.
114+
*
115+
* Nested folders are ignored.
116+
*
117+
* @return void
118+
*/
119+
function regenerate_themes()
120+
{
121+
$folder = 'src/themes/';
122+
$folder_scan = scandir($folder);
123+
foreach ($folder_scan as $parent_file) {
124+
if (is_dir($folder . $parent_file) && $parent_file != '.') {
125+
$file_scan = scandir($folder . $parent_file);
126+
foreach ($file_scan as $file) {
127+
if (!is_dir($file)) {
128+
$filepath = $folder . $parent_file . '/' . $file;
129+
$outputpath = 'themes/{$parent_file}/{$file}';
130+
if (str_ends_with($filepath, '.css')) {
131+
minifyCSS($filepath, $outputpath);
132+
} else {
133+
copy($filepath, $outputpath);
134+
}
135+
}
136+
}
137+
}
138+
}
139+
}
140+
112141
/**
113142
* @var array<string> All the paths of JS files to be minified
114143
*/

‎src/themes/Night_Mode/failure.mp3‎

252 KB
Binary file not shown.

0 commit comments

Comments
 (0)