Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brand committed May 31, 2022
0 parents commit baadd51
Show file tree
Hide file tree
Showing 46 changed files with 5,376 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");

module.exports = {
"root": true,
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-prettier"
],
"env": {
"vue/setup-compiler-macros": true
}
}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist-ssr
coverage
*.local

public

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Autoplay vocabulary

This application will help you repeat and remember words of the language you learn.<br>
Being a learner of English, I am convinced that the first words you need to learn are the words that you couldn't remember in your last talk.
90% that you will need those words again shortly in your next conversations. Having those words learned, you will be more confident.<br>
In my app, you should add new words yourself. I recommend using the Collins dictionary or the Cambridge dictionary in order to find explanations and ways of using the words.
https://www.collinsdictionary.com/ and https://dictionary.cambridge.org/ respectively.<br>
Whenever you're adding a new word, its mirror translation will be added automatically.<br>
After you have added words, you have the next features:
1. <b>The tab Repeat.</b><br>
This tab consists of the words that you are supposed to have remembered the best. You can use this tab just for repeating words.<br>
By looking at a word, you have to recall its translation in your mind. Then you can check yourself by pressing on the original word.<br>
If you can't remember a word, you can move it to the Study tab by pressing the button "Learn".<br>
If you don't remember a word, but don't want to move it to the Study tab, you can put it in the queue for repeating in the future by pressing the button "Repeat".
2. <b>The tab Study.</b><br>
This tab consists of the words that you are studying. After adding a word, it'll appear on this tab first.<br>
By looking at a word, you have to recall its translation in your mind. Then you can check yourself by pressing on the original word.<br>
When you think that you have remembered a word strongly, you can move this word to the Repeat tab by pressing the button "I know".<br>
If you don't remember a word, press the button "Learn".
3. <b>The tab Forget.</b><br>
This tab comprises all the words from the tab Study, but the words are shown as one list. You can use this tab for quick looks at the list if you need.
4. <b>The tab Play.</b><br>
This is the most incredible tab of the app. It plays your words automatically in circles. It means that you can relax, run, walk and repeat your words along the way. All the words will be pronounced by the app. After pronouncing a word, you have 5 seconds to recall its translation in your mind. After 5 seconds the app will pronounce the translation.<br>
This tab has a big button "Learn". You can press this button for moving a word to the tab "Study".

Each tab will fetch new words one by one until they are in the queue for drilling. Then the app will shuffle the words and start fetching them again.<br>
Look at several screenshots from the app:
![Screenshots](/screenshots.jpg)

## Quick start if you are a learner

If you are just a learner, you shouldn't dive deeply into the source. All that you need is the dist folder and a PHP+MySQL hosting.
You have to complete the next steps:
1. Copy all the files from the dist folder to your hosting server.
2. Create a database and run dump.sql.
3. Put the credentials from your database into the api/_init.php file.
4. Define login and password in order to get access to the app.
5. To get your words pronounced, you have to obtain the X-Goog-Api-Key from the Text-to-Speach feature by Google. Look at the screenshot below:
![Text to speach credentials](/text-to-speach.jpg)

That's it. You don't need to read the rest information on this page if you are not a developer and don't want to contribute to the project.

## Project Setup

If you want to improve the app, do the next:
```sh
npm install
```

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin).
40 changes: 40 additions & 0 deletions dist/api/_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

unset($_REQUEST['HTTP_SESSION_VARS']);
unset($_REQUEST['_SESSION']);
unset($_REQUEST['_SERVER']);

session_start();

$defLogin = ''; //learner's login
$defPwd = ''; //learner's password

$dbhost = "localhost"; //Host of server DB
$dbusername = ""; //Login for connection to DB server
$dbpassword = ""; //Password for connection to DB server
$dbname = "_autoplay_vocabulary"; //DB name
if (($_SERVER['REMOTE_ADDR'] == "127.0.0.1") || ($_SERVER['REMOTE_ADDR'] == "::1")) {//use this block for your local web server
$dbhost = "localhost"; //DB host for local servers
$dbusername = ""; //DB login for local servers
$dbpassword = ""; //DB password for local servers
$dbname = "_autoplay_vocabulary"; //DB name for local servers
}

$googleApiKey = '';//Text-to-speach google api key

$regularWordsTable = "regular_words"; //the table for regular words
$advancedWordsTable = "advanced_words"; //the table for advanced words

if ($_COOKIE['autoplay_vocabulary'] == 1) {
$_SESSION['site']['login'] = $defLogin;
$_SESSION['site']['pwd'] = $defPwd;
}

$dbHandler = @mysqli_connect($dbhost, $dbusername, $dbpassword);
if ($dbHandler !== false) {
if (mysqli_select_db($dbHandler, $dbname)) mysqli_set_charset($dbHandler, "utf8mb4"); else die(json_encode(['error' => ["message" => "Can't choose the DB"]]));
} else die(json_encode(['error' => ["message" => "Can't connect to the MySQL DB server"]]));

$inputData = json_decode(file_get_contents('php://input'), 1);
$workTable = ($inputData['appMode']) ? $advancedWordsTable : $regularWordsTable;

124 changes: 124 additions & 0 deletions dist/api/addeditword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

require_once("_init.php");

$res = [];
$res['new'] = 0;
$res['newWordWithDuplicate'] = [];
$pr_magic = ini_get('magic_quotes_gpc');

foreach ($inputData as $key => $value) {
$inputData[$key] = trim($value);
if (!$pr_magic) $inputData[$key] = addslashes($inputData[$key]);
}

if ($inputData['idToConnectWith']) {//если получили подтверждение объединения
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where id='".$inputData['idToConnectWith']."'");
$rowi = mysqli_fetch_assoc($resulti);
$isEnglish = ord($rowi['word']);
$isEnglish = (($isEnglish >= 65 && $isEnglish <= 90) || ($isEnglish >= 97 && $isEnglish <= 122)) ? true : false;
$j = 0;
for ($i = 1; $i <= 5; $i++) {
if ($rowi['v'.$i]) $j++;
}
$query = "update {$workTable} set id='".$rowi['id']."'";
for ($i = 1; $i <= 5; $i++) {
$j++;
if ($inputData['translate'.$i]) $query .= ", v".$j."='".mb_strtolower($inputData['translate'.$i])."'";
if ($inputData['description'.$i]) $query .= ", v".$j."d='".$inputData['description'.$i]."'";
if (!$isEnglish) {
if ($inputData['wordtype'.$i]) $query .= ", wordtype".$j."='".$inputData['wordtype'.$i]."'";
}
}
$query .= " where id='".$inputData['idToConnectWith']."'";
$res['query'] = $query;
mysqli_query($dbHandler, $query);
if ($inputData['wordId']) {
mysqli_query($dbHandler, "delete from {$workTable} where id='".$inputData['wordId']."'");
}
$res['status'] = "success";
} else {
if ($inputData['word'] && $inputData['translate1']) {
$existingWord = [];
if (!$inputData['wordId']) {
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where word='".$inputData['word']."'");
if ($resulti) {
$rowi = mysqli_fetch_assoc($resulti);
if ($rowi['id']) $existingWord = $rowi;
}
} else {
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where word='".$inputData['word']."' and id!='".$inputData['wordId']."'");
if ($resulti) {
$rowi = mysqli_fetch_assoc($resulti);
if ($rowi['id']) $existingWord = $rowi;
}
}

if ($existingWord['id']) {
$res['existingWord'] = $existingWord;
$res['existingWord']['forword'] = $inputData['word'];
}

if (!$existingWord['id']) {
$isEnglish = ord($inputData['word']);
$isEnglish = (($isEnglish >= 65 && $isEnglish <= 90) || ($isEnglish >= 97 && $isEnglish <= 122)) ? true : false;
if ($inputData['wordId'] > 0) $query = "update {$workTable} set word='".mb_strtolower($inputData['word'])."'"; else {
$query = "insert into {$workTable} set word='".mb_strtolower($inputData['word'])."'";
}
if ($inputData['wordtype']) $query .= ", wordtype='".$inputData['wordtype']."'";
for ($i = 1; $i <= 5; $i++) {
if ($inputData['translate'.$i]) $query .= ", v".$i."='".mb_strtolower($inputData['translate'.$i])."'";
if ($inputData['description'.$i]) $query .= ", v".$i."d='".$inputData['description'.$i]."'";
if (!$isEnglish) {
if ($inputData['wordtype'.$i]) $query .= ", wordtype".$i."='".$inputData['wordtype'.$i]."'";
}
}
if ($inputData['wordId']) {
$query .= " where id='".$inputData['wordId']."' ";
} else {
$resulti = mysqli_query($dbHandler, "select max(random_order) as random_order from {$workTable}");
$rowi = mysqli_fetch_assoc($resulti);
$maxRandomOrder = $rowi['random_order'] + 1;
$query .= ", random_order='".$maxRandomOrder."'";
$res['cntNewWords'] = 1;
}
mysqli_query($dbHandler, $query);

if (!$inputData['wordId']) {//if a new word, add it vice versa
for ($i = 1; $i <= 5; $i++) {
if ($inputData['translate'.$i]) {
$postFix = "";
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where word='".$inputData['translate'.$i]."'");
if ($resulti) {
$rowi = mysqli_fetch_assoc($resulti);
if ($rowi['count'] > 0) $postFix .= " ".($rowi['count'] + 1).'v';
}

$query = "insert into {$workTable} set word='".mb_strtolower($inputData['translate'.$i].$postFix)."'";
$query .= ", v1='".mb_strtolower($inputData['word'])."'";
if ($inputData['description'.$i]) $query .= ", v1d='".$inputData['description'.$i]."'";
if ($isEnglish) {
if ($inputData['wordtype'.$i]) $query .= ", wordtype1='".$inputData['wordtype'.$i]."'";
}
$maxRandomOrder++;
$query .= ", random_order='".$maxRandomOrder."'";
mysqli_query($dbHandler, $query);
$res['cntNewWords']++;
if ($postFix) {
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where word='".$inputData['translate'.$i]."'");
$rowi = mysqli_fetch_assoc($resulti);
$res['newWordWithDuplicate'] = $rowi;
}
}
}
}

$res['status'] = "success";
if (!$inputData['wordId']) {
$res['new'] = 1;
}
}
}
}

echo(json_encode($res));
9 changes: 9 additions & 0 deletions dist/api/deleteword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

require_once("_init.php");

if ($inputData['wordId']) {
$resulti = mysqli_query($dbHandler, "delete from {$workTable} where id='".$inputData['wordId']."'");
}

echo(json_encode([]));
23 changes: 23 additions & 0 deletions dist/api/getforgottenwords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

require_once("_init.php");

$res['words'] = array();
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where study=1 and done=0 and word RLIKE '^[a-zA-Z]' order by random_order asc");
$enWords = mysqli_fetch_all($resulti, MYSQLI_ASSOC);
if ($enWords) $res['words'] = array_merge($res['words'], $enWords);
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where study=1 and done=0 and word NOT RLIKE '^[a-zA-Z]' order by random_order asc");
$ruWords = mysqli_fetch_all($resulti, MYSQLI_ASSOC);
if ($ruWords) $res['words'] = array_merge($res['words'], $ruWords);

/*$res['ilist'] = array();
$result = mysqli_query($dbHandler, "select * from {$workTable} where study=0 and done=0 and ord>0 and advanced='".$advanced."' and word RLIKE '^[a-zA-Z]' order by ord desc");
while ($row = mysqli_fetch_assoc($result)) {
$res['ilist'][] = $row;
}
$result = mysqli_query($dbHandler, "select * from {$workTable} where study=0 and done=0 and ord>0 and advanced='".$advanced."' and word NOT RLIKE '^[a-zA-Z]' order by ord desc");
while ($row = mysqli_fetch_assoc($result)) {
$res['ilist'][] = $row;
}*/

echo(json_encode($res));
13 changes: 13 additions & 0 deletions dist/api/getplayedwordsstatistic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once("_init.php");

if ($_SESSION['site']['login'] === $defLogin) {
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable}");
$cntAllWords = mysqli_fetch_array($resulti)['count'];

$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where auto>0");
$cntWordsToPlay = mysqli_fetch_array($resulti)['count'];
}

echo(json_encode(["cntWordsToPlay" => $cntWordsToPlay, "cntAllWords" => $cntAllWords]));
25 changes: 25 additions & 0 deletions dist/api/getstatistics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

require_once("_init.php");

if ($_SESSION['site']['login'] === $defLogin) {
//quantity of all the words
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable}");
if ($resulti) $cntAllWords = mysqli_fetch_array($resulti)['count']; else die(json_encode(['error' => ["message" => "Some problem with the table ".$workTable.""]]));

//quantity of en - words
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where word RLIKE '^[a-zA-Z]'");
if ($resulti) $cntEnWords = mysqli_fetch_array($resulti)['count']; else die(json_encode(['error' => ["message" => "Some problem with the table ".$workTable.""]]));

//quantity of repeated words
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where study=0 and done=1");
if ($resulti) $cntRepeatedWords = mysqli_fetch_array($resulti)['count']; else die(json_encode(['error' => ["message" => "Some problem with the table ".$workTable.""]]));

//quantity of words to study
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where study=1");
if ($resulti) $cntWordsToStudy = mysqli_fetch_array($resulti)['count']; else die(json_encode(['error' => ["message" => "Some problem with the table ".$workTable.""]]));
} else {
die(json_encode([]));
}

echo(json_encode(["cntAllWords" => $cntAllWords, 'cntEnWords' => $cntEnWords, 'cntRepeatedWords' => $cntRepeatedWords, 'cntWordsToStudy' => $cntWordsToStudy, 'isUser' => ($_SESSION['site']['login'] === $defLogin)]));
37 changes: 37 additions & 0 deletions dist/api/getword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once("_init.php");

$study = $inputData['study'] ?: 0;
$res = [];
$res['status'] = 'continue';
$res['mess'] = null;
//retrieve a next random word to repeat
$resulti = mysqli_query($dbHandler, "select count(id) as count from {$workTable} where study={$study}");
$rowi = mysqli_fetch_assoc($resulti);
if ($rowi['count'] > 0) {
do {
$resulti = mysqli_query($dbHandler, "select * from {$workTable} where study={$study} and done=0 order by random_order limit 1");
if ($resulti) {
$rowi = mysqli_fetch_assoc($resulti);
if (!$rowi['id']) {//если все повторили, начинаем заново
$resulti = mysqli_query($dbHandler, "select max(id) as maxid from {$workTable}");
$rowi = mysqli_fetch_assoc($resulti);
$numbers = range(1, $rowi['maxid']);
shuffle($numbers);
for ($i = 1; $i <= $rowi['maxid']; $i++) {
mysqli_query($dbHandler, "update {$workTable} set random_order='".$numbers[($i - 1)]."' where id='".$i."' and study={$study}");
}
mysqli_query($dbHandler, "update {$workTable} set done='0' where study={$study}");
$res['mess'] = "Well done! You're the hero!";
}
} else {
break;
}
} while (!$rowi['id']);
} else {
$res['mess'] = "No words to repeat!";
$res['status'] = 'stop';
}

echo(json_encode($rowi + $res));
7 changes: 7 additions & 0 deletions dist/api/iknow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

require_once("_init.php");

if ($inputData['wordId']) {
mysqli_query($dbHandler, "update {$workTable} set done=1 where id='".$inputData['wordId']."'");
}
10 changes: 10 additions & 0 deletions dist/api/learn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

require_once("_init.php");

if ($inputData['wordId']) {
$resulti = mysqli_query($dbHandler, "select max(random_order) as random_order from {$workTable}");
$rowi = mysqli_fetch_assoc($resulti);
$maxRandomOrder = $rowi['random_order']+1;
mysqli_query($dbHandler, "update {$workTable} set done=0, study=1, random_order='".$maxRandomOrder."' where id='".$inputData['wordId']."'");
}
Loading

0 comments on commit baadd51

Please sign in to comment.