Skip to content

Commit

Permalink
Merge branch 'dev': REST API and numerous fixes.
Browse files Browse the repository at this point in the history
Changes annotations number to be equal to Ti2Order.
TTT Settings issues fixed ("Read" button was refreshing the page).
Updates composer dependencies.
Complete linting for PHP files.
Server data format improved.
  • Loading branch information
HugoFara committed Sep 16, 2023
2 parents 69e82c1 + af206fd commit d8e2258
Show file tree
Hide file tree
Showing 61 changed files with 4,970 additions and 2,547 deletions.
475 changes: 242 additions & 233 deletions composer.lock

Large diffs are not rendered by default.

468 changes: 270 additions & 198 deletions database_wizard.php

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions display_impr_text_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ function do_diplay_impr_text_header_content($title, $textid, $audio, $sourceURI)
</div>
<div>
<?php
if (isset($sourceURI)) {
echo ' <a href="' . $sourceURI . '" target="_blank">
if (isset($sourceURI)) {
echo ' <a href="' . $sourceURI . '" target="_blank">
<img src="'.get_file_path('icn/chain.png').'" title="Text Source" alt="Text Source" />
</a>';
}
echo getPreviousAndNextTextLinks($textid, 'display_impr_text.php?text=', true, ' &nbsp; &nbsp; ');
</a>';
}
echo getPreviousAndNextTextLinks($textid, 'display_impr_text.php?text=', true, ' &nbsp; &nbsp; ');
?>
</div>
<div>
Expand Down
1 change: 0 additions & 1 deletion do_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ function do_test_page($p)
{
pagestart_nobody(
'Test',

"body {
margin: 20px;
max-width: 100%;
Expand Down
4 changes: 2 additions & 2 deletions do_test_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function do_test_header_row($_p)
$textid, 'do_test.php?text=', false, ''
) . '</div>';

?>
?>
<div>
<a href="do_text.php?start=<?php echo $textid; ?>" target="_top">
<img src="icn/book-open-bookmark.png" title="Read" alt="Read" />
Expand All @@ -160,7 +160,7 @@ function do_test_header_row($_p)
</a>
<?php echo get_annotation_link($textid); ?>
</div>
<?php
<?php
}
?>
<div>
Expand Down
15 changes: 8 additions & 7 deletions do_test_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*
* @param bool|null $selection Test is of type selection
* @param string|null $sess_testsql SQL string for test
* @param int|null $lang Test is of type language, for the language $lang ID
* @param int|null $text Testing text with ID $text
* @param int|null $lang Test is of type language, for the language $lang ID
* @param int|null $text Testing text with ID $text
*
* @return string SQL projection (selection) string
*/
Expand Down Expand Up @@ -356,10 +356,10 @@ function do_test_get_word($testsql)
/**
* Get the solution to a test.
*
* @param int $testtype Test type between 1 and 5
* @param array $wo_record Word record element
* @param bool $nosent Test is in word mode
* @param string $wo_text Word text
* @param int $testtype Test type between 1 and 5
* @param array $wo_record Word record element
* @param bool $nosent Test is in word mode
* @param string $wo_text Word text
*
* @return string Solution to display.
*/
Expand Down Expand Up @@ -691,7 +691,8 @@ function do_test_test_interaction_globals($wb1, $wb2, $wb3)
* @global string $tbpref Database table prefix
* @global string $angDefs Languages definition array
*/
function do_test_test_javascript_clickable($wo_record, $solution) {
function do_test_test_javascript_clickable($wo_record, $solution)
{
global $tbpref, $langDefs;

$wid = $wo_record['WoID'];
Expand Down
53 changes: 21 additions & 32 deletions do_text_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ function do_header_row($textid, $langid): void
</div>
<div>
<?php
echo getPreviousAndNextTextLinks(
$textid, 'do_text.php?start=', false, ''
);
echo getPreviousAndNextTextLinks(
$textid, 'do_text.php?start=', false, ''
);
?>
</div>
<div>
Expand Down Expand Up @@ -109,15 +109,15 @@ function do_title($title, $sourceURI): void
?>
<h1>READ ▶
<?php
echo tohtml($title);
if (isset($sourceURI) && substr(trim($sourceURI), 0, 1) != '#') {
?>
echo tohtml($title);
if (isset($sourceURI) && !str_starts_with(trim($sourceURI), '#')) {
?>
<a href="<?php echo $sourceURI ?>" target="_blank">
<img src="<?php echo get_file_path('icn/chain.png') ?>" title="Text Source" alt="Text Source" />
</a>
<?php
}
?>
<?php
}
?>
</h1>
<?php
}
Expand Down Expand Up @@ -198,26 +198,13 @@ function browser_tts($text, $languageName): void
lang: getLangFromDict(WBLINK3) || <?php echo json_encode($languageCode); ?>,

/// {string} Rate at wich the speech is done
rate: 0.8,

/**
* Reads a text using the browser text reader.
*
* @deprecated Since 2.3.0-fork, use of window.readTextAloud is recommended instead.
*/
readTextAloud: function () {
const msg = new SpeechSynthesisUtterance(this.text);
console.log('This function is deprecated, do not use it!')
msg.text = this.text;
msg.lang = this.lang;
msg.rate = this.rate;
window.speechSynthesis.cancel();
window.speechSynthesis.speak(msg);
},
rate: 0.8

};

/** Check browser compatibility before reading */
/**
* Check browser compatibility before reading
*/
function init_reading() {
if (!('speechSynthesis' in window)) {
alert('Your browser does not support speechSynthesis!');
Expand Down Expand Up @@ -249,7 +236,7 @@ function toggle_reading() {
*/
function annotationModeChanged(mode) {
console.log(mode);

// 2.9.0: seems to be a debug function, candidate to deletion
}
</script>
<?php
Expand Down Expand Up @@ -277,12 +264,14 @@ function saveAudioPosition() {
var pos = $("#jquery_jplayer_1").data("jPlayer").status.currentTime;
$.ajax({
type: "POST",
url:'inc/ajax_save_text_position.php',
data: {
id: '<?php echo $textid; ?>',
audioposition: pos
url:'inc/ajax.php',
data: {
action: "reading_position",
action_type: "audio",
tid: '<?php echo $textid; ?>',
audio_position: pos
},
async: false
async: false // Asynchronous should be safe (2.9.0)
});
}

Expand Down
139 changes: 74 additions & 65 deletions do_text_text.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ function getLanguagesSettings($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
* @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
*
Expand All @@ -126,31 +126,34 @@ function getLanguagesSettings($langid)
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 (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(" ", [
'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'],
'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'])
);
Expand All @@ -171,53 +174,59 @@ function echo_term(
// Single word
if (isset($record['WoID'])) {
// Word found status 1-5|98|99
$attributes = array(
'id' => $spanid,
'class' => implode(" ", [
$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']
);
]
),
'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(" ", [
$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' => ''
);
]
),
'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]);
}
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);
}
}
for ($i = sizeof($exprs) - 1; $i >= 0; $i--) {
$exprs[$i][2]--;
if ($exprs[$i][2] < 1) {
unset($exprs[$i]);
$exprs = array_values($exprs);
}
}
}
}

Expand Down Expand Up @@ -332,20 +341,20 @@ function sentenceParser($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
* @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
{
$record, $showAll, $currcharcount, $hide, &$exprs = array()
): void {
$actcode = (int)$record['Code'];
$spanid = 'ID-' . $record['Ti2Order'] . '-' . $actcode;

Expand Down
Loading

0 comments on commit d8e2258

Please sign in to comment.