forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
do_text_text.php
860 lines (801 loc) · 25.7 KB
/
do_text_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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
<?php
/**
* \file
* \brief Show text header frame
*
* Call: do_text_text.php?text=[textid]
*
* PHP version 8.1
*
* @package Lwt
* @author LWT Project <[email protected]>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/php/files/do-text-text.html
* @since 1.0.3
*/
require_once 'inc/session_utility.php';
/**
* Get the record for this text in the database.
*
* @param string|int $textid ID of the text
*
* @return array{TxLgID: int, TxTitle: string, TxAnnotatedText: string,
* TxPosition: int}|false|null Record corresponding to this text.
*
* @global string $tbpref Table name prefix
*
* @psalm-return array<string, float|int|null|string>|false|null
*/
function get_text_data($textid)
{
global $tbpref;
$sql =
'SELECT TxLgID, TxTitle, TxAnnotatedText, TxPosition
FROM ' . $tbpref . 'texts
WHERE TxID = ' . $textid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
mysqli_free_result($res);
return $record;
}
/**
* Get the record for this text in the database.
*
* @param string $textid ID of the text
*
* @return array{TxLgID: int, TxTitle: string, TxAnnotatedText: string,
* TxPosition: int}|false|null Record corresponding to this text.
*
* @global string $tbpref Table name prefix
*
* @deprecated Use get_text_data instead.
*
* @psalm-return array<string, float|int|null|string>|false|null
*/
function getTextData($textid)
{
return get_text_data($textid);
}
/**
* Return the settings relative to this language.
*
* @param int $langid Language ID as defined in the database.
*
* @return array{LgName: string, LgDict1URI: string,
* LgDict2URI: string, LgGoogleTranslateURI: string, LgTextSize: int,
* LgRegexpWordCharacters: string, LgRemoveSpaces: int,
* LgRightToLeft: int, Lg}|false|null Record corresponding to this language.
*
* @global string $tbpref Table name prefix
*
* @psalm-return array<string, float|int|null|string>|false|null
*/
function get_language_settings($langid)
{
global $tbpref;
$sql =
'SELECT LgName, LgDict1URI, LgDict2URI, LgGoogleTranslateURI,
LgTextSize, LgRegexpWordCharacters, LgRemoveSpaces, LgRightToLeft
FROM ' . $tbpref . 'languages
WHERE LgID = ' . $langid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
mysqli_free_result($res);
return $record;
}
/**
* Return the settings relative to this language.
*
* @param int $langid Language ID as defined in the database.
*
* @return array{LgName: string, LgDict1URI: string,
* LgDict2URI: string, LgGoogleTranslateURI: string, LgTextSize: int,
* LgRemoveSpaces: int, LgRightToLeft: int}|false|null Record corresponding to this language.
*
* @global string $tbpref Table name prefix
*
* @deprecated Use get_language_settings instead.
*
* @psalm-return array<string, float|int|null|string>|false|null
*/
function getLanguagesSettings($langid)
{
return get_language_settings($langid);
}
/**
* Print the output when the word is a term (word or multi-word).
*
* @param int $actcode Action code, number of words forming
* the term (> 1 for multiword)
* @param int $showAll Show all words or not
* @param int $hideuntil Unused
* @param string $spanid ID for this span element
* @param int $currcharcount Current number of characters
* @param array<string, string> $record Various data
* @param array $exprs Current expressions
*
* @return void
*
* @since 2.8.0-fork Takes a new argument $exprs
*/
function echo_term(
$actcode,
$showAll,
$spanid,
$hidetag,
$currcharcount,
$record,
&$exprs = array()
) {
$actcode = (int)$record['Code'];
if ($actcode > 1) {
// A multiword, $actcode is the number of words composing it
if (empty($exprs) || $exprs[sizeof($exprs) - 1][1] != $record['TiText']) {
$exprs[] = array($actcode, $record['TiText'], $actcode);
}
if (isset($record['WoID'])) {
$attributes = array(
'id' => $spanid,
'class' => implode(
" ",
[
$hidetag, "click", "mword", ($showAll ? 'mwsty' : 'wsty'),
"order" . $record['Ti2Order'],
'word' . $record['WoID'], 'status' . $record['WoStatus'],
'TERM' . strToClassName($record['TiTextLC'])]
),
'data_pos' => $currcharcount,
'data_order' => $record['Ti2Order'],
'data_wid' => $record['WoID'],
'data_trans' => tohtml(
repl_tab_nl($record['WoTranslation']) .
getWordTagList($record['WoID'], ' ', 1, 0)
),
'data_rom' => tohtml($record['WoRomanization']),
'data_status' => $record['WoStatus'],
'data_code' => $actcode,
'data_text' => tohtml($record['TiText'])
);
$span = '<span';
foreach ($attributes as $attr_name => $val) {
$span .= ' ' . $attr_name . '="' . $val . '"';
}
$span .= '>';
if ($showAll) {
$span .= $actcode;
} else {
$span .= tohtml($record['TiText']);
}
$span .= '</span>';
echo $span;
}
} else {
// Single word
if (isset($record['WoID'])) {
// Word found status 1-5|98|99
$attributes = array(
'id' => $spanid,
'class' => implode(
" ",
[
$hidetag, "click", "word", "wsty", "word" . $record['WoID'],
'status' . $record['WoStatus'],
'TERM' . strToClassName($record['TiTextLC'])
]
),
'data_pos' => $currcharcount,
'data_order' => $record['Ti2Order'],
'data_wid' => $record['WoID'],
'data_trans' => tohtml(
repl_tab_nl($record['WoTranslation']) .
getWordTagList($record['WoID'], ' ', 1, 0)
),
'data_rom' => tohtml($record['WoRomanization']),
'data_status' => $record['WoStatus']
);
} else {
// Not registered word (status 0)
$attributes = array(
'id' => $spanid,
'class' => implode(
" ",
[
$hidetag, "click", "word", "wsty", "status0",
"TERM" . strToClassName($record['TiTextLC'])
]
),
'data_pos' => $currcharcount,
'data_order' => $record['Ti2Order'],
'data_trans' => '',
'data_rom' => '',
'data_status' => '0',
'data_wid' => ''
);
}
foreach ($exprs as $expr) {
$attributes['data_mw' . $expr[0]] = tohtml($expr[1]);
}
$span = '<span';
foreach ($attributes as $attr_name => $val) {
$span .= ' ' . $attr_name . '="' . $val . '"';
}
$span .= '>' . tohtml($record['TiText']) . '</span>';
echo $span;
for ($i = sizeof($exprs) - 1; $i >= 0; $i--) {
$exprs[$i][2]--;
if ($exprs[$i][2] < 1) {
unset($exprs[$i]);
$exprs = array_values($exprs);
}
}
}
}
/**
* Print the output when the word is a term.
*
* @param int $actcode Action code, > 1 for multiword
* @param int $showAll Show all words or not
* @param int $hideuntil Unused
* @param string $spanid ID for this span element
* @param int $currcharcount Current number of characters
* @param array<string, string> $record Various data
*
* @since 2.2.1 Return 0 instead of a new value for $hideuntil
*
* @deprecated Use echo_term instead.
*/
function echoTerm(
$actcode,
$showAll,
$hideuntil,
$spanid,
$hidetag,
$currcharcount,
$record
): int {
echo_term($actcode, $showAll, $spanid, $hidetag, $currcharcount, $record);
return 0;
}
/**
* Process each word (can be punction, term, etc...). Caused laggy texts, replaced by wordParser.
*
* @param string[] $record Record information
* @param 0|1 $showAll Show all words or not
* @param int $currcharcount Current number of caracters
*
* @return int New number of caracters
*
* @deprecated Use sentenceParser and wordParser instead.
*/
function wordProcessor($record, $showAll, $currcharcount): int
{
$cnt = 1;
$sid = 0;
if ($sid != (int) $record['Ti2SeID']) {
$sid = $record['Ti2SeID'];
echo '<span id="sent_', $sid, '">';
}
$actcode = (int)$record['Code'];
$spanid = 'ID-' . $record['Ti2Order'] . '-' . $actcode;
// Check if work should be hidden
$hidetag = '';
if ($cnt < $record['Ti2Order']) {
echo '<span id="ID-' . $cnt++ . '-1"></span>';
}
// The current word is not a term
if ($record['TiIsNotWord'] != 0) {
echo '<span id="' . $spanid . '" class="' . $hidetag . '">' .
str_replace("¶", '<br />', tohtml($record['TiText'])) .
'</span>';
} else {
echo_term(
$actcode,
$showAll,
$spanid,
$hidetag,
$currcharcount,
$record
);
}
if ($actcode == 1) {
$currcharcount += (int)$record['TiTextLength'];
}
return $currcharcount;
}
/**
* Check if a new sentence SPAN should be started.
*
* @param int $sid Sentence ID
* @param int $old_sid Old sentence ID
*
* @return int Sentence ID
*/
function sentence_parser($sid, $old_sid)
{
if ($sid == $old_sid) {
return $sid;
}
if ($sid != 0) {
echo '</span>';
}
$sid = $old_sid;
echo '<span id="sent_', $sid, '">';
return $sid;
}
/**
* Check if a new sentence SPAN should be started.
*
* @param int $sid Sentence ID
* @param int $old_sid Old sentence ID
*
* @return int Sentence ID
*
* @deprecated Use sentence_parser instead.
*/
function sentenceParser($sid, $old_sid)
{
return sentence_parser($sid, $old_sid);
}
/**
* Process each text item (can be punction, term, etc...)
*
* @param array $record Text item information
* @param 0|1 $showAll Show all words or not
* @param int $currcharcount Current number of caracters
* @param bool $hide Should some item be hidden, depends on $showAll
* @param array $exprs Current expressions
*
* @return void
*
* @since 2.5.0-fork
* @since 2.8.0-fork Take a new optional arguent $exprs
*/
function item_parser(
$record,
$showAll,
$currcharcount,
$hide,
&$exprs = array()
): void {
$actcode = (int)$record['Code'];
$spanid = 'ID-' . $record['Ti2Order'] . '-' . $actcode;
// Check if item should be hidden
$hidetag = $hide ? ' hide' : '';
if ($record['TiIsNotWord'] != 0) {
// The current item is not a term (likely punctuation)
echo "<span id=\"$spanid\" class=\"$hidetag\">" .
str_replace("¶", '<br />', tohtml($record['TiText'])) . '</span>';
} else {
// A term (word or multi-word)
echo_term(
$actcode,
$showAll,
$spanid,
$hidetag,
$currcharcount,
$record,
$exprs
);
}
}
/**
* Process each text item (can be punction, term, etc...)
*
* @param string[] $record Record information
* @param 0|1 $showAll Show all words or not
* @param int $currcharcount Current number of caracters
* @param int $hideuntil Should the value be hidden or not
*
* @return int New value for $hideuntil
*
* @deprecated Use item_parser instead (since 2.5.0-fork).
*/
function word_parser($record, $showAll, $currcharcount, $hideuntil): int
{
$actcode = (int)$record['Code'];
$spanid = 'ID-' . $record['Ti2Order'] . '-' . $actcode;
// Check if item should be hidden
$hidetag = '';
if ($record['Ti2Order'] <= $hideuntil) {
if (!$showAll || ($showAll && $actcode > 1)) {
$hidetag = ' hide';
}
} else {
$hidetag = '';
$hideuntil = -1;
}
if ($record['TiIsNotWord'] != 0) {
// The current item is not a term (likely punctuation)
echo "<span id=\"$spanid\" class=\"$hidetag\">" .
str_replace("¶", '<br />', tohtml($record['TiText'])) . '</span>';
} else {
// A term (word or multi-word)
echo_term(
$actcode,
$showAll,
$spanid,
$hidetag,
$currcharcount,
$record
);
if ($hideuntil == -1) {
$hideuntil = (int)$record['Ti2Order'] + ($actcode - 1) * 2;
}
}
return $hideuntil;
}
/**
* Process each word (can be punction, term, etc...)
*
* @param string[] $record Record information
* @param 0|1 $showAll Show all words or not
* @param int $currcharcount Current number of caracters
* @param int $cnt
* @param int $sid Sentence ID
* @param int $hideuntil Should the value be hidden or not
*
* @return int New value for $hideuntil
*
* @deprecated Use word_parser instead.
*/
function wordParser($record, $showAll, $currcharcount, $hideuntil): int
{
return word_parser($record, $showAll, $currcharcount, $hideuntil);
}
/**
* Get all words and start the iterate over them.
*
* @param string $textid ID of the text
* @param 0|1 $showAll Show all words or not
*
* @return void
*
* @global string $tbpref Table name prefix
*/
function main_word_loop($textid, $showAll): void
{
global $tbpref;
$sql =
"SELECT
CASE WHEN `Ti2WordCount`>0 THEN Ti2WordCount ELSE 1 END AS Code,
CASE WHEN CHAR_LENGTH(Ti2Text)>0 THEN Ti2Text ELSE `WoText` END AS TiText,
CASE WHEN CHAR_LENGTH(Ti2Text)>0 THEN LOWER(Ti2Text) ELSE `WoTextLC` END AS TiTextLC,
Ti2Order, Ti2SeID,
CASE WHEN `Ti2WordCount`>0 THEN 0 ELSE 1 END AS TiIsNotWord,
CASE
WHEN CHAR_LENGTH(Ti2Text)>0
THEN CHAR_LENGTH(Ti2Text)
ELSE CHAR_LENGTH(`WoTextLC`)
END AS TiTextLength,
WoID, WoText, WoStatus, WoTranslation, WoRomanization
FROM {$tbpref}textitems2 LEFT JOIN {$tbpref}words ON Ti2WoID = WoID
WHERE Ti2TxID = $textid
ORDER BY Ti2Order asc, Ti2WordCount desc";
$res = do_mysqli_query($sql);
$currcharcount = 0;
$hidden_items = array();
$exprs = array();
$cnt = 1;
$sid = 0;
$last = -1;
// Loop over words and punctuation
while ($record = mysqli_fetch_assoc($res)) {
$sid = sentence_parser($sid, $record['Ti2SeID']);
if ($cnt < $record['Ti2Order']) {
echo '<span id="ID-' . $cnt++ . '-1"></span>';
}
if ($showAll) {
$hide = isset($record['WoID'])
&& array_key_exists((int) $record['WoID'], $hidden_items);
} else {
$hide = $record['Ti2Order'] <= $last;
}
item_parser($record, $showAll, $currcharcount, $hide, $exprs);
if ((int)$record['Code'] == 1) {
$currcharcount += $record['TiTextLength'];
$cnt++;
}
$last = max(
$last,
(int) $record['Ti2Order'] + ((int)$record['Code'] - 1) * 2
);
if ($showAll) {
if (isset($record['WoID'])
&& !array_key_exists((int) $record['WoID'], $hidden_items) // !$hide
) {
$hidden_items[(int) $record['WoID']] = (int) $record['Ti2Order']
+ ((int)$record['Code'] - 1) * 2;
}
// Clean the already finished items
$hidden_items = array_filter(
$hidden_items,
fn ($val) => $val >= $record['Ti2Order'],
);
}
}
mysqli_free_result($res);
echo '<span id="totalcharcount" class="hide">' . $currcharcount . '</span>';
}
/**
* Get all words and start the iterate over them.
*
* @param string $textid ID of the text
* @param 0|1 $showAll Show all words or not
*
* @return void
*
* @global string $tbpref Table name prefix
*
* @deprecated Use main_word_loop instead.
*/
function mainWordLoop($textid, $showAll): void
{
main_word_loop($textid, $showAll);
}
/**
* Prepare style for showing word status. Write a now STYLE object
*
* @param int $showLearning 1 to show learning translations
* @param int<1, 4> $mode_trans Annotation position
* @param int $textsize Text font size
* @param bool $ann_exist Does annotations exist for this text
*
* @return void
*/
function do_text_text_style($showLearning, $mode_trans, $textsize, $ann_exists): void
{
$displaystattrans = (int)getSettingWithDefault('set-display-text-frame-term-translation');
$pseudo_element = ($mode_trans < 3) ? 'after' : 'before';
$data_trans = $ann_exists ? 'data_ann' : 'data_trans';
$stat_arr = array(1, 2, 3, 4, 5, 98, 99);
$ruby = $mode_trans == 2 || $mode_trans == 4;
echo '<style>';
if ($showLearning) {
foreach ($stat_arr as $value) {
if (checkStatusRange($value, $displaystattrans)) {
echo '.wsty.status', $value, ':',
$pseudo_element, ',.tword.content', $value, ':',
$pseudo_element,'{content: attr(',$data_trans,');}';
echo '.tword.content', $value,':',
$pseudo_element,'{color:rgba(0,0,0,0)}',"\n";
}
}
}
if ($ruby) {
echo '.wsty {',
($mode_trans == 4 ? 'margin-top: 0.2em;' : 'margin-bottom: 0.2em;'),
'text-align: center;
display: inline-block;',
($mode_trans == 2 ? 'vertical-align: top;' : ''),
'}',"\n";
echo '.wsty:', $pseudo_element,
'{
display: block !important;',
($mode_trans == 2 ? 'margin-top: -0.05em;' : 'margin-bottom: -0.15em;'),
'}',"\n";
}
$ann_textsize = array(100 => 50, 150 => 50, 200 => 40, 250 => 25);
echo '.tword:', $pseudo_element,
',.wsty:', $pseudo_element,
'{',
($ruby ? 'text-align: center;' : ''),
'font-size:' . $ann_textsize[$textsize] . '%;',
($mode_trans == 1 ? 'margin-left: 0.2em;' : ''),
($mode_trans == 3 ? 'margin-right: 0.2em;' : ''),
($ann_exists ? '' : '
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: inline-block;
vertical-align: -25%;'),
'}';
echo '.hide {'.
'display:none !important;
}';
echo '.tword:',
$pseudo_element, ($ruby ? ',.word:' : ',.wsty:'),
$pseudo_element, '{max-width:15em;}';
echo '</style>';
}
/**
* Prepare style for showing word status. Write a now STYLE object
*
* @param int $showLearning 1 to show learning translations
* @param int<1, 4> $mode_trans Annotation position
* @param int $textsize Text font size
* @param bool $ann_exist Does annotations exist for this text
*
* @return void
*
* @deprecated Use do_text_text_style instead.
*/
function prepareStyle($showLearning, $mode_trans, $textsize, $ann_exists): void
{
do_text_text_style($showLearning, $mode_trans, $textsize, $ann_exists);
}
/**
* Print JavaScript-formatted content.
*
* @param array<string, mixed> Associative array of all global variables for JS
*
* @return void
*/
function do_text_text_javascript($var_array): void
{
?>
<script type="text/javascript">
//<![CDATA[
/// Map global variables as a JSON object
const new_globals = <?php echo json_encode($var_array); ?>;
// Set global variables
for (let key in new_globals) {
if (typeof new_globals[key] !== 'string') {
for (let subkey1 in new_globals[key]) {
if (typeof new_globals[key] !== 'string') {
for (let subkey2 in new_globals[key][subkey1]) {
window[key][subkey1][subkey2] = new_globals[key][subkey1][subkey2];
}
} else {
window[key][subkey1] = new_globals[key][subkey1];
}
}
} else {
window[key] = new_globals[key];
}
}
LANG = getLangFromDict(LWT_DATA.language.translator_link);
LWT_DATA.text.reading_position = -1;
// Note from 2.10.0: is the next line necessary on text?
LWT_DATA.test.answer_opened = false;
// Change the language of the current frame
if (LANG && LANG != LWT_DATA.language.translator_link) {
$("html").attr('lang', LANG);
}
if (LWT_DATA.settings.jQuery_tooltip) {
$(function () {
$('#overDiv').tooltip();
$('#thetext').tooltip_wsty_init();
});
}
/**
* Save the current reading position.
* @global {string} LWT_DATA.text.id Text ID
*
* @since 2.0.3-fork
*/
function saveCurrentPosition() {
let pos = 0;
// First position from the top
const top_pos = $(window).scrollTop() - $('.wsty').not('.hide').eq(0).height();
$('.wsty').not('.hide').each(function() {
if ($(this).offset().top >= top_pos) {
pos = $(this).attr('data_pos');
return;
}
});
saveReadingPosition(LWT_DATA.text.id, pos);
}
$(document).ready(prepareTextInteractions);
$(document).ready(goToLastPosition);
$(window).on('beforeunload', saveCurrentPosition);
//]]>
</script>
<?php
}
/**
* Print JavaScript-formatted content.
*
* @param array<string, mixed> Associative array of all global variables for JS
*
* @return void
*
* @deprecated Use do_text_text_javascript instead.
*/
function do_text_javascript($var_array): void
{
do_text_text_javascript($var_array);
}
/**
* Main function for displaying sentences. It will print HTML content.
*
* @param string|int $textid ID of the requiered text
* @param bool $only_body If true, only show the inner body. If false, create a complete HTML document.
*/
function do_text_text_content($textid, $only_body = true): void
{
// Text settings
$record = get_text_data($textid);
$title = $record['TxTitle'];
$langid = (int)$record['TxLgID'];
$ann = (string) $record['TxAnnotatedText'];
$pos = $record['TxPosition'];
// Language settings
$record = get_language_settings($langid);
$wb1 = isset($record['LgDict1URI']) ? $record['LgDict1URI'] : "";
$wb2 = isset($record['LgDict2URI']) ? $record['LgDict2URI'] : "";
$wb3 = isset($record['LgGoogleTranslateURI']) ? $record['LgGoogleTranslateURI'] : "";
$textsize = $record['LgTextSize'];
$removeSpaces = $record['LgRemoveSpaces'];
$rtlScript = (bool)$record['LgRightToLeft'];
// User settings
$showAll = getSettingZeroOrOne('showallwords', 1);
$showLearning = getSettingZeroOrOne('showlearningtranslations', 1);
/**
* Annotation position between 0 and 4
*/
$mode_trans = (int) getSettingWithDefault('set-text-frame-annotation-position');
/**
* Ruby annotations
*/
$ruby = $mode_trans == 2 || $mode_trans == 4;
if (!$only_body) {
// Start the page with a HEAD and opens a BODY tag
pagestart_nobody($title);
}
?>
<script type="text/javascript" src="js/jquery.hoverIntent.js" charset="utf-8"></script>
<?php
$visit_status = getSettingWithDefault('set-text-visit-statuses-via-key');
if ($visit_status == '') {
$visit_status = '0';
}
$var_array = array(
// Change globals from jQuery hover
'LWT_DATA' => array(
'language' => array(
'id' => $langid,
'dict_link1' => $wb1,
'dict_link2' => $wb2,
'translator_link' => $wb3,
'delimiter' => tohtml(
str_replace(
array('\\',']','-','^'),
array('\\\\','\\]','\\-','\\^'),
getSettingWithDefault('set-term-translation-delimiters')
)
),
'word_parsing' => $record['LgRegexpWordCharacters'],
'rtl' => $rtlScript
),
'text' => array(
'id' => $textid,
'reading_position' => $pos,
'annotations' => json_decode(annotation_to_json($ann))
),
'settings' => array(
'jQuery_tooltip' => (
getSettingWithDefault('set-tooltip-mode') == 2 ? 1 : 0
),
'hts' => getSettingWithDefault('set-hts'),
'word_status_filter' => makeStatusClassFilter((int)$visit_status),
'annotations_mode' => $mode_trans
),
)
);
do_text_text_javascript($var_array);
do_text_text_style($showLearning, $mode_trans, $textsize, strlen($ann) > 0);
?>
<div id="thetext" <?php echo ($rtlScript ? 'dir="rtl"' : '') ?>>
<p style="margin-bottom: 10px;
<?php echo $removeSpaces ? 'word-break:break-all;' : ''; ?>
font-size: <?php echo $textsize; ?>%;
line-height: <?php echo $ruby ? '1' : '1.4'; ?>;"
>
<!-- Start displaying words -->
<?php main_word_loop($textid, $showAll); ?></span>
</p>
<p style="font-size:<?php echo $textsize; ?>%;line-height: 1.4; margin-bottom: 300px;"> </p>
</div>
<?php
if (!$only_body) {
pageend();
}
flush();
}
/*
Uncoment to use as a page, deprecated behavior in LWT-fork, will be removed in 3.0.0
if (isset($_REQUEST['text'])) {
do_text_text_content($_REQUEST['text'], false);
}
*/
?>