Esempio n. 1
0
function wpr_translate($text, $t1 = "", $t2 = "", $t3 = "")
{
    if (empty($text)) {
        $return["error"]["module"] = "Translation";
        $return["error"]["reason"] = "Translation Failed";
        $return["error"]["message"] = __("Empty text given.", "wprobot");
        return $return;
    }
    if (empty($t2)) {
        $return["error"]["module"] = "Translation";
        $return["error"]["reason"] = "Translation Failed";
        $return["error"]["message"] = __("No target language specified.", "wprobot");
        return $return;
    }
    if ($t1 == $t2) {
        $return["error"]["module"] = "Translation";
        $return["error"]["reason"] = "Translation Failed";
        $return["error"]["message"] = __("Same languages specified.", "wprobot");
        return $return;
    }
    // SAVE URLS
    preg_match_all('#\\href="(.*)"\\]#iU', $text, $matches, PREG_SET_ORDER);
    if ($matches) {
        //foreach($matches as $match) {
        // HREF = $match[1]
        //}
    }
    if ($t1 != 'no' & $t2 != 'no') {
        $transtext = wpr_gtrns($text, $t1, $t2);
        if (!empty($transtext["error"]["reason"])) {
            return $transtext;
        }
    }
    if ($t1 != 'no' & $t2 != 'no' & $t3 != 'no') {
        $transtext = wpr_gtrns($transtext, $t2, $t3);
        if (!empty($transtext["error"]["reason"])) {
            return $transtext;
        }
    }
    if ($t1 != 'no' & $t2 != 'no' & $t3 != 'no' & $t4 != 'no') {
        $transtext = wpr_gtrns($transtext, $t3, $t4);
        if (!empty($transtext["error"]["reason"])) {
            return $transtext;
        }
    }
    $pos = strpos($transtext, "302 Moved");
    $pos2 = strpos($transtext, "301 Moved");
    $pos3 = strpos($transtext, "404 Not Found");
    if ($pos === false && $pos2 === false && $pos3 === false) {
        $moved = 2;
    } else {
        $moved = 1;
    }
    if (!empty($transtext) && $transtext != ' ' && $moved != 1) {
        // REPLACE URLS
        preg_match_all('#\\href="(.*)"\\]#iU', $transtext, $rmatches, PREG_SET_ORDER);
        if ($rmatches) {
            $i = 0;
            foreach ($rmatches as $rmatch) {
                // HREF = $match[1]
                echo "<br/>REPLACE: " . $matches[$i][1];
                echo "<br/>WITH: " . $rmatch[1];
                $transtext = str_replace($rmatch[1], $matches[$i][1], $transtext);
                $i++;
            }
        }
        // TO DO:
        // - HTMLFIXER CLASS NECESSARY?
        $transtext = str_replace('&lt; / ', '</', $transtext);
        $transtext = str_replace('&lt;/ ', '</', $transtext);
        $transtext = str_replace('&lt; /', '</', $transtext);
        $transtext = str_replace('&lt; ', '<', $transtext);
        $transtext = str_replace('num = "', 'num="', $transtext);
        $transtext = str_replace('kw = "', 'kw="', $transtext);
        $transtext = str_replace('ebcat = "', 'ebcat="', $transtext);
        $transtext = str_replace('[Wprebay', '[wprebay', $transtext);
        $transtext = str_replace('[/ ', '[/', $transtext);
        $transtext = str_replace('Has_rating', 'has_rating', $transtext);
        //echo $transtext . "<br/>--------------------------------------------<br/>";
        $transtext = html_entity_decode($transtext);
        //echo $transtext . "<br/>--------------------------------------------<br/>";
        $transtext = stripslashes($transtext);
        $a = new HtmlFixer();
        $transtext = $a->getFixedHtml($transtext);
        //echo $transtext . "<br/>--------------------------------------------<br/>";
        return $transtext;
    } else {
        $return["error"]["module"] = "Translation";
        $return["error"]["reason"] = "Translation Failed";
        $return["error"]["message"] = __("The post could not be translated.", "wprobot");
        return $return;
    }
}
Esempio n. 2
0
function wpr_translate($text,$t1="",$t2="",$t3="",$t4="") {

	if(empty($text)) {
		$return["error"]["module"] = "Translation";
		$return["error"]["reason"] = "Translation Failed";
		$return["error"]["message"] = __("Empty text given.","wprobot");	
		return $return;		
	}
	
	if(empty($t2)) {
		$return["error"]["module"] = "Translation";
		$return["error"]["reason"] = "Translation Failed";
		$return["error"]["message"] = __("No target language specified.","wprobot");	
		return $return;		
	}		
	
	if($t1 == $t2) {
		$return["error"]["module"] = "Translation";
		$return["error"]["reason"] = "Translation Failed";
		$return["error"]["message"] = __("Same languages specified.","wprobot");	
		return $return;		
	}		
	
	// SAVE URLS
	//echo "<br/>------------------SAVE-----------------<br/>";
	preg_match_all('#href\s*=\s*"(.*)"#siU', $text, $matches, PREG_SET_ORDER);
	//print_r($matches);
	// SAVE SRC
	preg_match_all('#src\s*=\s*"(.*)"#siU', $text, $matches2, PREG_SET_ORDER);

	if ($t1!='no' && $t2!='no') {
		$transtext = wpr_gtrns($text, $t1, $t2);
		if(!empty($transtext["error"]["reason"])) {
			return $transtext;
		}
		
		$transtext = wpr_trans_format($transtext);
	}
	if ($t1!='no'  && $t2!='no'  && $t3!='no') {
		$transtext = wpr_gtrns($transtext, $t2, $t3);
		if(!empty($transtext["error"]["reason"])) {
			return $transtext;
		}			
		$transtext = wpr_trans_format($transtext);
	}
	if ($t1!='no'  && $t2!='no'  && $t3!='no'  && $t4!='no') {
		$transtext = wpr_gtrns($transtext, $t3, $t4);
		if(!empty($transtext["error"]["reason"])) {
			return $transtext;
		}			
		$transtext = wpr_trans_format($transtext);
	}	

	$pos = strpos($transtext, "302 Moved");
	$pos2 = strpos($transtext, "301 Moved");	
	$pos3 = strpos($transtext, "404 Not Found");							
	if ($pos === false && $pos2 === false && $pos3 === false) {
		$moved = 2;
	} else {	
		$moved = 1;
	}				 

	if ( !empty($transtext) && $transtext != ' ' && $moved != 1) {
		$transtext = html_entity_decode($transtext);	
		// REPLACE URLS
		//echo "<br/>------------------REPLACE-----------------<br/>";\s*=\s*
		//preg_match_all('#href = "(.*)"#siU', $transtext, $rmatches, PREG_SET_ORDER);
		preg_match_all('#href\s*=\s*"(.*)"#siU', $transtext, $rmatches, PREG_SET_ORDER);
		if ($rmatches) {
			$i=0;
			foreach($rmatches as $rmatch) {	// HREF = $match[1]	
				//echo "<br/>ORIGINAL: ".$matches[$i][1];
				//echo "<br/>REPLACEMENT: ".$rmatch[1];
				$transtext = str_replace($rmatch[1], $matches[$i][1], $transtext);
				$i++;
			}
		}		//print_r($rmatches);
		// REPLACE SRC
		//preg_match_all('#src ="(.*)"#siU', $transtext, $rmatches2, PREG_SET_ORDER);
		preg_match_all('#src\s*=\s*"(.*)"#siU', $transtext, $rmatches2, PREG_SET_ORDER);
		if ($rmatches2) {
			$i=0;
			foreach($rmatches2 as $rmatch2) {	// HREF = $match[1]	
				$transtext = str_replace($rmatch2[1], $matches2[$i][1], $transtext);
				$i++;
			}
		}

		return $transtext;
	} else {
		$return["error"]["module"] = "Translation";
		$return["error"]["reason"] = "Translation Failed";
		$return["error"]["message"] = __("The post could not be translated.","wprobot");	
		return $return;		
	}
}