Learning with Texts - Fork  2.10.0-fork
Learn foreign languages with texts
Namespaces | Functions | Variables
kernel_utility.php File Reference

Core utility functions that do not require a complete session. More...

Namespaces

 Lwt
 

Functions

 get_version ()
 
 get_version_number ()
 
 tohtml ($s)
 
 showRequest ()
 
 get_execution_time ()
 
 get_setting_data ()
 
 remove_spaces ($s, $remove)
 
 get_mecab_path ($mecab_args='')
 
 find_latin_sentence_end ($matches, $noSentenceEnd)
 
 my_die ($text)
 
 quickMenu ()
 
 pagestart_kernel_nobody ($title, $addcss='')
 
 pageend ()
 
 echodebug ($var, $text)
 
 get_statuses ()
 
 str_replace_first ($needle, $replace, $haystack)
 
 annotation_to_json ($ann)
 
 getreq ($s)
 
 getsess ($s)
 
 url_base ()
 
 make_score_random_insert_update ($type)
 
 getsqlscoreformula ($method)
 
 error_message_with_hide ($msg, $noback)
 
 langFromDict ($url)
 
 targetLangFromDict ($url)
 
 parseSQLFile ($filename)
 

Variables

const LWT_APP_VERSION '2.10.0-fork'
 
const LWT_RELEASE_DATE "2024-04-01"
 

Detailed Description

Core utility functions that do not require a complete session.

PHP version 8.1

Function Documentation

◆ annotation_to_json()

annotation_to_json (   $ann)

Convert annotations in a JSON format.

Parameters
string$annAnnotations.
Returns
string A JSON-encoded version of the annotations

◆ echodebug()

echodebug (   $var,
  $text 
)

Debug function only.

Parameters
mixed$varA printable variable to debug
string$textEchoed text in HTML page

@global bool $debug This functions doesn't do anything is $debug is false.

◆ error_message_with_hide()

error_message_with_hide (   $msg,
  $noback 
)

Display a error message vanishing after a few seconds.

Parameters
string$msgMessage to display.
bool$nobackIf true, don't display a button to go back
Returns
string HTML-formatted string for an automating vanishing message.

◆ find_latin_sentence_end()

find_latin_sentence_end (   $matches,
  $noSentenceEnd 
)

Find end-of-sentence characters in a sentence using latin alphabet.

Parameters
string[]$matchesAll the matches from a capturing regex
string$noSentenceEndIf different from '', can declare that a string a not the end of a sentence.
Returns
string $matches[0] with ends of sentences marked with \t and \r.

◆ get_execution_time()

get_execution_time ( )

Get the time since the last call

Returns
float Time sonce last call

◆ get_mecab_path()

get_mecab_path (   $mecab_args = '')

Returns path to the MeCab application. MeCab can split Japanese text word by word

Parameters
string$mecab_argsArguments to add
Returns
string OS-compatible command
Since
2.3.1-fork Much more verifications added
2.10.0-fork Support for Mac OS added

◆ get_setting_data()

get_setting_data ( )

Reload $setting_data if necessary

Returns
array $setting_data

◆ get_statuses()

get_statuses ( )

Return an associative array of all possible statuses

Returns
array<int<1, 5>|98|99, array{string, string}> Statuses, keys are 1, 2, 3, 4, 5, 98, 99. Values are associative arrays of keys abbr and name

◆ get_version()

get_version ( )

Return LWT version for humans

Version is hardcoded in this function. For instance 1.6.31 (October 03 2016)

@global bool $debug If true adds a red "DEBUG"

Returns
string Version number HTML-formatted

@psalm-return '2.9.1-fork (December 29 2023) DEBUG'|'2.9.1-fork (December 29 2023)'

◆ get_version_number()

get_version_number ( )

Return a machine readable version number.

Returns
string Machine-readable version, for instance v001.006.031 for version 1.6.31.

◆ getreq()

getreq (   $s)

Get a request when possible. Otherwise, return an empty string.

Parameters
string$sRequest key
Returns
string Trimmed request or empty string

◆ getsess()

getsess (   $s)

Get a session variable when possible. Otherwise, return an empty string.

Parameters
string$sSession variable key
Returns
string Trimmed sesseion variable or empty string

◆ getsqlscoreformula()

getsqlscoreformula (   $method)

SQL formula for computing score.

Parameters
int$methodScore for tomorrow (2), the day after it (3) or never (any value).
Returns
string SQL score computation string

@psalm-return ' GREATEST(-125, CASE WHEN WoStatus > 5 THEN 100 WHEN WoStatus = 1 THEN ROUND(-7 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 2 THEN ROUND(6.9 - 3.5 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 3 THEN ROUND(20 - 2.3 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 4 THEN ROUND(46.4 - 1.75 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 5 THEN ROUND(100 - 1.4 * DATEDIFF(NOW(),WoStatusChanged)) END)'|' GREATEST(-125, CASE WHEN WoStatus > 5 THEN 100 WHEN WoStatus = 1 THEN ROUND(-7 -7 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 2 THEN ROUND(3.4 - 3.5 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 3 THEN ROUND(17.7 - 2.3 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 4 THEN ROUND(44.65 - 1.75 * DATEDIFF(NOW(),WoStatusChanged)) WHEN WoStatus = 5 THEN ROUND(98.6 - 1.4 * DATEDIFF(NOW(),WoStatusChanged)) END)'|'0'

◆ langFromDict()

langFromDict (   $url)

Get a two-letter language code from dictionary source language.

Parameters
string$urlInput URL, usually Google Translate or LibreTranslate

◆ make_score_random_insert_update()

make_score_random_insert_update (   $type)

Make a random score for a new word.

Parameters
'iv'|'id'|'u'|string$type Type of insertion
  • 'iv': Keys only (TodayScore, Tomorrow, Random)
  • 'id': Values only
  • 'u': Key = value pairs
Returns
string SQL code to use

◆ my_die()

my_die (   $text)

Make the script crash and prints an error message

Parameters
string$textError text to output
Returns
never
Since
2.5.3-fork Add a link to the Discord community

◆ pageend()

pageend ( )

Add a closing body tag.

@global bool $debug Show the requests if true @global float $dspltime Total execution time since the PHP session started

◆ pagestart_kernel_nobody()

pagestart_kernel_nobody (   $title,
  $addcss = '' 
)

Start a page without connecting to the database with a complete header and a non-closed body.

Parameters
string$titleTitle of the page
string$addcssSome CSS to be embed in a style tag

@global string $tbpref The database table prefix if true @global int $debug Show the requests if true

◆ parseSQLFile()

parseSQLFile (   $filename)

Parse a SQL file by returning an array of the different queries it contains.

Parameters
string$filenameFile name
Returns
array

◆ quickMenu()

quickMenu ( )

Display the main menu of navigation as a dropdown

◆ remove_spaces()

remove_spaces (   $s,
  $remove 
)

Remove all spaces from a string.

Parameters
string$sInput string
string | bool$removeDo not do anything if empty or false
Returns
string String without spaces if requested.

◆ showRequest()

showRequest ( )

Echo debugging informations.

◆ str_replace_first()

str_replace_first (   $needle,
  $replace,
  $haystack 
)

Replace the first occurence of $needle in $haystack by $replace

Parameters
string$needleText to replace
string$replaceText to replace by
string$haystackInput string
Returns
string String with replaced text

◆ targetLangFromDict()

targetLangFromDict (   $url)

Get a two-letter language code from dictionary target language

Parameters
string$urlInput URL, usually Google Translate or LibreTranslate

◆ tohtml()

tohtml (   $s)

Escape special HTML characters.

Parameters
string$sString to escape.
Returns
string htmlspecialchars($s, ENT_COMPAT, "UTF-8");

◆ url_base()

url_base ( )

Get the base URL of the application

Returns
string base URL