commit dc0fdbf73df4b99c6e0f9c0c09f616a81f995771 Author: Nikiroy78 <35032449+Nikiroy78@users.noreply.github.com> Date: Wed Mar 8 01:10:34 2023 +0300 Add files via upload 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 0000000..b9bc58f Binary files /dev/null and b/database.db differ diff --git a/index.php b/index.php new file mode 100644 index 0000000..daf7f7a --- /dev/null +++ b/index.php @@ -0,0 +1,114 @@ + + + + Тестовое задание + + + + + +

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

+ +
+
+ + +
+

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