<?php
// ini_set("max_execution_time", 0);
set_time_limit(0);// to infinity for example
include "../../classes/tools/simple_html_dom.php";
class ManuallyLoghatnamehEnglish {
private $translatedHTML;
private $resultArray ;
function __construct(){
$this->translatedHTML = "";
}
public function getResultInArray($translatedLanguage){
$html = str_get_html($this->translatedHTML);
if(empty($html))
return "";
$wordTranslation;
switch($translatedLanguage){
case "entofa" :
$mainMeanings = $html->find('div');
// get main words
foreach($mainMeanings as $div){
if($div->getAttribute("align") == "center")
$mainMean= $div->plaintext;
// $mainMean= $div;
}
// get main en to fa
// echo PHP_EOL.PHP_EOL.PHP_EOL."---------------------------------------------- look";
// $translatedAnalyze = $html->find('#EnToFaAnalyze');
// print_r($translatedAnalyze[0]->plaintext);
// echo PHP_EOL.PHP_EOL."-------------------------------------------- end";
// $htmlTranslated = $html->find('#EnToFa');
// print_r($htmlTranslated[0]);
// exit();
// print_r($htmlTranslated);
// $allWordsAndMeanings = [];
// if(isset($htmlTranslated[0]))
// $allWordsAndMeanings = $htmlTranslated[0]->find('div');
// print_r($allWordsAndMeanings);
// print_r($allWordsAndMeanings);
// $mainMean[0]->find
// $waitForTranslation = false;
// $waitForWord = true;
// $currentWord = Array();
//
// foreach($allWordsAndMeanings as $wordOrMeaning) {
// if($wordOrMeaning->getAttribute("class") == "WordA" && $waitForWord){
// $currentWord['word'] = $wordOrMeaning->plaintext;
// $waitForTranslation = true;
// $waitForWord = false;
// }
// if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
// $currentWord['mean'] = $wordOrMeaning->plaintext;
// $waitForTranslation = false;
// $waitForWord = true;
// $words[]=$currentWord;
// }
//
//
// }
// get main en to fa similar words
$htmlTranslated = $html->find('#EnToFaSimWord');
$allWordsAndMeanings = [];
if(isset($htmlTranslated[0]))
$allWordsAndMeanings = $htmlTranslated[0]->find('div');
$waitForTranslation = false;
$waitForWord = true;
$currentWord = Array();
foreach($allWordsAndMeanings as $wordOrMeaning) {
if($wordOrMeaning->getAttribute("class") == "WordA" && $waitForWord){
$currentWord['word'] = $wordOrMeaning->plaintext;
$waitForTranslation = true;
$waitForWord = false;
}
if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
$currentWord['mean'] = $wordOrMeaning->plaintext;
$waitForTranslation = false;
$waitForWord = true;
$simWords[]=$currentWord;
}
}
// get main en to fa similar experession
$htmlTranslated = $html->find('#EnToFaSimExp');
$allWordsAndMeanings = [];
if(isset($htmlTranslated[0]))
$allWordsAndMeanings = $htmlTranslated[0]->find('div');
$waitForTranslation = false;
$waitForWord = true;
$currentWord = Array();
foreach($allWordsAndMeanings as $wordOrMeaning) {
if($wordOrMeaning->getAttribute("class") == "WordA" && $waitForWord){
$currentWord['word'] = $wordOrMeaning->plaintext;
$waitForTranslation = true;
$waitForWord = false;
}
if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
$currentWord['mean'] = $wordOrMeaning->plaintext;
$waitForTranslation = false;
$waitForWord = true;
$simExps[]=$currentWord;
}
}
// get syn words
$htmlFaToEnSyn = $html->find('#EnToFaSyn');
$allSynAndMeanings = [];
if(isset($htmlFaToEnSyn[0]))
$allSynAndMeanings = $htmlFaToEnSyn[0]->find('div');
$waitForType = false;
$waitForTranslation = false;
$waitForSynWord = true;
$currentSynWord = Array();
$meanType ="";
foreach($allSynAndMeanings as $wordOrMeaning) {
if($wordOrMeaning->getAttribute("class") == "MeanType"){
// $currentSynWord['synWord']['meanType'] = $wordOrMeaning->plaintext;
$meanType = $wordOrMeaning->plaintext;
$currentSynWord['meanType']=$meanType;
$waitForWord = true;
$waitForTranslation = false;
}
if($wordOrMeaning->getAttribute("class") == "WordB" && $waitForWord){
$currentSynWord['word'] = $wordOrMeaning->plaintext;
$waitForTranslation = true;
$waitForWord = false;
}
if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
$currentSynWord['mean'] = $wordOrMeaning->plaintext;
$waitForTranslation = false;
$waitForWord = true;
$synWords[]=$currentSynWord;
}
}
$wordTranslation['mainMean']=$mainMean;
$wordTranslation['words']=$words;
// $wordTranslation['words']="";
$wordTranslation['synWords']=$synWords;
$wordTranslation['simWords']=$simWords;
$wordTranslation['simExps']=$simExps;
// print_r($wordTranslation);
break;
case "fatoen":
$allNouns = $html->find('.Phonetic');
$htmlFaToEn = $html->find('#FaToEn');
$allWordsAndMeanings = $htmlFaToEn[0]->find('div');
$htmlFaToEnSyn = $html->find('#FaToEnSyn');
$allSynAndMeanings = $htmlFaToEnSyn[0]->find('div');
foreach($allNouns as $noun) {
$mainMeanEnglishArray[]=$noun->plaintext;
}
$waitForTranslation = false;
$waitForWord = true;
$currentWord = Array();
foreach($allWordsAndMeanings as $wordOrMeaning) {
if($wordOrMeaning->getAttribute("class") == "WordB" && $waitForWord){
$currentWord['word'] = $wordOrMeaning->plaintext;
$waitForTranslation = true;
$waitForWord = false;
}
if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
$currentWord['mean'] = $wordOrMeaning->plaintext;
$waitForTranslation = false;
$waitForWord = true;
$words[]=$currentWord;
}
}
//********************get synonyms **************************//
$waitForType = false;
$waitForTranslation = false;
$waitForSynWord = true;
$currentSynWord = Array();
$meanType ="";
foreach($allSynAndMeanings as $wordOrMeaning) {
if($wordOrMeaning->getAttribute("class") == "MeanType"){
// $currentSynWord['synWord']['meanType'] = $wordOrMeaning->plaintext;
$meanType = $wordOrMeaning->plaintext;
$currentSynWord['meanType']=$meanType;
$waitForWord = true;
$waitForTranslation = false;
}
if($wordOrMeaning->getAttribute("class") == "WordA" && $waitForWord){
// $currentSynWord[$meanType]['word'] = $wordOrMeaning->plaintext;
$currentSynWord['word'] = $wordOrMeaning->plaintext;
$waitForTranslation = true;
$waitForWord = false;
}
if($wordOrMeaning->getAttribute("class") == "Mean" && $waitForTranslation){
// $currentSynWord[$meanType]['mean'] = $wordOrMeaning->plaintext;
$currentSynWord['mean'] = $wordOrMeaning->plaintext;
$waitForTranslation = false;
$waitForWord = true;
$synWords[]=$currentSynWord;
}
}
$wordTranslation['mainMeanEnglishArray']=$mainMeanEnglishArray;
$wordTranslation['words']=$words;
$wordTranslation['synWords']=$synWords;
break;
}
return $wordTranslation;
}
public function translateText($txt,$ln1="DE"){
$ch = curl_init();
if($ln1=="DE")
$ln2 ="FA";
else
$ln2 ="DE";
try {
curl_setopt ( $ch, CURLOPT_URL, "http://www.dicu.ir/tarjomeh2.php" );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, "txt=$txt&lang1=$ln1&lang2=$ln2" );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_ENCODING, 'gzip, deflate' );
$headers = array ();
$headers [] = "Host: www.dicu.ir";
$headers [] = "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0";
$headers [] = "Accept: */*";
$headers [] = "Accept-Language: en-US,en;q=0.5";
$headers [] = "Content-Type: application/x-www-form-urlencoded";
$headers [] = "X-Requested-With: XMLHttpRequest";
$headers [] = "Referer: http://www.dicu.ir/index.php";
$headers [] = "Cookie: HstCfa2992739=1486424263604; HstCla2992739=1486424263604; HstCmu2992739=1486424263604; HstPn2992739=1; HstPt2992739=1; HstCnv2992739=1; HstCns2992739=1";
$headers [] = "Connection: keep-alive";
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
$result = curl_exec ( $ch );
if (curl_errno ( $ch )) {
echo 'Error:' . curl_error ( $ch );
}
curl_close ( $ch );
$this->translatedHTML = $result;
// $this->resultArray = $this->getResultInArray();
// return $this->resultArray;
} catch ( Exception $e ) {
return "";
}
}
public function translate($word,$ln="entofa"){
if($ln == "entofa" || $ln == "EN")
$ln = "entofa";
else
$ln = "fatoen";
$word = str_replace(" ", "%20",$word);
$url = "http://dictionary.abadis.ir/DicServer.aspx?Word=$word&LnType=$ln";
// $url = "http://towist.com/About/index.html";
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
try {
$proxies = array(); // Declaring an array to store the proxy list
// Adding list of proxies to the $proxies array
$proxies[] = 'user:password@173.234.11.134:54253'; // Some proxies require user, password, IP and port number
$proxies[] = 'user:password@173.234.120.69:54253';
$proxies[] = 'user:password@173.234.46.176:54253';
$proxies[] = '173.234.92.107'; // Some proxies only require IP
$proxies[] = '173.234.93.94';
$proxies[] = '173.234.94.90:54253'; // Some proxies require IP and port number
$proxies[] = '69.147.240.61:54253';
$proxy = '18.195.35.81:3128';
// $proxy = '35.196.26.166:3128';
// curl_setopt($ch, CURLOPT_PROXY, $proxy);
// curl_setopt($ch, CURLOPT_URL, "http://dictionary.abadis.ir/DicServer.aspx?Word=%\"u0647\"%\"u0648\"%\"u0627&LnType=fatoen\"");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
// Set any other cURL options that are required
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, "cookieDic2.txt" );
curl_setopt( $ch, CURLOPT_COOKIEFILE, "cookieDic2.txt" );
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = "Host: dictionary.abadis.ir";
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0";
$headers[] = "Accept: */*";
$headers[] = "Accept-Language: en-US,en;q=0.5";
$headers[] = "Referer: http://dictionary.abadis.ir/?LnType=$ln&Word=$word";
// $headers[] = "Cookie: DicItem=$ln; _ga=GA1.2.455845501.1486720265; ASP.NET_SessionId=dkezcpcfo3ftkara4kyebzjl";
$headers[] = "Cookie: DicItem=$ln; _ga=GA1.2.455845501.1586720263; ASP.NET_SessionId=dkezcpcfo3ftkara4kyebzjm";
$headers[] = "Connection: keep-alive";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
file_put_contents("result.html", $result);
// $result = file_get_contents("result.html");
// print_r($result);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$this->translatedHTML = $result;
$this->resultArray = $this->getResultInArray($ln);
return $this->resultArray;
} catch ( Exception $e ) {
return "";
}
}
public function makeTranslationTextMessage() {
$translated ="";
foreach ($this->resultArray as $table){
foreach($table as $tr){
if(!empty($tr[2]))
$translated.= trim($tr[2]).": ".$tr[5].PHP_EOL;
}
}
if($translated="")
$translated ="Keine Ahnung :(";
else
$translated . " :)";
return $translated;
}
}