From dc0fdbf73df4b99c6e0f9c0c09f616a81f995771 Mon Sep 17 00:00:00 2001 From: Nikiroy78 <35032449+Nikiroy78@users.noreply.github.com> Date: Wed, 8 Mar 2023 01:10:34 +0300 Subject: [PATCH] Add files via upload --- api/components/api-out.php | 7 ++ api/components/config.php | 3 + api/components/database-controller.php | 47 +++++++++ api/components/database.db | 0 api/components/get-history.php | 16 ++++ api/get_history.php | 7 ++ api/wrong_symbols.find.php | 128 +++++++++++++++++++++++++ database.db | Bin 0 -> 24576 bytes index.php | 114 ++++++++++++++++++++++ 9 files changed, 322 insertions(+) create mode 100644 api/components/api-out.php create mode 100644 api/components/config.php create mode 100644 api/components/database-controller.php create mode 100644 api/components/database.db create mode 100644 api/components/get-history.php create mode 100644 api/get_history.php create mode 100644 api/wrong_symbols.find.php create mode 100644 database.db create mode 100644 index.php diff --git a/api/components/api-out.php b/api/components/api-out.php new file mode 100644 index 0000000..1f1c7b4 --- /dev/null +++ b/api/components/api-out.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/api/components/config.php b/api/components/config.php new file mode 100644 index 0000000..7767919 --- /dev/null +++ b/api/components/config.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/api/components/database-controller.php b/api/components/database-controller.php new file mode 100644 index 0000000..8365fd9 --- /dev/null +++ b/api/components/database-controller.php @@ -0,0 +1,47 @@ +query('SELECT date, hash, text FROM history;'); + $list = array(); + while ($row = $results->fetchArray()) { + // var_dump($row); + $list[] = '['. $row['date'] .']: ('. $row['hash'] .'): '. $row['text']; + } + + return $list; +} + +function saveHistory ($md5, $text) { + global $db; + + $stmt = $db->prepare("INSERT INTO history (date, hash, text) VALUES (:time, :hash, :text);"); + //if (!$stmt) print_r("fail: " . $db->lastErrorMsg()); + $stmt->bindParam(':hash', $md5, SQLITE3_TEXT); + $stmt->bindParam(':text', $text, SQLITE3_TEXT); + $stmt->bindParam(':time', time(), SQLITE3_INTEGER); + + $stmt->execute(); +} + +function saveResult ($md5, $text, $result) { + global $db; + + $stmt = $db->prepare("INSERT INTO results (hash, result) VALUES (:md5Val, :result);"); + //if (!$stmt) print_r("fail: " . $db->lastErrorMsg()); + $stmt->bindParam(':md5Val', $md5, SQLITE3_TEXT); + $stmt->bindParam(':result', json_encode($result), SQLITE3_TEXT); + + $stmt->execute(); + + saveHistory($md5, $text); +} + +function getResultFromMd5 ($md5, $lang) { + return "NO"; +} + +?> \ No newline at end of file diff --git a/api/components/database.db b/api/components/database.db new file mode 100644 index 0000000..e69de29 diff --git a/api/components/get-history.php b/api/components/get-history.php new file mode 100644 index 0000000..cdc232e --- /dev/null +++ b/api/components/get-history.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/api/get_history.php b/api/get_history.php new file mode 100644 index 0000000..4c26305 --- /dev/null +++ b/api/get_history.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/api/wrong_symbols.find.php b/api/wrong_symbols.find.php new file mode 100644 index 0000000..3c72ebf --- /dev/null +++ b/api/wrong_symbols.find.php @@ -0,0 +1,128 @@ += 0.5 || count(selectRuIndex($text)) == strlen($text) ? "ru_RU" : "en_US"; +} + +function selectEnIndex ($text) { + $enSymbols = array(); + // $textArr = explode(" ", $text); + // $textArr = str_split($text, 1); + $text = iconv("UTF-8", "windows-1251", $text); + $textArr = str_split($text, 1); + $enDict = str_split('qwertyuiopasdfghjklzxcvbnm', 1); + // print_r($textArr); + + for ($i=0; $i <= count($textArr); $i++) { + // if (strpos('ййцукенгшщзхъфывапролджэячсмитьбюёё', mb_strtolower($text[$i])) === true) { + if (in_array(mb_strtolower($textArr[$i]), $enDict)) { + $enSymbols[] = $i; + } + } + return $enSymbols; +} + +function selectRuIndex ($text) { + $enSymbols = selectEnIndex($text); + $result = array(); + + $text = iconv("UTF-8", "windows-1251", $text); + $textArr = str_split($text, 1); + + for ($i=0; $i < count($textArr); $i++) { + if (!in_array($i, $enSymbols)) { + $result[] = $i; + } + } + + return $result; +} + +function wrong_symbol ($text, $lang) { + switch ($lang) { + case "ru_RU": + $cacheResult = getResultFromMd5(toMd5($text), "ru_RU"); + if ( + $cacheResult === "NO" + ) { + // return selectRuIndex($text); + $enSymbols = selectEnIndex($text); + $text = iconv("UTF-8", "windows-1251", $text); + $textArr = str_split($text, 1); + + $recheckSymbols = array(); + + $enDict = str_split('eopakxcyEOPAKXCBMHT', 1); + for ($i=0; $i <= count($textArr); $i++) { + if (in_array($textArr[$i], $enDict)) { + $recheckSymbols[] = $i; + } + } + + saveResult( + toMd5($text), + $text, + $recheckSymbols + ); + return $recheckSymbols; + } + else { + saveHistory(toMd5($text), $text); + return $cacheResult; + } + + case "en_US": + $cacheResult = getResultFromMd5(toMd5($text), "en_US"); + if ( + $cacheResult === "NO" + ) { + $ruSymbols = selectRuIndex($text); + $text = iconv("UTF-8", "windows-1251", $text); + $textArr = str_split($text, 1); + + $recheckSymbols = array(); + + $ruDict = str_split(iconv("UTF-8", "windows-1251", "еоракхсуЕОРАКХСВМНТ"), 1); + + for ($i=0; $i <= count($textArr); $i++) { + if (in_array($textArr[$i], $ruDict)) { + $recheckSymbols[] = $i; + } + } + + saveResult( + toMd5($text), + $text, + $recheckSymbols + ); + return $recheckSymbols; + } + else { + saveHistory(toMd5($text), $text); + return $cacheResult; + } + + default : // Определим язык и применим рекурсию + return wrong_symbol($text, detectLang($text)); + } +} + +die( + apiOut( + wrong_symbol($_GET['text'], $_GET['lang']) + ) +); + +?> \ No newline at end of file diff --git a/database.db b/database.db new file mode 100644 index 0000000000000000000000000000000000000000..b9bc58f893b74a454efbbcacc3361e8018dff77e GIT binary patch literal 24576 zcmeI3-)kII6vt-E5#GEa|;-?~ur* z(d-6VsSgn!d{cZ7@yCNd9()kgQt?Fu{{t1l3PLNTB3T6S*OQ3nZYGgHyHj7=bBB|2 z_U`x2J?As~GWXuhohdK3q?xR)t+1BqX#2HXPJ7HWHBGa?dQ;1R-w##*+it2at6AD3 zvzG_;H?@M^(De6=lEL%_gxHV(5N4hz5;zVxaaEtMV zY(Cq7_p)YdT`aFIw&cn)i`}|=PgbMJT4dHHA1_Dd9mbCJo2Fp!vNt_bn}F$BFx&Ip z?s|v&+}&h5GcB>^l39z+*2a(T?;V;P$!W_MguJ+Q^F_AaTJ3yZTv~3nR@W{q+G&tC zPHTPY_i(vb92yzPZOnFZU6alAMyr{+!mh&8PIGK$PV;nix-wZkXFe63Gv{Zf&&)^W z%xuk^nJy~snooHN&f|-(~}mLx}II>r=8~5HoNG_sM@`Pmb}>7o&SXSU-8vwDyl{^C!@Kv)aDkN z@ttbN2Nhv>vp1I1H8_6zONp={0VIF~kN^@u0!RP}AOR$R1nwIGJ>Rt-E@%%`F13ID zZSzK{R0_F6LS}m`Ahye;OCb)eAdxZkh);y3^}OFM6|}=ULmbNzR^SSY^CWisP!cLF z-=QSrF7sp9aqU@aA1-Jk+auzT3)f3r$4{uR75!GboN4v0fW zZQGKe2nmstxgJX_!URcd%dxox{ejInmC}#D|0Vyp(JqC|_dPF85*~&L^@YoWnAnsG zNRr3^ipX8xtg5=VM_dXi^(YGom$vk5MuZbv38RU{tuXX_217pFEdS3*p4&X7>P{yi zP-5Ux&f~--P^@4HO@#EE*d`=QJeXqo7JwS6{Q0Z=+k;0`kq%2P0C*8gdHQ&Ab^Xq52%i)%< zx6dk!Un=mdT`DDZ;JAVcFZ8(MQs1V&V;HoHo`mQqg`~moPltKI!__vio z{0jItltKI=_&H?|Uj$!O25|#?SsBFV!JkqFaZMDjzrjQ#6+xGEmO|-zJG$;?C_p#12gqa{g8(u?eYBt|$v9)7D$av0 z>(qnN^?)wxxWfXekLEy^by6AUO())K)!CCXYK=vShw#euy_l(jO@ zr$kxH0>v#+_cejuPEHyB7qO=!%2*31C{flzKwgQmRsnjB + + + Тестовое задание + + + + + +

Подсветка латинских символов

+ +
+
+ + +
+

+
+
+ +
+ + +
+ +
+
+ + + + \ No newline at end of file