about summary refs log tree commit diff stats
path: root/classes/Handler/DefineHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Handler/DefineHandler.php')
-rw-r--r--classes/Handler/DefineHandler.php88
1 files changed, 44 insertions, 44 deletions
diff --git a/classes/Handler/DefineHandler.php b/classes/Handler/DefineHandler.php
index 60d5b11..87fd3f9 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]));
+	}
 }