Skip to content

Commit

Permalink
Patch 6 (#2)
Browse files Browse the repository at this point in the history
* Code clean-up with the audio controller.
Remove the unitended declaration of global variables.

* Refactor audio_controller in  object  namespace style.
Backward compatibility is kept.

* Fixes HugoFara#138: changing audio speed was partially broken.

* Replaces calls to global audio functions by the new object.
Removes the undocumented audio functions.

* Avoid unnecessary function return type.

* Fixes "text_id is unkown" on text opening.

* Fixes warning on step 2 of feed wizard (related to HugoFara#129)

* Reorders functions to be in logical declaration order.

* Code cleaning.

* Refactoring jq_feedwizard as object namespace.

* Synctactic sugar on jq_feedwizard.js.

* Adds an helper object to avoid one-line JS.

* Prettyfies JS code.

* Isolates JS code in feed wizard step 3.

* Use json_encode to avoid PHP incursion in JS code.
Code prettyfying.

* Beautify JS and avoid calls to deprecated functions.

* Fixes JS errors on feeds: xPath was not set, and it was sometimes leave step 2.

* Beautifies demo DB as the users has the right to see what they install.

* Fix: the demo database was unreadable since last commit.
restore_file is much better at parsing SQL.

* Stop reading demo on errors, syntactic suger.

* Better detection of file end not read.

* Changes WoStatusChange to a value that doesn't need configuration change (HugoFara#78).

* Implementes HugoFara#148: removes dead feeds from demo database.

* Fixes a bug introduced in a previous commit.
Signalled by  @ProgramComputer.

* Fixes HugoFara#151: click delete on a language deletes the language.

* Multi-image docker

* Update docker-image.yml

* Update docker-image.yml

* Update docker-image.yml

* Update docker-image.yml

* Update docker-image.yml

* Update docker-image.yml

* Update docker-image.yml

---------

Co-authored-by: HugoFara <[email protected]>
  • Loading branch information
ProgramComputer and HugoFara authored Dec 29, 2023
1 parent b64cd6a commit f80e26d
Show file tree
Hide file tree
Showing 13 changed files with 4,090 additions and 1,495 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Docker image

on:
release:
types: [published]
push:
branches: [ 'master' ]
tags:
Expand All @@ -13,14 +15,26 @@ env:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v6
- linux/arm/v7
- linux/arm64
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3


- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
Expand All @@ -39,5 +53,14 @@ jobs:
with:
context: .
push: true
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{secrets.GITHUB_TOKEN }}
file: target/release/${{ matrix.platform }}
asset_name: ${{ steps.meta.outputs.tags }}-${{ matrix.platform }}
tag: ${{ github.ref }}

2 changes: 1 addition & 1 deletion backup_restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
`WoRomanization` varchar(100) DEFAULT NULL,
`WoSentence` varchar(1000) DEFAULT NULL,
`WoCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`WoStatusChanged` timestamp NOT NULL DEFAULT '0000-00-00 00:00:01',
`WoStatusChanged` timestamp NOT NULL DEFAULT '1970-01-01 01:00:01',
`WoTodayScore` double NOT NULL DEFAULT '0',
`WoTomorrowScore` double NOT NULL DEFAULT '0',
`WoRandom` double NOT NULL DEFAULT '0',
Expand Down
10 changes: 5 additions & 5 deletions do_text_text.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,11 @@ function do_text_text_javascript($var_array): void
//<![CDATA[

/// Map global variables as a JSON object
const vars = <?php echo json_encode($var_array); ?>;
const new_globals = <?php echo json_encode($var_array); ?>;

// Set global variables
for (const key in vars) {
window[key] = vars[key];
for (const key in new_globals) {
window[key] = new_globals[key];
}
LANG = getLangFromDict(WBLINK3);
TEXTPOS = -1;
Expand Down Expand Up @@ -668,10 +668,10 @@ function saveCurrentPosition() {
$('.wsty').not('.hide').each(function() {
if ($(this).offset().top >= top_pos) {
pos = $(this).attr('data_pos');
return false;
return;
}
});
saveReadingPosition(text_id, pos);
saveReadingPosition(TID, pos);
}

$(document).ready(prepareTextInteractions);
Expand Down
25 changes: 21 additions & 4 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,39 @@ ones are marked like "v1.0.0-fork".

* PHP files header docblocks are expanded, notably with a PHP version, package and category name.
* Japanese number are now parsed by MeCab. Big thanks to [@ProgramComputer](https://github.com/ProgramComputer) for his pull request [#149](https://github.com/HugoFara/lwt/pull/149)!
* Removes dead feeds from the demo database, as signalled in [#148](https://github.com/HugoFara/lwt/issues/148).

### Fixed

* Fixes [#113](https://github.com/HugoFara/lwt/issues/113): changing a language name was making text-to-speech unusable and may prompt a warning.
* Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type"). This is fixed.
* Fixes [#113](https://github.com/HugoFara/lwt/issues/113): changing a language name
was making text-to-speech unusable and may prompt a warning.
* Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type").
* Since 2.9.0, audio position was not saved properly.
* On `upload_words.php`, "update only empty fields" was broken.
* Translation were not set by default properly when editing terms translations table.
* The field MeCab was set for japanese even when not asked for.
Signalled on PR [#155](https://github.com/HugoFara/lwt/pull/155), thanks to [@ProgramComputer](https://github.com/ProgramComputer).
* Since 2.8.1, japanese word romanization was not displayed any more. Thanks to 아르노 for signalling the bug on Discord!
Signalled on PR [#155](https://github.com/HugoFara/lwt/pull/155), thanks to
[@ProgramComputer](https://github.com/ProgramComputer).
* Since 2.8.1, japanese word romanization was not displayed any more.
Thanks to 아르노 for signalling the bug on Discord!
* The go slower/faster feature on audio was broken
([#138](https://github.com/HugoFara/lwt/issues/138)), as functions `click_slower`
and `click_faster` were declared two times in `src/js/audio_controller.js`.
* When opening a text, text position was not saved and a `text_id is unknown` error was triggered.
* Do not display an error on step 2 of feed wizard at first initialization
([#129](https://github.com/HugoFara/lwt/issues/129)).
* It was impossible to install the demo database if they was more or less than one instruction a line.
This is fixed, and the SQL file was made more readable.
* Changes `WoStatusChange` default value to '1970-01-01 01:00:01', it was impossible
to install the demo DB out of LWT (related to [#78](https://github.com/HugoFara/lwt/issues/78)).
* Deleting a language deletes the language ([#151](https://github.com/HugoFara/lwt/issues/151)).
Before it was setting the language to empty values.

### Deprecated

* PHP documentation using Doxygen (under `/docs/html`) is now deprecated and will be removed in 3.0.0.
* Using `$langDefs` is deprecated in favor of `LWT_LANGUAGES_ARRAY` ([#163](https://github.com/HugoFara/lwt/issues/163)).
* Calling the global function `new_pos` to set audio position is deprecated. Please use `lwt_audio_controller.setPosition`.

## 2.9.0-fork (December 24 2023)

Expand Down
25 changes: 21 additions & 4 deletions docs/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -2197,22 +2197,39 @@ <h4>Changed</h4>
<ul>
<li>PHP files header docblocks are expanded, notably with a PHP version, package and category name.</li>
<li>Japanese number are now parsed by MeCab. Big thanks to <a href="https://github.com/ProgramComputer">@ProgramComputer</a> for his pull request <a href="https://github.com/HugoFara/lwt/pull/149">#149</a>!</li>
<li>Removes dead feeds from the demo database, as signalled in <a href="https://github.com/HugoFara/lwt/issues/148">#148</a>.</li>
</ul>
<h4>Fixed</h4>
<ul>
<li>Fixes <a href="https://github.com/HugoFara/lwt/issues/113">#113</a>: changing a language name was making text-to-speech unusable and may prompt a warning.</li>
<li>Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type"). This is fixed.</li>
<li>Fixes <a href="https://github.com/HugoFara/lwt/issues/113">#113</a>: changing a language name
was making text-to-speech unusable and may prompt a warning.</li>
<li>Since 2.9.0, tests may be unable to run due to a missing key in an AJAX request ("type").</li>
<li>Since 2.9.0, audio position was not saved properly.</li>
<li>On <code>upload_words.php</code>, "update only empty fields" was broken.</li>
<li>Translation were not set by default properly when editing terms translations table.</li>
<li>The field MeCab was set for japanese even when not asked for.
Signalled on PR <a href="https://github.com/HugoFara/lwt/pull/155">#155</a>, thanks to <a href="https://github.com/ProgramComputer">@ProgramComputer</a>.</li>
<li>Since 2.8.1, japanese word romanization was not displayed any more. Thanks to 아르노 for signalling the bug on Discord!</li>
Signalled on PR <a href="https://github.com/HugoFara/lwt/pull/155">#155</a>, thanks to
<a href="https://github.com/ProgramComputer">@ProgramComputer</a>.</li>
<li>Since 2.8.1, japanese word romanization was not displayed any more.
Thanks to 아르노 for signalling the bug on Discord!</li>
<li>The go slower/faster feature on audio was broken
(<a href="https://github.com/HugoFara/lwt/issues/138">#138</a>), as functions <code>click_slower</code>
and <code>click_faster</code> were declared two times in <code>src/js/audio_controller.js</code>.</li>
<li>When opening a text, text position was not saved and a <code>text_id is unknown</code> error was triggered.</li>
<li>Do not display an error on step 2 of feed wizard at first initialization
(<a href="https://github.com/HugoFara/lwt/issues/129">#129</a>).</li>
<li>It was impossible to install the demo database if they was more or less than one instruction a line.
This is fixed, and the SQL file was made more readable.</li>
<li>Changes <code>WoStatusChange</code> default value to '1970-01-01 01:00:01', it was impossible
to install the demo DB out of LWT (related to <a href="https://github.com/HugoFara/lwt/issues/78">#78</a>).</li>
<li>Deleting a language deletes the language (<a href="https://github.com/HugoFara/lwt/issues/151">#151</a>).
Before it was setting the language to empty values.</li>
</ul>
<h4>Deprecated</h4>
<ul>
<li>PHP documentation using Doxygen (under <code>/docs/html</code>) is now deprecated and will be removed in 3.0.0.</li>
<li>Using <code>$langDefs</code> is deprecated in favor of <code>LWT_LANGUAGES_ARRAY</code> (<a href="https://github.com/HugoFara/lwt/issues/163">#163</a>).</li>
<li>Calling the global function <code>new_pos</code> to set audio position is deprecated. Please use <code>lwt_audio_controller.setPosition</code>.</li>
</ul>
<h3>2.9.0-fork (December 24 2023)</h3>
<h4>Added in 2.9.0-fork</h4>
Expand Down
95 changes: 45 additions & 50 deletions edit_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ function edit_languages_refresh($lid): string
{
global $tbpref;
$message2 = runsql(
'delete from ' . $tbpref . 'sentences where SeLgID = ' . $lid,
"DELETE FROM {$tbpref}sentences where SeLgID = $lid",
"Sentences deleted"
);
$message3 = runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2LgID = ' . $lid,
"DELETE FROM {$tbpref}textitems2 where Ti2LgID = $lid",
"Text items deleted"
);
adjust_autoincr('sentences', 'SeID');
Expand All @@ -97,14 +97,14 @@ function edit_languages_refresh($lid): string
$message = $message2 .
" / " . $message3 .
" / Sentences added: " . get_first_value(
'select count(*) as value
from ' . $tbpref . 'sentences
where SeLgID = ' . $lid
"SELECT count(*) as value
FROM {$tbpref}sentences
where SeLgID = $lid"
) .
" / Text items added: " . get_first_value(
'select count(*) as value
from ' . $tbpref . 'textitems2
where Ti2LgID = ' . $lid
"SELECT count(*) as value
FROM {$tbpref}textitems2
where Ti2LgID = $lid"
);
return $message;
}
Expand All @@ -124,36 +124,31 @@ function edit_languages_delete($lid): string
{
global $tbpref;
$anztexts = get_first_value(
'select count(TxID) as value
from ' . $tbpref . 'texts
where TxLgID = ' . $lid
"SELECT count(TxID) as value
FROM {$tbpref}texts
where TxLgID = $lid"
);
$anzarchtexts = get_first_value(
'select count(AtID) as value
from ' . $tbpref . 'archivedtexts
where AtLgID = ' . $lid
"SELECT count(AtID) as value
FROM {$tbpref}archivedtexts
where AtLgID = $lid"
);
$anzwords = get_first_value(
'select count(WoID) as value
from ' . $tbpref . 'words
where WoLgID = ' . $lid
"SELECT count(WoID) as value
FROM {$tbpref}words
where WoLgID = $lid"
);
$anzfeeds = get_first_value(
'select count(NfID) as value
from ' . $tbpref . 'newsfeeds
where NfLgID = ' . $lid
"SELECT count(NfID) as value
FROM {$tbpref}newsfeeds
where NfLgID = $lid"
);
if ($anztexts > 0 || $anzarchtexts > 0 || $anzwords > 0 || $anzfeeds > 0) {
$message = 'You must first delete texts, archived texts, newsfeeds and words with this language!';
} else {
$message = runsql(
'UPDATE ' . $tbpref . 'languages
SET LgName = "", LgDict1URI = "", LgDict2URI = "",
LgGoogleTranslateURI = "", LgExportTemplate = "", LgTextSize = DEFAULT,
LgCharacterSubstitutions = "", LgRegexpSplitSentences = "",
LgExceptionsSplitSentences = "", LgRegexpWordCharacters = "",
LgRemoveSpaces = DEFAULT, LgSplitEachChar = DEFAULT,
LgRightToLeft = DEFAULT where LgID = ' . $lid,
"DELETE FROM {$tbpref}languages
WHERE LgID = $lid",
"Deleted"
);
}
Expand Down Expand Up @@ -281,11 +276,11 @@ function edit_languages_op_change($lid): string

if ($needReParse) {
runsql(
'delete from ' . $tbpref . 'sentences where SeLgID = ' . $lid,
"DELETE FROM {$tbpref}sentences where SeLgID = $lid",
"Sentences deleted"
);
runsql(
'delete from ' . $tbpref . 'textitems2 where Ti2LgID = ' . $lid,
"DELETE FROM {$tbpref}textitems2 where Ti2LgID = $lid",
"Text items deleted"
);
adjust_autoincr('sentences', 'SeID');
Expand Down Expand Up @@ -1099,9 +1094,9 @@ function edit_languages_display($message)
$current = (int) getSetting('currentlanguage');

$recno = get_first_value(
'SELECT COUNT(*) AS value
FROM ' . $tbpref . 'languages
WHERE LgName<>""'
"SELECT COUNT(*) AS value
FROM {$tbpref}languages
WHERE LgName<>''"
);

?>
Expand Down Expand Up @@ -1136,28 +1131,28 @@ function edit_languages_display($message)

<?php

$sql = 'SELECT LgID, LgName, LgExportTemplate
FROM ' . $tbpref . 'languages
WHERE LgName<>"" ORDER BY LgName';
$sql = "SELECT LgID, LgName, LgExportTemplate
FROM {$tbpref}languages
WHERE LgName<>'' ORDER BY LgName";
if ($debug) {
echo $sql;
}
// May be refactored with KISS principle
$res = do_mysqli_query(
'select NfLgID, count(*) as value
from ' . $tbpref . 'newsfeeds
group by NfLgID'
"SELECT NfLgID, count(*) as value
FROM {$tbpref}newsfeeds
group by NfLgID"
);
$newsfeedcount = null;
while ($record = mysqli_fetch_assoc($res)) {
$newsfeedcount[$record['NfLgID']] = $record['value'];
}
// May be refactored with KISS principle
$res = do_mysqli_query(
'SELECT NfLgID, count(*) AS value
FROM ' . $tbpref . 'newsfeeds, ' . $tbpref . 'feedlinks
"SELECT NfLgID, count(*) AS value
FROM {$tbpref}newsfeeds, {$tbpref}feedlinks
WHERE NfID=FlNfID
GROUP BY NfLgID'
GROUP BY NfLgID"
);
$feedarticlescount = null;
while ($record = mysqli_fetch_assoc($res)) {
Expand All @@ -1167,21 +1162,21 @@ function edit_languages_display($message)
while ($record = mysqli_fetch_assoc($res)) {
$lid = (int)$record['LgID'];
$foo = get_first_value(
'select count(TxID) as value
from ' . $tbpref . 'texts
where TxLgID=' . $lid
"SELECT count(TxID) as value
FROM {$tbpref}texts
where TxLgID = $lid"
);
$textcount = is_numeric($foo) ? (int)$foo : 0;
$foo = get_first_value(
'select count(AtID) as value
from ' . $tbpref . 'archivedtexts
where AtLgID=' . $lid
"SELECT count(AtID) as value
FROM {$tbpref}archivedtexts
where AtLgID = $lid"
);
$archtextcount = is_numeric($foo) ? (int)$foo : 0;
$foo = get_first_value(
'select count(WoID) as value
from ' . $tbpref . 'words
where WoLgID=' . $lid
"SELECT count(WoID) as value
FROM {$tbpref}words
where WoLgID = $lid"
);
$wordcount = is_numeric($foo) ? (int)$foo : 0;
if (is_null($newsfeedcount)) {
Expand Down
Loading

0 comments on commit f80e26d

Please sign in to comment.