<?php
class GermanDatabaseHandler extends DictionaryDatabaseHandler {
public $connectionExtern;
function init(){
parent::init();
$this->username = CONFIG_DB_USER_GERMAN;
$this->password = CONFIG_DB_PWD_GERMAN;
$this->database = CONFIG_DB_NAME_GERMAN;
$extern = new ExternalConnection();
$this->connectionExtern = $extern->getConnection();
// $this->connectExtern();
}
function getConnection(){
return $this->connection;
}
// public function connectExtern(){
// $this->getConnection()Extern = new mysqli($this->servernameExternal, $this->usernameExternal, $this->passwordExternal, $this->databaseExternal);
// if ($this->getConnection()Extern->connect_error) {
// die("Connection failed: " . $this->getConnection()Extern->connect_error);
// throw new Exception("Connection failed: " . $this->getConnection()Extern->connect_error);
// }
// }
public function getTrnslations($word, $ln)
{
// $sql= "SELECT id, artikel,word,perfect,plural,translation,soundFile FROM `".$this->database."`.`$this->dictionaryTable2` where searchedWord='"
// . $word . "' limit 60";
$sqlPrime = "SELECT * FROM `$this->database`.`"
. TABLES::$dicDeFa . "` where word like '" . $word . "' or translation like '"
. $word . "' UNION (SELECT id, artikel, word, perfect,plural, hasProposition, reflexive, translation,wordType,minusRate,plusRate, youtube_link ,true as related,status,wordID,userID,insertedTime FROM bayadic_dictionary_de_fa WHERE id IN (SELECT id FROM "
. TABLES::$dicRelatedWordsDeFa . " WHERE word LIKE '" . $word . "'))";
$sqlPrime .= "UNION SELECT concat('c',id) as id,
artikel,
word,
perfect,
plural,
hasProposition,
reflexive,
translation,
wordType,
minusRate,
plusRate,
related,
status,
wordID,
userID,
youtube_link,
insertedTime
FROM " . TABLES::$dicDeFaContribution . " where (word like '" . $word . "' or translation like '" . $word . "') and status='requested' and (plusRate-minusRate > -2) limit 60";
$this->connectionExtern->query("SET NAMES utf8");
// $result = $this->getConnection()->query ( $sql ) or die ( $this->getConnection()->error );
// $result = $this->getConnection()->query($sqlPrime);
$result = $this->connectionExtern->query($sqlPrime);
if(!empty($this->connectionExtern->error)){
throw new Exception($this->connectionExtern->error);
}
if(!empty($this->getConnection()->error)){
throw new Exception($this->getConnection()->error);
}
// $result = $this->getConnection()Extern->query($sqlPrime);
if(!empty($this->getConnection()->error)){
throw new Exception($this->getConnection()->error);
}
while ($wordArray = mysqli_fetch_assoc($result)) {
$wordArrayResult[] = $wordArray;
}
if (isset($wordArrayResult) && is_array($wordArrayResult) && count($wordArrayResult) > 0 && !empty($wordArrayResult[0])) {
$this->wordArrayResult = $wordArrayResult;
$this->translated = true;
} else {
$this->isSearched($word);
$this->translated = false;
}
return $this->wordArrayResult;
}
public function makeTranslationTextMessageHtml($noHtmlTag = FALSE)
{
$translated = "";
foreach ($this->wordArrayResult as $word) {
$perfectForm = "";
if ($word['word']) {
$artikel = "";
switch (trim($word['artikel'])) {
case "n":
$artikel = "Das - ";
break;
case "m":
$artikel = "Der - ";
break;
case "f":
$artikel = "Die - ";
break;
default:
$endoftimetest = "true";
// if(substr($word['word'], -1)=="n")
// $perfectForm = "<a href='https://telegram.me/translateGerman_bot'>(</a>";
// $this->findPerfect($word)."<a href='https://telegram.me/translateGerman_bot'>)</a>";
break;
}
// if(!$this->hasUserSuggested($userId, 2))
// $perfectForm ="(perfekt)";
$translated .= " <a href='https://telegram.me/translateGerman_bot'>" . $artikel . "</a>" . "<b>" . trim($word['word']) . ":</b> " . $word['translation'] . $perfectForm . PHP_EOL;
}
}
if ($noHtmlTag)
$translated = strip_tags($translated);
return $translated . " 😊" . PHP_EOL;
}
public function findPerfect($word)
{
// if($word)
$perfect = $word['perfect'];
$word = $word['word'];
if (false && !$perfect) {
$url = "http://api.verbix.com/conjugator/html?language=deu&tableurl=http://tools.verbix.com/webverbix/personal/template.htm&verb=$word";
$contents = file_get_contents($url);
$regex = '/Participio:<\/b> <span class="normal">(.*?)<\/span>/';
preg_match($regex, $contents, $treffer, PREG_OFFSET_CAPTURE, 3);
$regex = '/Participio:<\/b> <span class="irregular">(.*?)<\/span>/';
preg_match($regex, $contents, $trefferIre, PREG_OFFSET_CAPTURE, 3);
if (!empty($treffer[1][0]) || !empty($trefferIre[1][0])) {
$perfect = $treffer[1][0];
if (empty($perfect))
$perfect = $trefferIre[1][0];
$perfect = str_replace("ä", "ä", $perfect);
$perfect = str_replace("ü", "ü", $perfect);
$perfect = str_replace("ö", "ö", $perfect);
} else
$perfect = "-";
$this->updatePerfect($word, $perfect);
}
return $perfect;
}
public function hasSoundFile($word, &$soundFile, &$foundWord)
{
// $sql = "SELECT soundFile FROM `".$this->database."`.`$this->dictionaryTable` WHERE searchedWord='".$word."'";
$sql = "SELECT soundFile FROM dictionary where searchedWord = '" . $word . "'
UNION
SELECT soundFile FROM dicusers_contribution where word like '" . $word . "'";
$this->getConnection()->query("SET NAMES utf8");
$result = $this->getConnection()->query($sql);
if(!empty($this->getConnection()->error)){
throw new Exception($this->getConnection()->error);
}
$words = mysqli_fetch_assoc($result);
$soundFile = $words['soundFile'];
// $soundFile = $sql;
// $foundWord = $words['searchedWord'];
$foundWord = $word;
if (!isset($foundWord) && isset($words['word'])) {
$foundWord = $words['word'];
}
if (!empty($words['soundFile']))
return true;
else
return false;
}
public function saveVoiceAdress($word, $soundAdress)
{
if ($this->hasSoundFile($word, $notusing, $notused2))
return false;
$sql = "UPDATE `" . $this->database . "`.`$this->dictionaryTable` SET soundFile='$soundAdress' where searchedWord= '$word'";
$this->getConnection()->query("SET NAMES utf8");
$sql = "UPDATE `" . $this->database . "`.`dicusers_contribution` SET soundFile='$soundAdress' where word= '$word'";
$this->getConnection()->query("SET NAMES utf8");
$result = $this->getConnection()->query($sql);
if(!empty($this->getConnection()->error)){
throw new Exception($this->getConnection()->error);
}
return true;
}
}
?>