api.php
Table of Contents
Constants
- LWT_API_RELEASE_DATE = "2023-12-29"
- LWT_API_VERSION = "0.1.1"
Functions
- send_response() : never
- Send JSON response and exit.
- endpoint_exits() : string
- Check if an API endpoint exists.
- rest_api_version() : array<string|int, string>
- Return the API version.
- media_files() : array<string|int, string>
- List the audio and video files in the media folder.
- readingConfiguration() : array<string|int, mixed>
- The way text should be read
- get_phonetic_reading() : array<string|int, string>
- Get the phonetic reading of a word based on it's language.
- get_word_test_ajax() : array<string|int, int|mixed|string>
- Retun the next word to test as JSON
- word_test_ajax() : array<string|int, mixed>
- Return the next word to test.
- tomorrow_test_count() : array<string|int, mixed>
- Return the number of reviews for tomorrow by using the suplied query.
- get_theme_path() : array<string|int, mixed>
- Get the file path using theme.
- get_texts_statistics() : array<string|int, mixed>
- Return statistics about a group of text.
- sentences_with_registred_term() : array<string|int, mixed>
- Sentences containing an input word.
- sentences_with_new_term() : array<string|int, mixed>
- Return the example sentences containing an input word.
- similar_terms() : array<string|int, mixed>
- Get terms similar to a given term.
- imported_terms() : array<string|int, mixed>
- Return the list of imported terms.
- term_translations() : array<string|int, mixed>
- Translations for a term to choose an annotation.
- unknown_get_action_type() : array<string|int, mixed>
- Error message when the provided action_type does not match anything known.
- save_setting() : array<string|int, string>
- Save a setting to the database.
- set_annotation() : array<string|int, string>
- Save the annotation for a term.
- set_audio_position() : array<string|int, string>
- Set audio position.
- set_text_position() : array<string|int, string>
- Set text reading position.
- increment_term_status() : array<string|int, string>
- Change the status of a term by one unit.
- set_term_status() : array<string|int, int|string>
- Set the status of a term.
- update_translation() : array<string|int, string>
- Edit the translation of an existing term.
- add_translation() : array<string|int, int|string>
- Create the translation for a new term.
- unknown_post_action_type() : array<string|int, string>
- Notify of an error on POST method.
- request_handler() : never
- Main handler for any provided request, while answer the result.
Constants
LWT_API_RELEASE_DATE
public
string
LWT_API_RELEASE_DATE
= "2023-12-29"
Date of the last released change of the LWT API.
LWT_API_VERSION
public
string
LWT_API_VERSION
= "0.1.1"
Version of this current LWT API.
Functions
send_response()
Send JSON response and exit.
send_response([int $status = 200 ][, mixed $data = null ]) : never
Parameters
- $status : int = 200
-
Status code to display
- $data : mixed = null
-
Any data to return
Return values
neverendpoint_exits()
Check if an API endpoint exists.
endpoint_exits(string $method, mixed $requestUri) : string
Parameters
- $method : string
-
Method name (e.g. 'GET' or 'POST')
- $requestUri : mixed
Return values
string —The first matching endpoint
rest_api_version()
Return the API version.
rest_api_version(array<string|int, mixed> $get_req) : array<string|int, string>
Parameters
- $get_req : array<string|int, mixed>
-
GET request, unnused
Tags
Return values
array<string|int, string> —JSON-encoded version
media_files()
List the audio and video files in the media folder.
media_files(array<string|int, mixed> $get_req) : array<string|int, string>
Parameters
- $get_req : array<string|int, mixed>
-
Unnused
Return values
array<string|int, string> —Path of media files
readingConfiguration()
The way text should be read
readingConfiguration(mixed $get_req) : array<string|int, mixed>
Parameters
- $get_req : mixed
Return values
array<string|int, mixed>get_phonetic_reading()
Get the phonetic reading of a word based on it's language.
get_phonetic_reading(array<string|int, mixed> $get_req) : array<string|int, string>
Parameters
- $get_req : array<string|int, mixed>
-
Array with the fields "text" and "lang" (short language name)
Tags
Return values
array<string|int, string> —JSON-encoded result
get_word_test_ajax()
Retun the next word to test as JSON
get_word_test_ajax(string $testsql, bool $word_mode, int $lgid, string $wordregex, int $testtype) : array<string|int, int|mixed|string>
Parameters
- $testsql : string
-
SQL projection query
- $word_mode : bool
-
Test is in word mode
- $lgid : int
-
Language ID
- $wordregex : string
-
Word selection regular expression
- $testtype : int
-
Test type
Tags
Return values
array<string|int, int|mixed|string> —Next word formatted as an array.
word_test_ajax()
Return the next word to test.
word_test_ajax(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Array with the fields { test_key: string, selection: string, word_mode: bool, lg_id: int, word_regex: string, type: int }
Return values
array<string|int, mixed> —Next word formatted as JSON.
tomorrow_test_count()
Return the number of reviews for tomorrow by using the suplied query.
tomorrow_test_count(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Array with the fields "test_key" and "selection"
Tags
Return values
array<string|int, mixed> —JSON-encoded result
get_theme_path()
Get the file path using theme.
get_theme_path(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with field "path", relative filepath using theme.
Tags
Return values
array<string|int, mixed> —JSON-encoded result
get_texts_statistics()
Return statistics about a group of text.
get_texts_statistics(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with field "texts_id", texts ID.
Return values
array<string|int, mixed>sentences_with_registred_term()
Sentences containing an input word.
sentences_with_registred_term(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with fields "lg_id", "word_lc" and "word_id".
Return values
array<string|int, mixed>sentences_with_new_term()
Return the example sentences containing an input word.
sentences_with_new_term(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with fields "lg_id" and "advanced_search" (optional).
Return values
array<string|int, mixed>similar_terms()
Get terms similar to a given term.
similar_terms(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with fields "lg_id" and "term".
Tags
Return values
array<string|int, mixed> —Similar terms in HTML format.
imported_terms()
Return the list of imported terms.
imported_terms(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with fields "last_update", "page" and "count".
Return values
array<string|int, mixed>term_translations()
Translations for a term to choose an annotation.
term_translations(array<string|int, mixed> $get_req) : array<string|int, mixed>
Parameters
- $get_req : array<string|int, mixed>
-
Get request with fields "text_id" and "term_lc".
Return values
array<string|int, mixed>unknown_get_action_type()
Error message when the provided action_type does not match anything known.
unknown_get_action_type(mixed $get_req[, bool $action_exists = false ]) : array<string|int, mixed>
Parameters
- $get_req : mixed
- $action_exists : bool = false
-
Set to true if the action is recognized but not the action_type
Tags
Return values
array<string|int, mixed> —JSON-encoded error message.
save_setting()
Save a setting to the database.
save_setting(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "key" (setting name) and "value"
Tags
Return values
array<string|int, string> —Setting save status
set_annotation()
Save the annotation for a term.
set_annotation(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Post request with keys "text_id", "elem" and "data".
Tags
Return values
array<string|int, string> —JSON-encoded result
set_audio_position()
Set audio position.
set_audio_position(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "text_id" (int) and "position"
Tags
Return values
array<string|int, string> —Success message
set_text_position()
Set text reading position.
set_text_position(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "text_id" (int) and "position"
Tags
Return values
array<string|int, string> —Success message
increment_term_status()
Change the status of a term by one unit.
increment_term_status(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "term_id" (int) and "status_up" (1 or 0)
Tags
Return values
array<string|int, string> —Status message
set_term_status()
Set the status of a term.
set_term_status(array<string|int, mixed> $post_req) : array<string|int, int|string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "term_id" (int) and "status" (0-5|98|99)
Tags
Return values
array<string|int, int|string>update_translation()
Edit the translation of an existing term.
update_translation(array<string|int, mixed> $post_req) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "term_id" (int) and "translation".
Tags
Return values
array<string|int, string> —Term in lower case, or "" if term does not exist
add_translation()
Create the translation for a new term.
add_translation(array<string|int, mixed> $post_req) : array<string|int, int|string>
Parameters
- $post_req : array<string|int, mixed>
-
Array with the fields "term_text", "lg_id" (int) and "translation".
Tags
Return values
array<string|int, int|string> —Error message in case of failure, lowercase term otherwise
unknown_post_action_type()
Notify of an error on POST method.
unknown_post_action_type(array<string|int, mixed> $post_req[, bool $action_exists = false ]) : array<string|int, string>
Parameters
- $post_req : array<string|int, mixed>
-
POST request used
- $action_exists : bool = false
-
Set to true if the action is recognized but not the action_type
Tags
Return values
array<string|int, string> —JSON-encoded error message
request_handler()
Main handler for any provided request, while answer the result.
request_handler(string $method, mixed $requestUri, array<string|int, mixed>|null $post_param) : never
Parameters
- $method : string
-
Method name (e.g. 'GET' or 'POST')
- $requestUri : mixed
- $post_param : array<string|int, mixed>|null
-
Post arguments, usually equal to $_POST