commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
class ort implements module { |
|
3 |
static function register_cmd() { |
|
4 |
return array( |
|
5 |
'o' => 'cmd_ort', |
|
6 |
'ort' => 'cmd_ort', |
|
7 |
); |
|
8 |
} |
|
9 |
|
|
10 |
static function help($cmd=NULL) { |
|
11 |
if($cmd === NULL) { |
|
12 |
GGapi::putRichText('ort ', TRUE); |
|
13 |
GGapi::putRichText('słowo', FALSE, TRUE); |
|
14 |
GGapi::putRichText("\n".' Słownik ortograficzny'."\n"); |
|
15 |
} |
|
16 |
else |
|
17 |
{ |
|
18 |
GGapi::putRichText('ort ', TRUE); |
|
19 |
GGapi::putRichText('słowo', FALSE, TRUE); |
|
20 |
GGapi::putRichText(' (alias: '); |
|
21 |
GGapi::putRichText('o', TRUE); |
|
22 |
GGapi::putRichText(')'."\n".' Sprawdza w słowniku ortograficznym '); |
|
23 |
GGapi::putRichText('słowo', FALSE, TRUE); |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
27 |
static function cmd_ort($name, $arg) { |
|
28 |
if(empty($arg)) { |
|
29 |
GGapi::putText('Funkcja '); |
|
30 |
GGapi::putRichText('ort', TRUE); |
|
31 |
GGapi::putRichText(' wymaga argumentu '); |
|
32 |
GGapi::putRichText('slowo'."\n\n", FALSE, TRUE); |
|
33 |
GGapi::putRichText('Przykłady', FALSE, FALSE, TRUE); |
|
34 |
GGapi::putRichText("\n".'ort grzegżółka'."\n".'ort warsawa'); |
|
35 |
|
|
36 |
return; |
|
37 |
} |
|
38 |
|
|
39 |
$proc = proc_open('aspell --lang=pl --encoding=utf-8 --ignore-case=true pipe', array(array('pipe', 'r'), array('pipe', 'w'), array('file', '/dev/null', 'w')), $pipe); |
|
40 |
|
|
41 |
fwrite($pipe[0], trim($arg)."\n"); |
|
42 |
fclose($pipe[0]); |
|
43 |
|
|
44 |
$status = proc_get_status($proc); |
|
45 |
while($status['running']) { |
|
46 |
usleep(1); |
|
47 |
$status = proc_get_status($proc); |
|
48 |
} |
|
49 |
|
|
50 |
fgets($pipe[1], 1024); |
|
51 |
$spell = fread($pipe[1], 4096); |
|
52 |
|
|
53 |
if(substr($spell, 0, 1)=='*') { |
|
54 |
GGapi::putRichText('Pisownia poprawna', FALSE, FALSE, FALSE, 0, 150, 0); |
|
55 |
} |
|
56 |
elseif(substr($spell, 0, 1)=='#') { |
|
57 |
GGapi::putText('Brak propozycji poprawnej pisowni'); |
|
58 |
} |
|
59 |
else |
|
60 |
{ |
|
61 |
$spell = explode(': ', $spell, 2); |
|
62 |
$spell = explode(',', $spell[1]); |
|
63 |
|
|
64 |
$txt = 'Prawdopobnie chodziło ci o:'; |
|
65 |
foreach($spell as $val) { |
|
66 |
$txt .= "\n".'- '.trim($val); |
|
67 |
} |
|
68 |
|
|
69 |
GGapi::putText($txt); |
|
70 |
} |
|
71 |
|
|
72 |
fclose($pipe[1]); |
|
73 |
proc_close($proc); |
|
74 |
} |
|
75 |
} |
|
76 |
?> |