Documentation

session_utility.php

\file \brief All the files needed for a LWT session.

By requiring this file, you start a session, connect to the database and declare a lot of useful functions.

PHP version 8.1

Tags
author

HugoFara hugo.farajallah@protonmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/files/inc-session-utility.html
since
2.0.3-fork

Table of Contents

Functions

getPreviousAndNextTextLinks()  : string
Return navigation arrows to previous and next texts.
echo_lwt_logo()  : void
Return an HTML formatted logo of the application.
getprefixes()  : array<string|int, string>
Return all different database prefixes that are in use.
media_paths_search()  : array<string|int, array<string|int, mixed>>
Return the list of media files found in folder, recursively.
get_media_paths()  : array<string|int, mixed>
Return the paths for all media files.
selectmediapathoptions()  : string
Get the different options to display as acceptable media files.
selectmediapath()  : string
Select the path for a media (audio or video).
get_seconds_selectoptions()  : string
get_playbackrate_selectoptions()  : string
remove_soft_hyphens()  : string|array<string|int, string>
replace_supp_unicode_planes_char()  : null|string|array<string|int, string>
makeCounterWithTotal()  : string
encodeURI()  : string
print_file_path()  : void
Echo the path of a file using the theme directory. Echo the base file name of file is not found
get_file_path()  : string
Get the path of a file using the theme directory
get_sepas()  : mixed
get_first_sepa()  : mixed
get_mobile_display_mode_selectoptions()  : string
Prepare options for mobile.
get_sentence_count_selectoptions()  : string
get_words_to_do_buttons_selectoptions()  : string
get_regex_selectoptions()  : string
get_tooltip_selectoptions()  : string
get_themes_selectoptions()  : string
processSessParam()  : string|int
Get a session value and update it if necessary.
processDBParam()  : string|int
Get a database value and update it if necessary.
getWordTagList()  : string
get_last_key()  : int
Return the last inserted ID in the database
get_checked()  : string
If $value is true, return an HTML-style checked attribute.
get_selected()  : string
Return an HTML attribute if $value is equal to $selval.
do_test_test_get_projection()  : string
Create a projection operator do perform word test.
do_test_test_from_selection()  : string
Prepare the SQL when the text is a selection.
make_status_controls_test_table()  : string
Make the plus and minus controls in a test table for a word.
get_languages_selectoptions()  : string
Return options as HTML code to insert in a language select.
get_languagessize_selectoptions()  : string
get_wordstatus_radiooptions()  : string
get_wordstatus_selectoptions()  : string
get_annotation_position_selectoptions()  : string
get_hts_selectoptions()  : string
get_paging_selectoptions()  : string
get_wordssort_selectoptions()  : string
get_tagsort_selectoptions()  : string
get_textssort_selectoptions()  : string
get_andor_selectoptions()  : string
get_set_status_option()  : string
get_status_name()  : string
get_status_abbr()  : string
get_colored_status_msg()  : string
get_multiplewordsactions_selectoptions()  : string
get_multipletagsactions_selectoptions()  : string
get_allwordsactions_selectoptions()  : string
get_alltagsactions_selectoptions()  : string
get_multipletextactions_selectoptions()  : string
get_multiplearchivedtextactions_selectoptions()  : string
get_texts_selectoptions()  : string
makePager()  : void
Makes HTML content for a text of style "Page 1 of 3".
makeStatusCondition()  : string
checkStatusRange()  : bool
makeStatusClassFilter()  : string
Adds HTML attributes to create a filter over words learning status.
makeStatusClassFilterHelper()  : void
Replace $status in $array by -1
createTheDictLink()  : string
Create and verify a dictionary URL link
createDictLinksInEditWin()  : string
Returns dictionnary links formatted as HTML.
makeOpenDictStr()  : string
Create a dictionnary open URL from an pseudo-URL
makeOpenDictStrJS()  : string
makeOpenDictStrDynSent()  : string
Create a dictionnary open URL from an pseudo-URL
createDictLinksInEditWin2()  : string
Returns dictionnary links formatted as HTML.
makeDictLinks()  : string
createDictLinksInEditWin3()  : string
checkTest()  : string
Return checked attribute if $val is in array $_REQUEST[$name]
strToHex()  : string
strToClassName()  : string
Escapes everything to "¤xx" but not 0-9, a-z, A-Z, and unicode >= (hex 00A5, dec 165)
anki_export()  : never
tsv_export()  : never
flexible_export()  : never
mask_term_in_sentence_v2()  : string
repl_tab_nl()  : string
Replace all white space characters by a simple space ' '.
mask_term_in_sentence()  : string
return_textwordcount()  : array<string|int, array<string|int, array<string|int, float|int|null|string>|float|int|null|string>>
Return statistics about a list of text ID.
textwordcount()  : void
Compute and echo word statistics about a list of text ID.
todo_words_count()  : int
Return the number of words left to do in this text.
todo_words_content()  : string
Prepare HTML interactions for the words left to do in this text.
texttodocount2()  : string
Prepare HTML interactions for the words left to do in this text.
sentences_containing_word_lc_query()  : string
Return a SQL string to find sentences containing a word.
sentences_from_word()  : mysqli_result|true
Perform a SQL query to find sentences containing a word.
getSentence()  : array<string|int, string>
Format the sentence(s) $seid containing $wordlc highlighting $wordlc.
sentences_with_word()  : array<string|int, array<string|int, string>>
Return sentences containing a word.
example_sentences_area()  : void
Prepare the area to for examples sentences of a word.
get20Sentences()  : string
Show 20 sentences containg $wordlc.
get_languages()  : array<string, int>
Return a dictionary of languages name - id
getLanguage()  : string
Get language name from its ID
getLanguageCode()  : string
Try to get language code from its ID
getScriptDirectionTag()  : string
Return a right-to-left direction indication in HTML if language is right-to-left.
findMecabExpression()  : array<string|int, array<string|int, int|string>>
Find all occurences of an expression using MeCab.
insert_expression_from_mecab()  : array<string|int, array<string|int, string>>
Insert an expression to the database using MeCab.
insertExpressionFromMeCab()  : array{: string[], : string[]}
Insert an expression to the database using MeCab.
findStandardExpression()  : array<string|int, array<string|int, int|null|string>>
Find all occurences of an expression, do not use parsers like MeCab.
insert_standard_expression()  : array<string|int, array<string|int, null|string>>
Insert an expression without using a tool like MeCab.
new_expression_interactable()  : void
Prepare a JavaScript dialog to insert a new expression. Use elements in global JavaScript scope.
new_expression_interactable2()  : void
Prepare a JavaScript dialog to insert a new expression.
newMultiWordInteractable()  : void
Prepare a JavaScript dialog to insert a new expression.
insertExpressions()  : null|string
Alter the database to add a new word
restore_file()  : string
Restore the database from a file.
recreate_save_ann()  : string
Uses provided annotations, and annotations from database to update annotations.
create_ann()  : string
Create new annotations for a text.
create_save_ann()  : string
truncateUserDatabase()  : void
Truncate the database, remove all data belonging by the current user.
process_term()  : string
get_first_translation()  : string
get_annotation_link()  : string
trim_value()  : void
Like trim, but in place (modify variable)
phoneticReading()  : string
Parses text be read by an automatic audio player.
phonetic_reading()  : string
Parses text be read by an automatic audio player.
refreshText()  : string
Refresh a text.
makeMediaPlayer()  : void
Create an HTML media player, audio or video.
makeVideoPlayer()  : void
Create an embed video player
makeAudioPlayer()  : void
Create an HTML audio player.
framesetheader()  : void
Echo a HEAD tag for using with frames
pagestart()  : void
Write a page header and start writing its body.
pagestart_nobody()  : void
Start a standard page with a complete header and a non-closed body.

Functions

Return navigation arrows to previous and next texts.

getPreviousAndNextTextLinks(int $textid, string $url, bool $onlyann, string $add) : string
Parameters
$textid : int

ID of the current text

$url : string

Base URL to append before $textid

$onlyann : bool

Restrict to annotated texts only

$add : string

Some content to add before the output

Return values
string

Arrows to previous and next texts.

Return an HTML formatted logo of the application.

echo_lwt_logo() : void
Tags
since
2.7.0

Do no longer indicate database prefix in logo

getprefixes()

Return all different database prefixes that are in use.

getprefixes() : array<string|int, string>
Tags
psalm-return

list

Return values
array<string|int, string>

A list of prefixes.

Return the list of media files found in folder, recursively.

media_paths_search(string $dir) : array<string|int, array<string|int, mixed>>
Parameters
$dir : string

Directory to search into.

Tags
psalm-return

array{paths: array, folders: array}

Return values
array<string|int, array<string|int, mixed>>

All paths found (matching files and folders) in "paths" and folders in "folders".

get_media_paths()

Return the paths for all media files.

get_media_paths() : array<string|int, mixed>
Return values
array<string|int, mixed>

Paths of media files, in the form array<string, string>

selectmediapathoptions()

Get the different options to display as acceptable media files.

selectmediapathoptions(string $dir) : string
Parameters
$dir : string

Directory containing files

Return values
string

HTML-formatted OPTION tags

selectmediapath()

Select the path for a media (audio or video).

selectmediapath(string $f) : string
Parameters
$f : string

HTML field name for media string in form. Will be used as this.form.[$f] in JS.

Return values
string

HTML-formatted string for media selection

get_seconds_selectoptions()

get_seconds_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_playbackrate_selectoptions()

get_playbackrate_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

remove_soft_hyphens()

remove_soft_hyphens(mixed $str) : string|array<string|int, string>
Parameters
$str : mixed
Tags
psalm-return

array|string

Return values
string|array<string|int, string>

replace_supp_unicode_planes_char()

replace_supp_unicode_planes_char(mixed $s) : null|string|array<string|int, string>
Parameters
$s : mixed
Tags
psalm-return

array|null|string

Return values
null|string|array<string|int, string>

makeCounterWithTotal()

makeCounterWithTotal(mixed $max, mixed $num) : string
Parameters
$max : mixed
$num : mixed
Return values
string

encodeURI()

encodeURI(mixed $url) : string
Parameters
$url : mixed
Return values
string

print_file_path()

Echo the path of a file using the theme directory. Echo the base file name of file is not found

print_file_path(string $filename) : void
Parameters
$filename : string

Filename

get_file_path()

Get the path of a file using the theme directory

get_file_path(string $filename) : string
Parameters
$filename : string

Filename

Return values
string

File path if it exists, otherwise the filename

get_mobile_display_mode_selectoptions()

Prepare options for mobile.

get_mobile_display_mode_selectoptions("0"|"1"|"2" $v) : string
Parameters
$v : "0"|"1"|"2"

Current mobile type

Return values
string

get_sentence_count_selectoptions()

get_sentence_count_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_words_to_do_buttons_selectoptions()

get_words_to_do_buttons_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_regex_selectoptions()

get_regex_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_tooltip_selectoptions()

get_tooltip_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_themes_selectoptions()

get_themes_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

processSessParam()

Get a session value and update it if necessary.

processSessParam(string $reqkey, string $sesskey, string|int $default, bool $isnum) : string|int
Parameters
$reqkey : string

If in $_REQUEST, update the session with $_REQUEST[$reqkey]

$sesskey : string

Field of the session to get or update

$default : string|int

Default value to return

$isnum : bool

If true, convert the result to an int

Return values
string|int

The required data unless $isnum is specified

processDBParam()

Get a database value and update it if necessary.

processDBParam(string $reqkey, string $dbkey, string $default, bool $isnum) : string|int
Parameters
$reqkey : string

If in $_REQUEST, update the database with $_REQUEST[$reqkey]

$dbkey : string

Field of the database to get or update

$default : string

Default value to return

$isnum : bool

If true, convert the result to an int

Return values
string|int

The string data unless $isnum is specified

getWordTagList()

getWordTagList(mixed $wid[, mixed $before = ' ' ][, mixed $brack = 1 ][, mixed $tohtml = 1 ]) : string
Parameters
$wid : mixed
$before : mixed = ' '
$brack : mixed = 1
$tohtml : mixed = 1
Return values
string

get_last_key()

Return the last inserted ID in the database

get_last_key() : int
Tags
since
2.6.0-fork

Officially returns a int in documentation, as it was the case

Return values
int

get_checked()

If $value is true, return an HTML-style checked attribute.

get_checked(mixed $value) : string
Parameters
$value : mixed

Some value that can be evaluated as a boolean

Tags
psalm-return

' checked="checked" '|''

Return values
string

' checked="checked" ' if value is true, '' otherwise

get_selected()

Return an HTML attribute if $value is equal to $selval.

get_selected(mixed $value, mixed $selval) : string
Parameters
$value : mixed
$selval : mixed
Tags
psalm-return

' selected="selected" '|''

Return values
string

''|' selected="selected" ' Depending if inputs are equal

do_test_test_get_projection()

Create a projection operator do perform word test.

do_test_test_get_projection(string $key, array<string|int, mixed>|int $value) : string
Parameters
$key : string

Type of test.

  • 'words': selection from words
  • 'texts': selection from texts
  • 'lang': selection from language
  • 'text': selection from single text
$value : array<string|int, mixed>|int

Object to select.

Tags
global

string $tbpref

Return values
string

SQL projection necessary

do_test_test_from_selection()

Prepare the SQL when the text is a selection.

do_test_test_from_selection(mixed $selection_type, string $selection_data) : string
Parameters
$selection_type : mixed
$selection_data : string

Comma separated ID of elements to test.

Return values
string

SQL formatted string suitable to projection (inserted in a "FROM ")

make_status_controls_test_table()

Make the plus and minus controls in a test table for a word.

make_status_controls_test_table(int $score, int $status, int $wordid) : string
Parameters
$score : int

Score associated to this word

$status : int

Status for this word

$wordid : int

Word ID

Return values
string

the HTML-formatted string to use

get_languages_selectoptions()

Return options as HTML code to insert in a language select.

get_languages_selectoptions(string|int|null $v, string $dt) : string
Parameters
$v : string|int|null

Selected language ID

$dt : string

Default value to display

Return values
string

get_languagessize_selectoptions()

get_languagessize_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_wordstatus_radiooptions()

get_wordstatus_radiooptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_wordstatus_selectoptions()

get_wordstatus_selectoptions(mixed $v, mixed $all, mixed $not9899[, mixed $off = true ]) : string
Parameters
$v : mixed
$all : mixed
$not9899 : mixed
$off : mixed = true
Return values
string

get_annotation_position_selectoptions()

get_annotation_position_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_hts_selectoptions()

get_hts_selectoptions(mixed $current_setting) : string
Parameters
$current_setting : mixed
Return values
string

get_paging_selectoptions()

get_paging_selectoptions(mixed $currentpage, mixed $pages) : string
Parameters
$currentpage : mixed
$pages : mixed
Return values
string

get_wordssort_selectoptions()

get_wordssort_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_tagsort_selectoptions()

get_tagsort_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_textssort_selectoptions()

get_textssort_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_andor_selectoptions()

get_andor_selectoptions(mixed $v) : string
Parameters
$v : mixed
Return values
string

get_set_status_option()

get_set_status_option(mixed $n[, mixed $suffix = "" ]) : string
Parameters
$n : mixed
$suffix : mixed = ""
Return values
string

get_status_name()

get_status_name(mixed $n) : string
Parameters
$n : mixed
Return values
string

get_status_abbr()

get_status_abbr(mixed $n) : string
Parameters
$n : mixed
Return values
string

get_colored_status_msg()

get_colored_status_msg(mixed $n) : string
Parameters
$n : mixed
Return values
string

get_multiplewordsactions_selectoptions()

get_multiplewordsactions_selectoptions() : string
Return values
string

get_multipletagsactions_selectoptions()

get_multipletagsactions_selectoptions() : string
Return values
string

get_allwordsactions_selectoptions()

get_allwordsactions_selectoptions() : string
Return values
string

get_alltagsactions_selectoptions()

get_alltagsactions_selectoptions() : string
Return values
string

get_multipletextactions_selectoptions()

get_multipletextactions_selectoptions() : string
Return values
string

get_multiplearchivedtextactions_selectoptions()

get_multiplearchivedtextactions_selectoptions() : string
Return values
string

get_texts_selectoptions()

get_texts_selectoptions(mixed $lang, mixed $v) : string
Parameters
$lang : mixed
$v : mixed
Return values
string

makePager()

Makes HTML content for a text of style "Page 1 of 3".

makePager(mixed $currentpage, mixed $pages, mixed $script, mixed $formname) : void
Parameters
$currentpage : mixed
$pages : mixed
$script : mixed
$formname : mixed

makeStatusCondition()

makeStatusCondition(mixed $fieldname, mixed $statusrange) : string
Parameters
$fieldname : mixed
$statusrange : mixed
Return values
string

checkStatusRange()

checkStatusRange(mixed $currstatus, mixed $statusrange) : bool
Parameters
$currstatus : mixed
$statusrange : mixed
Return values
bool

makeStatusClassFilter()

Adds HTML attributes to create a filter over words learning status.

makeStatusClassFilter(int<0, 5>|98|99|599 $status) : string
Parameters
$status : int<0, 5>|98|99|599

Word learning status 599 is a special status combining 5 and 99 statuses. 0 return an empty string

Return values
string

CSS class filter to exclude $status

makeStatusClassFilterHelper()

Replace $status in $array by -1

makeStatusClassFilterHelper(int $status, array<string|int, int> &$array) : void
Parameters
$status : int

A value in $array

$array : array<string|int, int>

Any array of values

Create and verify a dictionary URL link

createTheDictLink(string $u, string $t) : string

Case 1: url without any ### or lwt_term: append UTF-8-term Case 2: url with one ### or lwt_term: substitute UTF-8-term Case 3: url with two (###|lwt_term)enc###: unsupported encoding changed, abandonned since 2.6.0-fork

Parameters
$u : string

Dictionary URL. It may contain 'lwt_term' that will get parsed

$t : string

Text that substite the 'lwt_term'

Tags
since
2.7.0-fork

It is recommended to use "lwt_term" instead of "###"

Return values
string

Dictionary link formatted

createDictLinksInEditWin()

Returns dictionnary links formatted as HTML.

createDictLinksInEditWin(int $lang, string $word, string $sentctljs, bool $openfirst) : string
Parameters
$lang : int

Language ID

$word : string
$sentctljs : string
$openfirst : bool

True if we should open right frames with translation first

Tags
global

string $tbpref Database table prefix

Return values
string

HTML-formatted interface

makeOpenDictStr()

Create a dictionnary open URL from an pseudo-URL

makeOpenDictStr(string $url, string $txt) : string
Parameters
$url : string

An URL, starting with a "*" is deprecated.

  • If it contains a "popup" query, open in new window
  • Otherwise open in iframe
$txt : string

Clickable text to display

Return values
string

HTML-formatted string

makeOpenDictStrJS()

makeOpenDictStrJS(mixed $url) : string
Parameters
$url : mixed
Return values
string

makeOpenDictStrDynSent()

Create a dictionnary open URL from an pseudo-URL

makeOpenDictStrDynSent(string $url, string $sentctljs, string $txt) : string
Parameters
$url : string

A string containing at least a URL

  • If it contains the query "lwt_popup", open in Popup
  • Starts with a '*': open in pop-up window (deprecated)
  • Otherwise open in iframe
$sentctljs : string

Clickable text to display

$txt : string

Clickable text to display

Tags
since
2.7.0-fork

Supports LibreTranslate, using other string that proper URL is deprecated.

Return values
string

HTML-formatted string

createDictLinksInEditWin2()

Returns dictionnary links formatted as HTML.

createDictLinksInEditWin2(int $lang, string $sentctljs, string $wordctljs) : string
Parameters
$lang : int

Language ID

$sentctljs : string
$wordctljs : string
Tags
global

string $tbpref Database table prefix

Return values
string

HTML formatted interface

makeDictLinks(mixed $lang, mixed $wordctljs) : string
Parameters
$lang : mixed
$wordctljs : mixed
Return values
string

createDictLinksInEditWin3()

createDictLinksInEditWin3(mixed $lang, mixed $sentctljs, mixed $wordctljs) : string
Parameters
$lang : mixed
$sentctljs : mixed
$wordctljs : mixed
Return values
string

checkTest()

Return checked attribute if $val is in array $_REQUEST[$name]

checkTest(mixed $val, string $name) : string
Parameters
$val : mixed

Value to look for, needle

$name : string

Key of request haystack.

Tags
psalm-return

' '|' checked="checked" '

Return values
string

' ' of ' checked="checked" ' if the qttribute should be checked.

strToHex()

strToHex(mixed $string) : string
Parameters
$string : mixed
Return values
string

strToClassName()

Escapes everything to "¤xx" but not 0-9, a-z, A-Z, and unicode >= (hex 00A5, dec 165)

strToClassName(string $string) : string
Parameters
$string : string

String to escape

Return values
string

anki_export()

anki_export(mixed $sql) : never
Parameters
$sql : mixed
Return values
never

tsv_export()

tsv_export(mixed $sql) : never
Parameters
$sql : mixed
Return values
never

flexible_export()

flexible_export(mixed $sql) : never
Parameters
$sql : mixed
Return values
never

mask_term_in_sentence_v2()

mask_term_in_sentence_v2(mixed $s) : string
Parameters
$s : mixed
Return values
string

repl_tab_nl()

Replace all white space characters by a simple space ' '.

repl_tab_nl(string $s) : string

The output string is also trimmed.

Parameters
$s : string

String to parse

Return values
string

String with only simple whitespaces.

mask_term_in_sentence()

mask_term_in_sentence(mixed $s, mixed $regexword) : string
Parameters
$s : mixed
$regexword : mixed
Return values
string

return_textwordcount()

Return statistics about a list of text ID.

return_textwordcount(string $texts_id) : array<string|int, array<string|int, array<string|int, float|int|null|string>|float|int|null|string>>

It is useful for unknown percent with this fork.

The echo is an output array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int} Total number of words, number of expression, statistics, total unique, number of unique expressions, unique statistics

Parameters
$texts_id : string

Texts ID separated by comma

Tags
global

string $tbpref Table name prefix

psalm-return

array{total: array<float|int|string, float|int|null|string>, expr: array<float|int|string, float|int|null|string>, stat: array<float|int|string, array<float|int|string, float|int|null|string>>, totalu: array<float|int|string, float|int|null|string>, expru: array<float|int|string, float|int|null|string>, statu: array<float|int|string, array<float|int|string, float|int|null|string>>}

Return values
array<string|int, array<string|int, array<string|int, float|int|null|string>|float|int|null|string>>

Statistics under the form of an array

textwordcount()

Compute and echo word statistics about a list of text ID.

textwordcount(string $textID) : void

It is useful for unknown percent with this fork.

The echo is an output array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int} Total number of words, number of expression, statistics, total unique, number of unique expressions, unique statistics

Parameters
$textID : string

Text IDs separated by comma

Tags
global

string $tbpref Table name prefix

deprecated
2.9.0

Use return_textwordcount instead.

todo_words_count()

Return the number of words left to do in this text.

todo_words_count(int $textid) : int
Parameters
$textid : int

Text ID

Tags
global

string $tbpref

Return values
int

Number of words

todo_words_content()

Prepare HTML interactions for the words left to do in this text.

todo_words_content(int $textid) : string
Parameters
$textid : int

Text ID

Tags
global

string $tbpref

since
2.7.0-fork

Adapted to use LibreTranslate dictionary as well.

Return values
string

HTML result

texttodocount2()

Prepare HTML interactions for the words left to do in this text.

texttodocount2(string|int $textid) : string
Parameters
$textid : string|int

Text ID

Tags
since
2.7.0-fork

Adapted to use LibreTranslate dictionary as well.

deprecated

Since 2.10.0, use todo_words_content instead

Return values
string

HTML result

sentences_containing_word_lc_query()

Return a SQL string to find sentences containing a word.

sentences_containing_word_lc_query(string $wordlc, int $lid) : string
Parameters
$wordlc : string

Word to look for in lowercase

$lid : int

Language ID

Return values
string

Query in SQL format

sentences_from_word()

Perform a SQL query to find sentences containing a word.

sentences_from_word(int|null $wid, string $wordlc, int $lid[, int $limit = -1 ]) : mysqli_result|true
Parameters
$wid : int|null

Word ID or mode

  • null: use $wordlc instead, simple search
  • -1: use $wordlc with a more complex search
  • 0 or above: sentences containing $wid
$wordlc : string

Word to look for in lowercase

$lid : int

Language ID

$limit : int = -1

Maximum number of sentences to return

Return values
mysqli_result|true

Query

getSentence()

Format the sentence(s) $seid containing $wordlc highlighting $wordlc.

getSentence(int $seid, string $wordlc, int $mode) : array<string|int, string>
Parameters
$seid : int

Sentence ID

$wordlc : string

Term text in lower case

$mode : int
  • Up to 1: return only the current sentence
  • Above 1: return previous sentence and current sentence
  • Above 2: return previous, current and next sentence
Tags
global

string $tbpref Database table prefix.

psalm-return

list{string, string}

Return values
array<string|int, string>

[0]=html, word in bold, [1]=text, word in }

sentences_with_word()

Return sentences containing a word.

sentences_with_word(int $lang, string $wordlc, int|null $wid[, int|null $mode = 0 ][, int $limit = 20 ]) : array<string|int, array<string|int, string>>
Parameters
$lang : int

Language ID

$wordlc : string

Word to look for in lowercase

$wid : int|null

Word ID

  • null: use $wordlc instead, simple search
  • -1: use $wordlc with a more complex search
  • 0 or above: find sentences containing $wid
$mode : int|null = 0

Sentences to get:

  • Up to 1 is 1 sentence,
  • 2 is previous and current sentence,
  • 3 is previous, current and next one
$limit : int = 20

Maximum number of sentences to return

Tags
psalm-return

list{0?: array{0: string, 1: string},...}

Return values
array<string|int, array<string|int, string>>

Array of sentences found

example_sentences_area()

Prepare the area to for examples sentences of a word.

example_sentences_area(mixed $lang, mixed $termlc, mixed $selector, mixed $wid) : void
Parameters
$lang : mixed
$termlc : mixed
$selector : mixed
$wid : mixed

get20Sentences()

Show 20 sentences containg $wordlc.

get20Sentences(int $lang, string $wordlc, int|null $wid, string $jsctlname, int $mode) : string
Parameters
$lang : int

Language ID

$wordlc : string

Term in lower case.

$wid : int|null

Word ID

$jsctlname : string

Path for the textarea of the sentence of the word being edited.

$mode : int
  • Up to 1: return only the current sentence
  • Above 1: return previous and current sentence
  • Above 2: return previous, current and next sentence
Tags
global

string $tbpref Database table prefix

Return values
string

HTML-formatted string of which elements are candidate sentences to use.

get_languages()

Return a dictionary of languages name - id

get_languages() : array<string, int>
Return values
array<string, int>

getLanguage()

Get language name from its ID

getLanguage(string|int $lid) : string
Parameters
$lid : string|int

Language ID

Tags
global

string $tbpref Table name prefix

Return values
string

Language name

getLanguageCode()

Try to get language code from its ID

getLanguageCode(int $lg_id, array<string|int, mixed> $languages_table) : string
Parameters
$lg_id : int

Language ID

$languages_table : array<string|int, mixed>

Table of languages, usually LWT_LANGUAGES_ARRAY

Tags
global

string $tbpref

Return values
string

If found, two-letter code (e. g. BCP 47) or four-letters for the langugae. '' otherwise.

getScriptDirectionTag()

Return a right-to-left direction indication in HTML if language is right-to-left.

getScriptDirectionTag(string|int|null $lid) : string
Parameters
$lid : string|int|null

Language ID

Return values
string

' dir="rtl" '|''

findMecabExpression()

Find all occurences of an expression using MeCab.

findMecabExpression(string $text, string|int $lid) : array<string|int, array<string|int, int|string>>
Parameters
$text : string

Text to insert

$lid : string|int

Language ID

Tags
global

string $tbpref Table name prefix

psalm-return

list{0?: array{SeID: int, TxID: int, position: int, term: string},...}

Return values
array<string|int, array<string|int, int|string>>

Each found multi-word details

insert_expression_from_mecab()

Insert an expression to the database using MeCab.

insert_expression_from_mecab(string $text, string|int $lid, string|int $wid, int $len) : array<string|int, array<string|int, string>>
Parameters
$text : string

Text to insert

$lid : string|int

Language ID

$wid : string|int

Word ID

$len : int

Number of words in the expression

Tags
since
2.5.0-fork

Function added.

deprecated

Since 2.10.0 Use insertMecabExpression

global

string $tbpref Table name prefix

psalm-return

list{array<int, string>, list{0?: string,...}}

Return values
array<string|int, array<string|int, string>>

Append text and values to insert to the database

insertExpressionFromMeCab()

Insert an expression to the database using MeCab.

insertExpressionFromMeCab(string $textlc, string $lid, string $wid, int $len, int $mode) : array{: string[], : string[]}
Parameters
$textlc : string

Text to insert in lower case

$lid : string

Language ID

$wid : string

Word ID

$len : int

Number of words in the expression

$mode : int

If equal to 0, add data in the output

Tags
since
2.5.0-fork

Function deprecated. $mode is unnused, data are always returned. The second return argument is always empty array.

deprecated

Use insertMecabExpression instead.

global

string $tbpref Table name prefix

psalm-return

array{0: array<int, string>, 1: list}

Return values
array{: string[], : string[]}

Append text and SQL array.

findStandardExpression()

Find all occurences of an expression, do not use parsers like MeCab.

findStandardExpression(string $textlc, string|int $lid) : array<string|int, array<string|int, int|null|string>>
Parameters
$textlc : string

Text to insert in lower case

$lid : string|int

Language ID

Tags
global

string $tbpref Table name prefix

psalm-return

list{0?: array{SeID: int, SeTxID: int, position: int, term: null|string, term_display: null|string},...}

Return values
array<string|int, array<string|int, int|null|string>>

Each inserted mutli-word details

insert_standard_expression()

Insert an expression without using a tool like MeCab.

insert_standard_expression(string $textlc, string|int $lid, string|int $wid, int $len, mixed $mode) : array<string|int, array<string|int, null|string>>
Parameters
$textlc : string

Text to insert in lower case

$lid : string|int

Language ID

$wid : string|int

Word ID

$len : int

Number of words in the expression

$mode : mixed

Unnused

Tags
since
2.5.0-fork

Mode is unnused and data are always added to the output.

since
2.5.2-fork

Fixed multi-words insertion for languages using no space.

deprecated

Since 2.10.0-fork, use insertStandardExpression

psalm-return

list{array<int, null|string>, array<never, never>, list{0?: string,...}}

Return values
array<string|int, array<string|int, null|string>>

Append text, empty and sentence id

new_expression_interactable()

Prepare a JavaScript dialog to insert a new expression. Use elements in global JavaScript scope.

new_expression_interactable(mixed $hex, mixed $appendtext, mixed $sid, mixed $len) : void
Parameters
$hex : mixed
$appendtext : mixed
$sid : mixed
$len : mixed
Tags
deprecated

Use newMultiWordInteractable instead. The new function does not use global JS variables.

new_expression_interactable2()

Prepare a JavaScript dialog to insert a new expression.

new_expression_interactable2(string $hex, array<string|int, string> $appendtext, int $wid, int $len) : void
Parameters
$hex : string

Lowercase text, formatted version of the text.

$appendtext : array<string|int, string>

Text to append

$wid : int

Term ID

$len : int

Words count.

Tags
global

string $tbpref Database table prefix.

since
2.10.0-fork

Fixes a bug inserting wrong title in tooltip

newMultiWordInteractable()

Prepare a JavaScript dialog to insert a new expression.

newMultiWordInteractable(string $hex, array<string|int, array<string|int, string>> $multiwords, int $wid, int $len) : void
Parameters
$hex : string

Lowercase text, formatted version of the text.

$multiwords : array<string|int, array<string|int, string>>

Multi-words to happen, format [textid][position][text]

$wid : int

Term ID

$len : int

Words count.

Tags
global

string $tbpref Database table prefix.

since
2.10.0-fork

Fixes a bug inserting wrong title in tooltip

insertExpressions()

Alter the database to add a new word

insertExpressions(string $textlc, string|int $lid, mixed $wid, int $len, int $mode) : null|string
Parameters
$textlc : string

Text in lower case

$lid : string|int

Language ID

$wid : mixed
$len : int

Number of words in the expression

$mode : int

Function mode

  • 0: Default mode, do nothing special
  • 1: Runs an expresion inserter interactable
  • 2: Return the sql output
Tags
global

string $tbpref Table name prefix

Return values
null|string

If $mode == 2 return values to insert in textitems2, nothing otherwise.

restore_file()

Restore the database from a file.

restore_file(resource $handle, string $title) : string
Parameters
$handle : resource

Backup file handle

$title : string

File title

Tags
global

string $trbpref Database table prefix

global

int $debug Debug status

global

string $dbname Database name

since
2.0.3-fork

Function was broken

since
2.5.3-fork

Function repaired

since
2.7.0-fork

$handle should be an uncompressed file.

since
2.9.1-fork

It can read SQL with more or less than one instruction a line

Return values
string

Human-readable status message

recreate_save_ann()

Uses provided annotations, and annotations from database to update annotations.

recreate_save_ann(int $textid, string $oldann) : string
Parameters
$textid : int

Id of the text on which to update annotations

$oldann : string

Old annotations

Return values
string

Updated annotations for this text.

create_ann()

Create new annotations for a text.

create_ann(int $textid) : string
Parameters
$textid : int

Id of the text to create annotations for

Tags
since
2.9.0

Annotations "position" change, they are now equal to Ti2Order it was shifted by one index before.

Return values
string

Annotations for the text

create_save_ann()

create_save_ann(mixed $textid) : string
Parameters
$textid : mixed
Return values
string

truncateUserDatabase()

Truncate the database, remove all data belonging by the current user.

truncateUserDatabase() : void

Keep settings.

Tags
global

$tbpref

process_term()

process_term(mixed $nonterm, mixed $term, mixed $trans, mixed $wordid, mixed $line) : string
Parameters
$nonterm : mixed
$term : mixed
$trans : mixed
$wordid : mixed
$line : mixed
Return values
string

get_first_translation()

get_first_translation(mixed $trans) : string
Parameters
$trans : mixed
Return values
string
get_annotation_link(mixed $textid) : string
Parameters
$textid : mixed
Return values
string

trim_value()

Like trim, but in place (modify variable)

trim_value(string &$value) : void
Parameters
$value : string

Value to be trimmed

phoneticReading()

Parses text be read by an automatic audio player.

phoneticReading(string $text, string $lgid) : string

Some non-phonetic alphabet will need this, currently only Japanese is supported, using MeCab.

Parameters
$text : string

Text to be converted

$lgid : string

Language ID

Return values
string

Parsed text in a phonetic format.

phonetic_reading()

Parses text be read by an automatic audio player.

phonetic_reading(string $text, string $lang) : string

Some non-phonetic alphabet will need this, currently only Japanese is supported, using MeCab.

Parameters
$text : string

Text to be converted

$lang : string

Language code (usually BCP 47 or ISO 639-1)

Tags
since
2.9.0

Any language starting by "ja" or "jp" is considered phonetic.

Return values
string

Parsed text in a phonetic format.

refreshText()

Refresh a text.

refreshText(mixed $word, mixed $tid) : string
Parameters
$word : mixed
$tid : mixed
Tags
deprecated

No longer used, incompatible with new database system.

since
1.6.25-fork

Not compatible with the database

Return values
string

makeMediaPlayer()

Create an HTML media player, audio or video.

makeMediaPlayer(string $path[, int $offset = 0 ]) : void
Parameters
$path : string

URL or local file path

$offset : int = 0

Offset from the beginning of the video

makeVideoPlayer()

Create an embed video player

makeVideoPlayer(string $path[, int $offset = 0 ]) : void
Parameters
$path : string

URL or local file path

$offset : int = 0

Offset from the beginning of the video

makeAudioPlayer()

Create an HTML audio player.

makeAudioPlayer(string $audio[, int $offset = 0 ]) : void
Parameters
$audio : string

Audio URL

$offset : int = 0

Offset from the beginning of the video

framesetheader()

Echo a HEAD tag for using with frames

framesetheader(string $title) : void
Parameters
$title : string

Title to use

pagestart()

Write a page header and start writing its body.

pagestart(string $title, bool $close) : void
Parameters
$title : string

Title of the page

$close : bool

Set to true if you are closing the header

Tags
since
2.7.0

Show no text near the logo, page title enclosed in H1

global

bool $debug Show a DEBUG span if true

pagestart_nobody()

Start a standard page with a complete header and a non-closed body.

pagestart_nobody(string $title[, string $addcss = '' ]) : void
Parameters
$title : string

Title of the page

$addcss : string = ''

Some CSS to be embed in a style tag

Tags
global

string $tbpref The database table prefix if true

global

int $debug Show the requests if true


        
On this page

Search results