Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**************************************************************
- "Learning with Texts" (LWT) is free and unencumbered software
- released into the PUBLIC DOMAIN.
- Anyone is free to copy, modify, publish, use, compile, sell, or
- distribute this software, either in source code form or as a
- compiled binary, for any purpose, commercial or non-commercial,
- and by any means.
- In jurisdictions that recognize copyright laws, the author or
- authors of this software dedicate any and all copyright
- interest in the software to the public domain. We make this
- dedication for the benefit of the public at large and to the
- detriment of our heirs and successors. We intend this
- dedication to be an overt act of relinquishment in perpetuity
- of all present and future rights to this software under
- copyright law.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
- AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE
- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- For more information, please refer to [http://unlicense.org/].
- ***************************************************************/
- require_once( 'settings.inc.php' );
- require_once( 'connect.inc.php' );
- require_once( 'dbutils.inc.php' );
- require_once( 'utilities.inc.php' );
- $ok = FALSE;
- $from = trim(stripTheSlashesIfNeeded($_REQUEST["sl"]));
- $dest = trim(stripTheSlashesIfNeeded($_REQUEST["tl"]));
- $phrase = mb_strtolower(trim(stripTheSlashesIfNeeded($_REQUEST["text"])), 'UTF-8');
- pagestart_nobody('');
- //$titletext = '<a href="https://translate.google.com/?ie=UTF-8&sl=' . $from . '&tl=' . $dest . '&text=' . $phrase . '">Google Translate (' . tohtml($from) . "-" . tohtml($dest) . "): <span class=\"red2\">" . tohtml($phrase) . "</span></a>";
- $titletext = 'Google Translate (' . tohtml($from) . "-" . tohtml($dest) . "): <span class=\"red2\">" . tohtml($phrase) . "</span>";
- echo '<h3>' . $titletext . '</h3>';
- echo '<p>(Click on <img src="icn/tick-button.png" title="Choose" alt="Choose" /> to copy word(s) into above term)<br /> </p>';
- ?>
- <script type="text/javascript">
- //<![CDATA[
- function addTranslation (s) {
- var w = window.parent.frames['ro'];
- if (typeof w == 'undefined') w = window.opener;
- if (typeof w == 'undefined') {
- alert ('Translation can not be copied!');
- return;
- }
- var c = w.document.forms[0].WoTranslation;
- if (typeof c != 'object') {
- alert ('Translation can not be copied!');
- return;
- }
- var oldValue = c.value;
- if (oldValue.trim() == '') {
- c.value = s;
- w.makeDirty();
- }
- else {
- if (oldValue.indexOf(s) == -1) {
- c.value = oldValue + ' / ' + s;
- w.makeDirty();
- }
- else {
- if (confirm('"' + s + '" seems already to exist as a translation.\nInsert anyway?')) {
- c.value = oldValue + ' / ' + s;
- w.makeDirty();
- }
- }
- }
- }
- //]]>
- </script>
- <?php
- if ($from != '' && $dest != '' && $phrase != '') {
- $ggl_data = file_get_contents('https://translate.googleapis.com/translate_a/single?client=gtx&sl=' . urlencode($from) . '&tl=' . urlencode($dest) . '&dt=t&q=' . urlencode($phrase) . '&ie=UTF-8&oe=UTF-8');
- function get_string_between($string, $start, $end){
- $string = " ".$string;
- $ini = strpos($string,$start);
- if ($ini == 0) return "";
- $ini += strlen($start);
- $len = strpos($string,$end,$ini) - $ini;
- return substr($string,$ini,$len);
- }
- $word = get_string_between($ggl_data,'[[["','","');
- if(! ($ggl_data === FALSE)) {
- $ok = TRUE;
- }
- }
- if ( $ok ) {
- if ($word != $phrase) {
- echo "<p>\n";
- $word = strtolower(trim(strip_tags($word)));
- echo '<span class="click" onclick="addTranslation(' . prepare_textdata_js($word) . ');"><img src="icn/tick-button.png" title="Copy" alt="Copy" /> ' . $word . '</span><br />' . "\n";
- echo "</p>";
- } else {
- echo '<p>No translations found (' . tohtml($from) . '-' . tohtml($dest) . ').<br /> </p>';
- }
- } else {
- echo '<p>Retrieval error (' . tohtml($from) . '-' . tohtml($dest) . '). Possible reason: Terrible code.</p>';
- }
- pageend();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement