forked from chaosarium/lwt
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.php
455 lines (415 loc) · 14.7 KB
/
index.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
<?php
/**
* \file
* \brief LWT Start screen and main menu
*
* Call: index.php
*
* PHP version 8.1
*
* @category User_Interface
* @package Lwt
* @author LWT Project <[email protected]>
* @license Unlicense <http://unlicense.org/>
* @link https://hugofara.github.io/lwt/docs/php/files/index.html
* @since 1.0.3
*
* "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/].
*/
/**
* Echo an error page if connect.inc.php was not found.
*
* @return void
*
* @since 2.7.0-fork Now display a link to the connect.ing.php creation wizard,
* return void instead of dying.
*/
function no_connectinc_error_page()
{
?>
<html>
<body>
<div style="padding: 1em; color:red; font-size:120%; background-color:#CEECF5;">
<p>
<b>Fatal Error:</b>
Cannot find file: "connect.inc.php"!<br />
Please do one of the following:
<ul>
<li>
Rename the correct file "connect_[servertype].inc.php" to "connect.inc.php"
([servertype] is the name of your server: xampp, mamp, or easyphp).
</li>
<li>
<a href="database_wizard.php">Use the wizard</a>.
</li>
</ul>
Please read the documentation: <a href="https://hugofara.github.io/lwt/README.md">https://hugofara.github.io/lwt/README.md</a>
</p>
</div>
</body>
</html>
<?php
}
if (!file_exists('connect.inc.php')) {
no_connectinc_error_page();
die('');
}
require_once 'inc/session_utility.php';
/**
* Prepare the different SPAN opening tags
*
* @return string[] 3 different span levels
*
* @global string $tbpref Database table prefix
* @global string $fixed_tbpref Fixed database table prefix
*
* @psalm-return list{'<span title="Manage Table Sets" onclick="location.href='table_set_management.php';" class="click">'|'<span>', string, '<span title="Select Table Set" onclick="location.href='start.php';" class="click">'|'<span>'}
*/
function get_span_groups(): array
{
global $tbpref, $fixed_tbpref;
if ($tbpref == '') {
$span2 = "<i>Default</i> Table Set</span>";
} else {
$span2 = "Table Set: <i>" . tohtml(substr($tbpref, 0, -1)) . "</i></span>";
}
if ($fixed_tbpref) {
$span1 = '<span>';
$span3 = '<span>';
} else {
$span1 = '<span title="Manage Table Sets" onclick="location.href=\'table_set_management.php\';" class="click">';
if (count(getprefixes()) > 0) {
$span3 = '<span title="Select Table Set" onclick="location.href=\'start.php\';" class="click">';
} else {
$span3 = '<span>';
}
}
return array($span1, $span2, $span3);
}
/**
* Display the current text options.
*
* @return void
*
* @global string $tbpref Database table prefix
*/
function do_current_text_info($textid)
{
global $tbpref;
$txttit = get_first_value(
'SELECT TxTitle AS value
FROM ' . $tbpref . 'texts
WHERE TxID=' . $textid
);
if (!isset($txttit)) {
return;
}
$txtlng = get_first_value(
'SELECT TxLgID AS value FROM ' . $tbpref . 'texts WHERE TxID=' . $textid
);
$lngname = getLanguage($txtlng);
$annotated = (int)get_first_value(
"SELECT LENGTH(TxAnnotatedText) AS value
FROM " . $tbpref . "texts
WHERE TxID = " . $textid
) > 0;
?>
<div style="height: 85px;">
Last Text (<?php echo tohtml($lngname); ?>):<br />
<i><?php echo tohtml($txttit); ?></i>
<br />
<a href="do_text.php?start=<?php echo $textid; ?>">
<img src="icn/book-open-bookmark.png" title="Read" alt="Read" /> Read
</a>
<a href="do_test.php?text=<?php echo $textid; ?>">
<img src="icn/question-balloon.png" title="Test" alt="Test" /> Test
</a>
<a href="print_text.php?text=<?php echo $textid; ?>">
<img src="icn/printer.png" title="Print" alt="Print" /> Print
</a>
<?php
if ($annotated) {
?>
<a href="print_impr_text.php?text=<?php echo $textid; ?>">
<img src="icn/tick.png" title="Improved Annotated Text" alt="Improved Annotated Text" /> Ann. Text
</a>
<?php
}
?>
</div>
<?php
}
/**
* Echo a select element to switch between languages.
*
* @return void
*/
function do_language_selectable($langid)
{
?>
<div for="filterlang">Language:
<select id="filterlang" onchange="{setLang(document.getElementById('filterlang'),'index.php');}">
<?php echo get_languages_selectoptions($langid, '[Select...]'); ?>
</select>
</div>
<?php
}
/**
* When on a WordPress server, make a logout button
*
* @return void
*/
function wordpress_logout_link()
{
if (isset($_SESSION['LWT-WP-User'])) {
?>
<div class="menu">
<a href="wp_lwt_stop.php">
<span style="font-size:115%; font-weight:bold; color:red;">LOGOUT</span> (from WordPress and LWT)
</a>
</div>
<?php
}
}
/**
* Return a lot of different server state variables.
*
* @return (false|float|string|string[])[] {0: string, 1: float, 2: string[], 3: string, 4: string, 5: string}
* Table prefix, database size, server software, apache version, PHP version, MySQL
* version
*
* @deprecated Use get_server_data_table, will be removed in 3.0.0.
*
* @psalm-return list{string, float, non-empty-list<string>, string, false|string, string}
* @global string $tbpref Database table prefix
* @global string $dbname Database name
*/
function get_server_data(): array
{
global $tbpref, $dbname;
$dbaccess_format = convert_string_to_sqlsyntax($dbname);
$data_table = array();
$data_table["prefix"] = convert_string_to_sqlsyntax_nonull($tbpref);
$data_table["db_size"] = (float)get_first_value(
"SELECT ROUND(SUM(data_length+index_length)/1024/1024, 1) AS value
FROM information_schema.TABLES
WHERE table_schema = $dbaccess_format
AND table_name IN (
'{$tbpref}archivedtexts', '{$tbpref}archtexttags', '{$tbpref}feedlinks', '{$tbpref}languages',
'{$tbpref}newsfeeds', '{$tbpref}sentences', '{$tbpref}settings', '{$tbpref}tags', '{$tbpref}tags2',
'{$tbpref}textitems2', '{$tbpref}texts', '{$tbpref}texttags', '{$tbpref}words', '{$tbpref}wordtags'
)"
);
if (!isset($data_table["db_size"])) {
$data_table["db_size"] = 0.0;
}
$data_table["serversoft"] = explode(' ', $_SERVER['SERVER_SOFTWARE']);
$data_table["apache"] = "Apache/?";
if (substr($data_table["serversoft"][0], 0, 7) == "Apache/") {
$data_table["apache"] = $data_table["serversoft"][0];
}
$data_table["php"] = phpversion();
$data_table["mysql"] = (string)get_first_value("SELECT VERSION() as value");
return array(
$data_table["prefix"], $data_table["db_size"], $data_table["serversoft"],
$data_table["apache"], $data_table["php"], $data_table["mysql"]
);
}
/**
* Load the content of warnings for visual display.
*
* @return void
*/
function index_load_warnings()
{
?>
<script type="text/javascript">
//<![CDATA[
const loadWarnings = {
cookiesDisabled: function () {
if (!areCookiesEnabled()) {
$('#cookies_disabled')
.html('*** Cookies are not enabled! Please enable them! ***');
}
},
shouldUpdate: function (from_version, to_version) {
const regex = /^(\d+)\.(\d+)\.(\d+)(?:-[\w.-]+)?/;
const match1 = from_version.match(regex);
const match2 = to_version.match(regex);
let level1, level2;
for (let i = 1; i < 4; i++) {
level1 = parseInt(match1[i], 10);
level2 = parseInt(match2[i], 10);
if (level1 < level2) {
return true;
} else if (level1 > level2) {
return false;
}
}
return null;
},
outdatedPHP: function (php_version) {
const php_min_version = '8.0.0';
if (loadWarnings.shouldUpdate(php_version, php_min_version)) {
$('#php_update_required').html(
'*** Your PHP version is ' + php_version + ', but version ' +
php_min_version + ' is required. Please update it. ***'
)
}
},
updateLWT: function(lwt_version) {
$.getJSON(
'https://api.github.com/repos/hugofara/lwt/releases/latest'
).done(function (data) {
const latest_version = data.tag_name;
if (loadWarnings.shouldUpdate(lwt_version, latest_version)) {
$('#lwt_new_version').html(
'*** An update for LWT is available: ' +
latest_version +', your version is ' + lwt_version +
'. <a href="https://github.com/HugoFara/lwt/releases/tag/' +
latest_version + '">Download</a>.***'
);
}
});
}
}
loadWarnings.cookiesDisabled();
loadWarnings.outdatedPHP(<?php echo json_encode(phpversion()); ?>);
loadWarnings.updateLWT(<?php echo json_encode(LWT_APP_VERSION); ?>);
//]]>
</script>
<?php
}
/**
* Display the main body of the page.
*
* @return void
*
* @global string $tbpref Database table prefix
* @global int $debug Debug mode enabled
*/
function index_do_main_page()
{
global $tbpref, $debug;
$currentlang = null;
if (is_numeric(getSetting('currentlanguage'))) {
$currentlang = (int) getSetting('currentlanguage');
}
$currenttext = null;
if (is_numeric(getSetting('currenttext'))) {
$currenttext = (int) getSetting('currenttext');
}
$langcnt = (int) get_first_value("SELECT COUNT(*) AS value FROM {$tbpref}languages");
pagestart_nobody(
"Home",
"
body {
max-width: 1920px;
margin: 20px;
}"
);
echo_lwt_logo();
echo '<h1>Learning With Texts (LWT)</h1>
<h2>Home' . ($debug ? ' <span class="red">DEBUG</span>' : '') . '</h2>';
?>
<div class="red"><p id="php_update_required"></p></div>
<div class="red"><p id="cookies_disabled"></p></div>
<div class="msgblue"><p id="lwt_new_version"></p></div>
<p style="text-align: center;">Welcome to your language learning app!</p>
<div style="display: flex; justify-content: space-evenly; flex-wrap: wrap;">
<div class="menu">
<?php
if ($langcnt == 0) {
?>
<div><p>Hint: The database seems to be empty.</p></div>
<a href="install_demo.php">Install the LWT demo database, </a>
<a href="edit_languages.php?new=1">Define the first language you want to learn.</a>
<?php
} else if ($langcnt > 0) {
do_language_selectable($currentlang);
if ($currenttext !== null) {
do_current_text_info($currenttext);
}
}
?>
<a href="edit_languages.php">Languages</a>
</div>
<div class="menu">
<a href="edit_texts.php">Texts</a>
<a href="edit_archivedtexts.php">Text Archive</a>
<a href="edit_texttags.php">Text Tags</a>
<a href="check_text.php">Check Text</a>
<a href="long_text_import.php">Import Long Text</a>
</div>
<div class="menu">
<a href="edit_words.php" title="View and edit saved words and expressions">Terms</a>
<a href="edit_tags.php">Term Tags</a>
<a href="upload_words.php">Import Terms</a>
</div>
<div class="menu">
<a href="do_feeds.php?check_autoupdate=1">Newsfeeds</a>
<a href="backup_restore.php" title="Backup, restore or empty database">Database</a>
</div>
<div class="menu">
<a href="statistics.php" title="Text statistics">Statistics</a>
<a href="docs/info.html">Help</a>
<a href="server_data.php" title="Various data useful for debug">Server Data</a>
</div>
<div class="menu">
<a href="settings.php">Settings</a>
<a href="text_to_speech_settings.php" title="Text-to-Speech settings">Text-to-Speech</a>
<a href="mobile.php" title="Mobile LWT is a legacy function">Mobile LWT (Deprecated)</a>
</div>
<?php wordpress_logout_link(); ?>
</div>
<p>
This is LWT Version <?php echo get_version(); ?>,
<a href="start.php"><?php echo ($tbpref == '' ? 'default table set' : 'table prefixed with "' . $tbpref . '"') ?></a>.
</p>
<br style="clear: both;" />
<footer>
<p class="small">
<a target="_blank" href="http://unlicense.org/" style="vertical-align: top;">
<img alt="Public Domain" title="Public Domain" src="img/public_domain.png" style="display: inline;" />
</a>
<a href="https://sourceforge.net/projects/learning-with-texts/" target="_blank">"Learning with Texts" (LWT)</a> is free
and unencumbered software released into the
<a href="https://en.wikipedia.org/wiki/Public_domain_software" target="_blank">PUBLIC DOMAIN</a>.
<a href="http://unlicense.org/" target="_blank">More information and detailed Unlicense ...</a>
</p>
</footer>
<?php
index_load_warnings();
pageend();
}
index_do_main_page();
?>