Skip to content

Commit e5cb1de

Browse files
author
LWT Project
committed
Version 1.5.5 (20-Jun-2013 11:47)
1 parent dd9ecf9 commit e5cb1de

3 files changed

Lines changed: 106 additions & 27 deletions

File tree

‎glosbe_api.php‎

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
$phrase = mb_strtolower(trim(stripTheSlashesIfNeeded($_REQUEST["phrase"])), 'UTF-8');
3131
$ok = FALSE;
3232

33+
pagestart_nobody('');
34+
$titeltext = '<a href="http://glosbe.com/' . $from . '/' . $dest . '/' . $phrase . '" Dictionary (' . tohtml($from) . "-" . tohtml($dest) . "): &nbsp; <span class=\"red2\">" . tohtml($phrase) . "</span></a>";
35+
echo '<h3>' . $titeltext . '</h3>';
36+
echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br />&nbsp;</p>';
37+
3338
if ($from != '' && $dest != '' && $phrase != '') {
3439

3540
$glosbe_data = file_get_contents('http://glosbe.com/gapi/translate?from=' . urlencode($from) . '&dest=' . urlencode($dest) . '&format=json&phrase=' . urlencode($phrase));
@@ -47,35 +52,105 @@
4752

4853
if ( $ok ) {
4954

50-
echo "<h1>" . tohtml($data['phrase']) . "</h1>\n";
51-
5255
if (count($data['tuc']) > 0) {
56+
57+
$i = 0;
5358

54-
echo "<p>Translations:</p>\n<ul>\n";
59+
echo "<p>\n";
5560
foreach ($data['tuc'] as &$value) {
61+
$word = '';
5662
if (isset($value['phrase'])) {
5763
if (isset($value['phrase']['text']))
58-
echo "<li>" . $value['phrase']['text'] . "</li>\n";
64+
$word = $value['phrase']['text'];
5965
} else if (isset($value['meanings'])) {
6066
if (isset($value['meanings'][0]['text']))
61-
echo "<li>(" . $value['meanings'][0]['text'] . ")</li>\n";
67+
$word = $value['meanings'][0]['text'];
68+
}
69+
if ($word != '') {
70+
echo '<span class="click" onclick=""><img src="icn/tick-button.png" title="Copy" alt="Copy" /></span> &nbsp;' . $word . '<br />' . "\n";
71+
$i++;
6272
}
6373
}
64-
echo "</ul>\n<hr />\n<pre>\n";
74+
echo "</p>";
75+
/*
76+
echo "\n<hr />\n<pre>\n";
6577
print_r($data['tuc']);
6678
echo "</pre>\n";
79+
*/
80+
if ($i) {
81+
echo '<p>&nbsp;<br/>' . $i . ' translation' . ($i==1 ? '' : 's') . ' retrieved via <a href="http://glosbe.com/a-api" API</a>.</p>';
82+
}
6783

6884
} else {
85+
86+
echo '<p>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').<br />&nbsp;</p>';
87+
88+
if ($dest != "en" && $from != "en") {
89+
90+
$ok = FALSE;
91+
92+
$dest = "en";
93+
$titeltext = '<a href="http://glosbe.com/' . $from . '/' . $dest . '/' . $phrase . '" Dictionary (' . tohtml($from) . "-" . tohtml($dest) . "): &nbsp; <span class=\"red2\">" . tohtml($phrase) . "</span></a>";
94+
echo '<hr /><p>&nbsp;</p><h3>' . $titeltext . '</h3>';
95+
96+
$glosbe_data = file_get_contents('http://glosbe.com/gapi/translate?from=' . urlencode($from) . '&dest=' . urlencode($dest) . '&format=json&phrase=' . urlencode($phrase));
97+
98+
if(! ($glosbe_data === FALSE)) {
99+
100+
$data = json_decode ($glosbe_data, true);
101+
if ( isset($data['phrase']) ) {
102+
$ok = (($data['phrase'] == $phrase) && (isset($data['tuc'])));
103+
}
104+
105+
}
106+
107+
if ( $ok ) {
108+
109+
if (count($data['tuc']) > 0) {
110+
111+
$i = 0;
112+
113+
echo "<p>&nbsp;<br />\n";
114+
foreach ($data['tuc'] as &$value) {
115+
$word = '';
116+
if (isset($value['phrase'])) {
117+
if (isset($value['phrase']['text']))
118+
$word = $value['phrase']['text'];
119+
} else if (isset($value['meanings'])) {
120+
if (isset($value['meanings'][0]['text']))
121+
$word = $value['meanings'][0]['text'];
122+
}
123+
if ($word != '') {
124+
echo '<span class="click" onclick=""><img src="icn/tick-button.png" title="Copy" alt="Copy" /></span> &nbsp;' . $word . '<br />' . "\n";
125+
$i++;
126+
}
127+
}
128+
echo "</p>";
129+
if ($i) {
130+
echo '<p>&nbsp;<br/>' . $i . ' translation' . ($i==1 ? '' : 's') . ' retrieved via <a href="http://glosbe.com/a-api" API</a>.</p>';
131+
}
132+
133+
} else {
134+
135+
echo '<p>&nbsp;<br/>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').</p>';
136+
137+
}
69138

70-
echo "<p>No translations available.</p>";
139+
} else {
140+
141+
echo '<p>&nbsp;<br/>Retrieval error (' . tohtml($from) . '-' . tohtml($dest) . ').</p>';
142+
143+
}
144+
}
71145

72146
}
73147

74148
} else {
75149

76-
echo "<h1>" . tohtml($phrase) . "</h1>\n";
77-
echo "<p>No data available or retrieval error./p>";
150+
echo '<p>Retrieval error (' . tohtml($from) . '-' . tohtml($dest) . ').</p>';
78151

79152
}
80153

154+
pageend();
155+
81156
?>

‎js/pgm.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,15 @@ function owin(url) {
364364
window.open(
365365
url,
366366
'dictwin',
367-
'width=600, height=400, scrollbars=yes, menubar=no, resizable=yes, status=no'
367+
'width=800, height=400, scrollbars=yes, menubar=no, resizable=yes, status=no'
368368
);
369369
}
370370

371371
function oewin(url) {
372372
window.open(
373373
url,
374374
'editwin',
375-
'width=600, height=600, scrollbars=yes, menubar=no, resizable=yes, status=no'
375+
'width=800, height=600, scrollbars=yes, menubar=no, resizable=yes, status=no'
376376
);
377377
}
378378

@@ -390,11 +390,11 @@ function createTheDictLink(u,w,t,b) {
390390
var txtbefore = b.trim();
391391
var r = '';
392392
if (url != '' && txt != '') {
393-
if(url.substr(0,8) == '*http://') {
393+
if(url.substr(0,1) == '*') {
394394
r = ' ' + txtbefore +
395395
' <span class=\x22click\x22 onclick=\x22owin(\'' + createTheDictUrl(url.substring(1),escape_apostrophes(trm)) + '\');\x22>' + txt + '</span> ';
396396
}
397-
else if (url.substr(0,7) == 'http://') {
397+
else {
398398
r = ' ' + txtbefore +
399399
' <a href=\x22' + createTheDictUrl(url,trm) + '\x22> + txt + '</a> ';
400400
}

‎utilities.inc.php‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,10 +1694,10 @@ function createDictLinksInEditWin($lang,$word,$sentctljs,$openfirst) {
16941694
function makeOpenDictStr($url, $txt) {
16951695
$r = '';
16961696
if ($url != '' && $txt != '') {
1697-
if(substr($url,0,8) == '*http://') {
1697+
if(substr($url,0,1) == '*') {
16981698
$r = ' <span class="click" onclick="owin(' . prepare_textdata_js(substr($url,1)) . ');">' . tohtml($txt) . '</span> ';
16991699
}
1700-
elseif (substr($url,0,7) == 'http://') {
1700+
else {
17011701
$r = ' <a href="' . $url . '">' . tohtml($txt) . '</a> ';
17021702
}
17031703
}
@@ -1709,10 +1709,10 @@ function makeOpenDictStr($url, $txt) {
17091709
function makeOpenDictStrJS($url) {
17101710
$r = '';
17111711
if ($url != '') {
1712-
if(substr($url,0,8) == '*http://') {
1712+
if(substr($url,0,1) == '*') {
17131713
$r = "owin(" . prepare_textdata_js(substr($url,1)) . ");\n";
17141714
}
1715-
elseif (substr($url,0,7) == 'http://') {
1715+
else {
17161716
$r = "top.frames['ru'].location.href=" . prepare_textdata_js($url) . ";\n";
17171717
}
17181718
}
@@ -1724,10 +1724,10 @@ function makeOpenDictStrJS($url) {
17241724
function makeOpenDictStrDynSent($url, $sentctljs, $txt) {
17251725
$r = '';
17261726
if ($url != '') {
1727-
if(substr($url,0,8) == '*http://') {
1727+
if(substr($url,0,1) == '*') {
17281728
$r = '<span class="click" onclick="translateSentence2(' . prepare_textdata_js(substr($url,1)) . ',' . $sentctljs . ');">' . tohtml($txt) . '</span>';
17291729
}
1730-
elseif (substr($url,0,7) == 'http://') {
1730+
else {
17311731
$r = '<span class="click" onclick="translateSentence(' . prepare_textdata_js($url) . ',' . $sentctljs . ');">' . tohtml($txt) . '</span>';
17321732
}
17331733
}
@@ -2672,12 +2672,14 @@ function LWTTableCheck () {
26722672
// -------------------------------------------------------------
26732673

26742674
function LWTTableSet ($key, $val) {
2675+
LWTTableCheck ();
26752676
runsql("INSERT INTO _lwtgeneral (LWTKey, LWTValue) VALUES (" . convert_string_to_sqlsyntax($key) . ", " . convert_string_to_sqlsyntax($val) . ") ON DUPLICATE KEY UPDATE LWTValue = " . convert_string_to_sqlsyntax($val),'');
26762677
}
26772678

26782679
// -------------------------------------------------------------
26792680

26802681
function LWTTableGet ($key) {
2682+
LWTTableCheck ();
26812683
return get_first_value("SELECT LWTValue as value FROM _lwtgeneral WHERE LWTKey = " . convert_string_to_sqlsyntax($key));
26822684
}
26832685

@@ -3168,16 +3170,17 @@ function check_update_db() {
31683170
$err = @mysql_select_db($dbname);
31693171
if ($err == FALSE) die('DB select error (Cannot find database: "'. $dbname . '" or connection parameter $dbname is wrong; please create database and/or correct file: "connect.inc.php"). Hint: The database can be created by importing the file "dbinstall.sql" within phpMyAdmin. Please read the documentation: http://lwt.sf.net');
31703172

3171-
// Is $tbpref set in connect.inc.php? Take it.
3172-
// If not: Is it set in table "_lwtgeneral"? Take it.
3173-
// If not: Use $tbpref = '' (no prefix, old/standard behaviour).
3174-
3175-
// $fixed_tbpref = 1 if $tbpref was fixed in connect.inc.php.
3173+
// *** GLOBAL VARAIABLES ***
3174+
// $tbpref = Current Table Prefix
3175+
// $fixed_tbpref = Table Prefix is fixed, no changes possible
3176+
// *** GLOBAL VARAIABLES ***
31763177

3177-
LWTTableCheck();
3178+
// Is $tbpref set in connect.inc.php? Take it and $fixed_tbpref=1.
3179+
// If not: $fixed_tbpref=0. Is it set in table "_lwtgeneral"? Take it.
3180+
// If not: Use $tbpref = '' (no prefix, old/standard behaviour).
31783181

31793182
if (! isset($tbpref)) {
3180-
$fixed_tbpref = 0;
3183+
$fixed_tbpref = 0;
31813184
$p = LWTTableGet("current_table_prefix");
31823185
if (isset($p))
31833186
$tbpref = $p;
@@ -3195,7 +3198,8 @@ function check_update_db() {
31953198
if (strpos("_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", substr($tbpref,$i,1)) === FALSE) die('Table prefix/set "' . $tbpref . '" contains characters or digits other than 0-9, a-z, A-Z or _. Please fix in "connect.inc.php".');
31963199
}
31973200

3198-
LWTTableSet ("current_table_prefix", $tbpref);
3201+
if (! $fixed_tbpref)
3202+
LWTTableSet ("current_table_prefix", $tbpref);
31993203

32003204
// *******************************************************************
32013205
// IF PREFIX IS NOT '', THEN ADD A '_', TO ENSURE NO IDENTICAL NAMES

0 commit comments

Comments
 (0)