about summary refs log tree commit diff stats
path: root/backend.php
diff options
context:
space:
mode:
authorAndrew Dolgov <noreply@fakecake.org>2017-02-27 14:34:43 +0300
committerAndrew Dolgov <noreply@fakecake.org>2017-02-27 14:34:43 +0300
commitbcf8165809d732a1f5959124bb09814edd5490da (patch)
treeef8dfe4ea347f993efd36f259f5aa13b75d39903 /backend.php
parent05524168a957704eabbd3713a6d8efea9f055b80 (diff)
downloadthe-epube-bcf8165809d732a1f5959124bb09814edd5490da.tar.gz
the-epube-bcf8165809d732a1f5959124bb09814edd5490da.tar.xz
support dictd lookups on word selection
Diffstat (limited to 'backend.php')
-rw-r--r--backend.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/backend.php b/backend.php
index b7298fa..e7a7e41 100644
--- a/backend.php
+++ b/backend.php
@@ -184,6 +184,41 @@
 
 		break;
 
+	case "define":
+
+		if (defined('DICT_ENABLED') && DICT_ENABLED) {
+
+			$word = escapeshellarg($_REQUEST["word"]);
+
+			exec(DICT_CLIENT . " -h ". DICT_SERVER ." $word 2>&1", $output, $rc);
+
+			if ($rc == 0) {
+				print json_encode(["result" => $output]);
+
+			} else if ($rc == 21) {
+
+				$word_match = "";
+
+				foreach ($output as $line) {
+					if (preg_match('/^[^ ]+: *([^ ]+)$/', $line, $match)) {
+						if ($match[1]) {
+							$word_match = escapeshellarg($match[1]);
+							break;
+						}
+					}
+				}
+
+				unset($output);
+				exec(DICT_CLIENT . " -h ". DICT_SERVER ." $word_match 2>&1", $output, $rc);
+
+				if ($rc == 0) {
+					print json_encode(["result" => $output]);
+				}
+			}
+		}
+
+		break;
+
 	default:
 		header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
 		echo "Method not found.";