-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdict.php
100 lines (94 loc) · 2.78 KB
/
dict.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
//-----------------------------------------------------------------
// Webdict for VnOSS
// Data from HND (http://www.informatik.uni-leipzig.de/~duc/Dict/)
//
// Author: [email protected]
// Date: Sun Jan 8 17:40:22 CET 2006
//-----------------------------------------------------------------
// dict.php?q=QUERYSTRING&d=EN_VI&max=NUM&fmt=FORMAT
//
include('dict_functions.php');
include('dict_config.php');
$db = mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error());
mysql_select_db($dbname) or die('Could not select database');
$query = "SET NAMES 'UTF8'";
mysql_query($query,$db);
$max=20;
//------------------------------
function return_PHP($res){
$words = array();
while($row = mysql_fetch_row($res)){
$words[] = '"'.$row[0].'"';
}
$out = implode(",",$words);
$out = '$ACList = Array ('.$out.');';
return $out;
}
function return_JS($res){
global $dict,$DICT;
$words = array();
while($row = mysql_fetch_row($res)){
$words[] = '"'.$row[0].'"';
}
$out = implode(",",$words);
$out = 'showACDiv("'.$_key.'", "'.$DICT[$dict].'", new Array('.$out.'));';
return $out;
}
function return_HTML($res){
$words = array();
while($row = mysql_fetch_row($res)){
$words[] = '<div class="ACList">'.$row[0].'</div>';
}
$out = implode("\n",$words);
return $out;
}
function return_TXT($res,$sep){
$words = array();
while($row = mysql_fetch_row($res)){
$words[] = $row[0];
}
$out = implode($sep,$words);
return $out;
}
function return_XML($res){
$words = array('<?xml version="1.0" ?>','<wordlist>');
while($row = mysql_fetch_row($res)){
$words[] = '<item>'.$row[0].'</item>';
}
$words[] = '</wordlist>';
$out = implode("\n",$words);
return $out;
}
//$DICTS = array ('en_vi','vi_en','fr_vi','vi_fr','de_vi','vi_de','no_vi','vi_vi','ru_vi');
//-------------------------------------------------------------------------------
if(isset($_GET['q']) && $_GET['q']!='' && isset($_GET['d'])){
$dict = strtolower($_GET['d']);
$fmt = strtolower($_GET['fmt']);
$fmt = isset($fmt) ? $fmt : 'js';
if (isset($_GET['max'])){
$max = $_GET['max'];
$max = ($max<0 || $max>50)?20:$max;
}
$_key = $_GET['q'];
$key = $_key.'%';
//if(!in_array($dict,$DICTS) { $dict = 'en_vi'; }
if(strlen($key)>32 OR preg_match("/\.|\/|\-\-|=/",$key)){ exit; }
//$key = _Addslashes($key);
$out = '';
$query = 'SELECT d_word FROM '.$dict." WHERE d_word LIKE '$key' LIMIT $max";
//echo "$query\n";
$res = mysql_query($query,$db);
if($res){
switch ($fmt){
case 'xml' : $out = return_XML($res); break;
case 'html' : $out = return_HTML($res); break;
case 'txt' : $out = return_TXT($res,"\n"); break;
case 'csv' : $out = return_TXT($res,';'); break;
case 'php' : $out = return_PHP($res); break;
case 'js' :
default : $out = return_JS($res);
}
}
echo $out;
}