forked from hans/lwt
-
Notifications
You must be signed in to change notification settings - Fork 9
/
do_text_text.php
254 lines (206 loc) · 11.6 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
<?php
/**************************************************************
"Learning with Texts" (LWT) is free and unencumbered software
released into the PUBLIC DOMAIN.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a
compiled binary, for any purpose, commercial or non-commercial,
and by any means.
In jurisdictions that recognize copyright laws, the author or
authors of this software dedicate any and all copyright
interest in the software to the public domain. We make this
dedication for the benefit of the public at large and to the
detriment of our heirs and successors. We intend this
dedication to be an overt act of relinquishment in perpetuity
of all present and future rights to this software under
copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
For more information, please refer to [http://unlicense.org/].
***************************************************************/
/**************************************************************
Call: do_text_text.php?text=[textid]
Show text header frame
***************************************************************/
require_once( 'settings.inc.php' );
require_once( 'connect.inc.php' );
require_once( 'dbutils.inc.php' );
require_once( 'utilities.inc.php' );
$sql = 'select TxLgID, TxTitle, TxAnnotatedText, TxPosition from ' . $tbpref . 'texts where TxID = ' . $_REQUEST['text'];
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$title = $record['TxTitle'];
$langid = $record['TxLgID'];
$ann = $record['TxAnnotatedText'];
$ann_exists = (strlen($ann) > 0);
$pos = $record['TxPosition'];
mysqli_free_result($res);
pagestart_nobody(tohtml($title));
$sql = 'select LgName, LgDict1URI, LgDict2URI, LgGoogleTranslateURI, LgTextSize, LgRemoveSpaces, LgRightToLeft from ' . $tbpref . 'languages where LgID = ' . $langid;
$res = do_mysqli_query($sql);
$record = mysqli_fetch_assoc($res);
$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 = $record['LgRightToLeft'];
mysqli_free_result($res);
$showAll = getSettingZeroOrOne('showallwords',1);
$showLearning = getSettingZeroOrOne('showlearningtranslations', 1);
?>
<script type="text/javascript" src="js/jquery.hoverIntent.js" charset="utf-8"></script>
<script type="text/javascript">
//<![CDATA[
ANN_ARRAY = <?php echo annotation_to_json($ann); ?>;
DELIMITER = '<?php echo tohtml(str_replace (array('\\',']','-','^'),array('\\\\','\\]','\\-','\\^'),getSettingWithDefault('set-term-translation-delimiters'))); ?>';
TEXTPOS = -1;
OPENED = 0;
WBLINK1 = '<?php echo $wb1; ?>';
WBLINK2 = '<?php echo $wb2; ?>';
WBLINK3 = '<?php echo $wb3; ?>';
LANG = WBLINK3.replace(/.*[?&]sl=([a-zA-Z\-]*)(&.*)*$/, "$1");
if(LANG && LANG!=WBLINK3) $("html").attr('lang',LANG);
RTL = <?php echo $rtlScript; ?>;
TID = '<?php echo $_REQUEST['text']; ?>';
ADDFILTER = '<?php echo makeStatusClassFilter(getSettingWithDefault('set-text-visit-statuses-via-key')); ?>';
<?php if(getSettingWithDefault('set-tooltip-mode') == 2) { ?>
JQ_TOOLTIP = 1;
$(function() {
$( '#overDiv' ).tooltip();
$( "#thetext" ).tooltip_wsty_init();
});
<?php }
else echo 'JQ_TOOLTIP = 0;';
$mode_trans=getSettingWithDefault('set-text-frame-annotation-position');
?>
$(document).ready( function() {
$('.word').each(word_each_do_text_text);
$('.mword').each(mword_each_do_text_text);
$('.word').click(word_click_event_do_text_text);
$('#thetext').on('selectstart','span',false).on('mousedown','.wsty',{annotation: <?php echo $mode_trans; ?>},mword_drag_n_drop_select);
$('#thetext').on('click','.mword',mword_click_event_do_text_text);
$('.word').dblclick(word_dblclick_event_do_text_text);
$('#thetext').on('dblclick','.mword',word_dblclick_event_do_text_text);
$(document).keydown(keydown_event_do_text_text);
$('#thetext').hoverIntent({over: word_hover_over, out: word_hover_out, interval: 150,selector:".wsty,.mwsty"});
});
$(document).ready( function() {
var pos = <?php
if($pos>0){
echo '$(".wsty';
echo "[data_pos='$pos']";
echo '").not(".hide").eq(0);';
echo 'if (typeof pos.attr("data_pos") === "undefined") {pos= $(".wsty").not(".hide").filter(function(){return $(this).attr("data_pos")<='. $pos.';}).eq(-1);}';
}
else echo '0;';
?>
$(document).scrollTo(pos);
window.focus();
window.setTimeout('overlib()', 10);
window.setTimeout('cClick()', 100);
});
$(window).on('beforeunload',function() {
var pos=0;
var top=$(window).scrollTop()-$('.wsty').not('.hide').eq(0).height();
$('.wsty').not('.hide').each(function() {
if ($(this).offset().top>=top){
pos=$(this).attr('data_pos');
return false;
}
});
$.ajax({type: "POST",url:'ajax_save_text_position.php', data: { id: '<?php echo $_REQUEST['text']; ?>', position: pos }, async:false});
});
//]]>
</script>
<?php
$data_trans=$ann_exists?'data_ann':'data_trans';
$pseudo_element=($mode_trans<3)?'after':'before';
$ruby=($mode_trans==2 || $mode_trans==4)?1:0;
$displaystattrans=getSettingWithDefault('set-display-text-frame-term-translation');
echo "<style>\n";
$stat_arr = array(1,2,3,4,5,98,99);
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,');}',"\n",'.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";}
if($ruby)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%;'),'}',"\n",'.hide{display:none !important;}.tword:',$pseudo_element,($ruby?',.word:':',.wsty:'),$pseudo_element,'{max-width:15em;}</style>';
echo '<div id="thetext" ' . ($rtlScript ? 'dir="rtl"' : '') . '><p style="' . ($removeSpaces ? 'word-break:break-all;' : '') .
'font-size:' . $textsize . '%;line-height: ',($ruby?'1':'1.4'),'; margin-bottom: 10px;">';
$currcharcount = 0;
$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 as TiOrder,Ti2SeID as TiSeID,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 = ' . $_REQUEST['text'] . ' order by Ti2Order asc, Ti2WordCount desc';
$hideuntil = -1;
$hidetag = '';
$cnt = 1;
$sid = 0;
$res = do_mysqli_query($sql);
while ($record = mysqli_fetch_assoc($res)) { // MAIN LOOP
if($sid != $record['TiSeID']){
if($sid != 0){
echo '</span>';
}
$sid = $record['TiSeID'];
echo '<span id="sent_',$sid,'">';
}
$actcode = $record['Code'] + 0;
$spanid = 'ID-' . $record['TiOrder'] . '-' . $actcode;
if ( $hideuntil > 0 ) {
if ( $record['TiOrder'] <= $hideuntil )
$hidetag = ' hide';
else {
$hideuntil = -1;
$hidetag = '';
}
}
if($cnt<$record['TiOrder']){
echo '<span id="ID-' . $cnt++ . '-1"></span>';
}
if ($record['TiIsNotWord'] != 0) { // NOT A TERM
echo '<span id="' . $spanid . '" class="' .
$hidetag . '">' .
str_replace(
"¶",
'<br />',
tohtml($record['TiText'])) . '</span>';
} // $record['TiIsNotWord'] != 0 -- NOT A TERM
/////////////////////////////////////////////////
else { // $record['TiIsNotWord'] == 0 -- A TERM
if ($actcode > 1) { // A MULTIWORD FOUND
//$titext[$actcode] = $record['TiText'];
if (isset($record['WoID'])) { // MULTIWORD FOUND - DISPLAY (Status 1-5, display)
if (! $showAll) {
if ($hideuntil == -1) {
$hideuntil = $record['TiOrder'] + ($record['Code'] - 1) * 2;
}
}
?><span id="<?php echo $spanid; ?>" class="<?php echo $hidetag; ?> click mword <?php echo ($showAll ? 'mwsty' : 'wsty'); ?> <?php echo 'order'. $record['TiOrder']; ?> <?php echo 'word'. $record['WoID']; ?> <?php echo 'status'. $record['WoStatus']; ?> TERM<?php echo strToClassName($record['TiTextLC']); ?>" data_pos="<?php echo $currcharcount; ?>" data_order="<?php echo $record['TiOrder']; ?>" data_wid="<?php echo $record['WoID']; ?>" data_trans="<?php echo tohtml(repl_tab_nl($record['WoTranslation']) . getWordTagList($record['WoID'],' ',1,0)); ?>" data_rom="<?php echo tohtml($record['WoRomanization']); ?>" data_status="<?php echo $record['WoStatus']; ?>" data_code="<?php echo $record['Code']; ?>" data_text="<?php echo tohtml($record['TiText']); ?>"><?php echo ($showAll ? (' ' . $record['Code'] . ' ') : tohtml($record['TiText'])); ?></span><?php
}
} // ($actcode > 1) -- A MULTIWORD FOUND
////////////////////////////////////////////////
else { // ($actcode == 1) -- A WORD FOUND
if (isset($record['WoID'])) { // WORD FOUND STATUS 1-5,98,99
?><span id="<?php echo $spanid; ?>" class="<?php echo $hidetag; ?> click word wsty <?php echo 'word'. $record['WoID']; ?> <?php echo 'status'. $record['WoStatus']; ?> TERM<?php echo strToClassName($record['TiTextLC']); ?>" data_pos="<?php echo $currcharcount; ?>" data_order="<?php echo $record['TiOrder']; ?>" data_wid="<?php echo $record['WoID']; ?>" data_trans="<?php echo tohtml(repl_tab_nl($record['WoTranslation']) . getWordTagList($record['WoID'],' ',1,0)); ?>" data_rom="<?php echo tohtml($record['WoRomanization']); ?>" data_status="<?php echo $record['WoStatus']; ?>"><?php echo tohtml($record['TiText']); ?></span><?php
} // WORD FOUND STATUS 1-5,98,99
////////////////////////////////////////////////
else { // NOT A WORD AND NOT A MULTIWORD FOUND - STATUS 0
?><span id="<?php echo $spanid; ?>" class="<?php echo $hidetag; ?> click word wsty status0 TERM<?php echo strToClassName($record['TiTextLC']); ?>" data_pos="<?php echo $currcharcount; ?>" data_order="<?php echo $record['TiOrder']; ?>" data_trans="" data_rom="" data_status="0" data_wid=""><?php echo tohtml($record['TiText']); ?></span><?php
} // NOT A WORD AND NOT A MULTIWORD FOUND - STATUS 0
//$titext = array('','','','','','','','','','','');
} // ($actcode == 1) -- A WORD FOUND
} // $record['TiIsNotWord'] == 0 -- A TERM
if ($actcode == 1){ $currcharcount += $record['TiTextLength']; $cnt++;}
} // while ($record = mysql_fetch_assoc($res)) -- MAIN LOOP
mysqli_free_result($res);
echo '</span><span id="totalcharcount" class="hide">' . $currcharcount . '</span></p><p style="font-size:' . $textsize . '%;line-height: 1.4; margin-bottom: 300px;"> </p></div>';
pageend();
?>