5 $kombilo_dir = "../kombilo";
8 $q = preg_replace("/[^nsew]/", "", $_GET['q']);
11 $p = preg_replace("/[^\.OX]/", "", strtoupper($_GET['p']));
12 $a = preg_replace("/[^a-z]/", "", $_GET['a']);
16 $cache_fn = "$kombilo_dir/cache/$q-$w-$h-$p-$a";
17 if (file_exists($cache_fn)) {
19 $fp = @fopen
($cache_fn, "r");
21 $output[] = fgets($fp);
24 if ($output[0] == "") {
28 /*exec("python $kombilo_dir/search.py " .
29 escapeshellcmd($q) . " " .
30 escapeshellcmd($w) . " " .
31 escapeshellcmd($h) . " " .
32 escapeshellcmd($p) . " " .
40 $fp = fsockopen("127.0.0.1", 6060, $errno, $errstr, 10);
42 echo "$errstr ($errno)<br />\n";
45 fwrite($fp, "$q $w $h $p $a\n");
48 $output .= fgets($fp, 2048);
52 $output = split("\n", $output);
55 file_put_contents($cache_fn, join("\n", $output));
58 if (!count($output)) {
63 if (count($output) > 50) {
64 $output = array_slice($output, 0, 50);
71 foreach ($output as $line) {
72 list($fn, $pw, $wr, $pb, $br, $re, $dt, $mv) = split("\t", $line);
74 $id = str_replace(".sgf", "", $fn);
75 $mv = split(",", $mv);
76 $mv = (int)$mv[count($mv)-2];
77 array_push($results, array(
87 $odd = $odd ?
false : true;
90 $json = new Services_JSON();
91 echo $json->encode($results);