diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-31 09:11:20 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-31 09:11:20 +0300 |
| commit | b58f0a8f2431040edf94edb21f9c884f20ba6049 (patch) | |
| tree | b70055bf14983a59242ae27cdba75f6d39d391a3 /classes/Handler/DefineHandler.php | |
| parent | b76af33e9bfb57b46fb8d8292b614bf9ee2e3c2d (diff) | |
| download | the-epube-b58f0a8f2431040edf94edb21f9c884f20ba6049.tar.gz the-epube-b58f0a8f2431040edf94edb21f9c884f20ba6049.tar.xz | |
tabs to spaces
Diffstat (limited to 'classes/Handler/DefineHandler.php')
| -rw-r--r-- | classes/Handler/DefineHandler.php | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/classes/Handler/DefineHandler.php b/classes/Handler/DefineHandler.php index 87fd3f9..60d5b11 100644 --- a/classes/Handler/DefineHandler.php +++ b/classes/Handler/DefineHandler.php @@ -10,59 +10,59 @@ use Response; class DefineHandler implements RequestHandlerInterface, AuthRequired { - /** @return array<string> */ - private function parseDictReply(string $reply): array - { - $tmp = []; + /** @return array<string> */ + private function parseDictReply(string $reply): array + { + $tmp = []; - foreach (explode("\n", $reply) as $line) { - list($code, $message) = explode(" ", $line, 2); + foreach (explode("\n", $reply) as $line) { + list($code, $message) = explode(" ", $line, 2); - if (!$code && $message) { - array_push($tmp, $message); - } - } + if (!$code && $message) { + array_push($tmp, $message); + } + } - return $tmp; - } + return $tmp; + } - public function handle(Request $request): Response - { - if (!Config::get(Config::DICT_SERVER)) { - return (new Response())->withBody(json_encode(["result" => ["Dictionary lookups are disabled."]])); - } + public function handle(Request $request): Response + { + if (!Config::get(Config::DICT_SERVER)) { + return (new Response())->withBody(json_encode(["result" => ["Dictionary lookups are disabled."]])); + } - $word = strip_tags(str_replace("", "", $request->getAttribute('word'))); - $origWord = $word; - $result = []; + $word = strip_tags(str_replace("", "", $request->getAttribute('word'))); + $origWord = $word; + $result = []; - for ($i = 0; $i < 3; $i++) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, sprintf("dict://%s/define:%s", Config::get(Config::DICT_SERVER), $word)); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $dictReply = curl_exec($ch); + for ($i = 0; $i < 3; $i++) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, sprintf("dict://%s/define:%s", Config::get(Config::DICT_SERVER), $word)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $dictReply = curl_exec($ch); - if ($dictReply) { - $retParsed = $this->parseDictReply($dictReply); + if ($dictReply) { + $retParsed = $this->parseDictReply($dictReply); - if (count($retParsed) > 0) { - array_push($result, "<strong>$word</strong>"); - $result = array_merge($result, $retParsed); - break; - } else { - $word = mb_substr($word, 0, mb_strlen($word) - 1); - } - } else { - array_push($result, curl_error($ch)); - } + if (count($retParsed) > 0) { + array_push($result, "<strong>$word</strong>"); + $result = array_merge($result, $retParsed); + break; + } else { + $word = mb_substr($word, 0, mb_strlen($word) - 1); + } + } else { + array_push($result, curl_error($ch)); + } - curl_close($ch); - } + curl_close($ch); + } - if (count($result) == 0) { - array_push($result, "No results for: <b>$origWord</b>"); - } + if (count($result) == 0) { + array_push($result, "No results for: <b>$origWord</b>"); + } - return (new Response())->withBody(json_encode(["result" => $result])); - } + return (new Response())->withBody(json_encode(["result" => $result])); + } } |
