Ejemplo n.º 1
0
 private static function googleTranslate($text, $from = 'auto', $to = 'de', $return_source_lang = false)
 {
     $html = GWF_HTTP::post('https://translate.google.com/', array('sl' => $from, 'tl' => $to, 'js' => 'n', 'hl' => 'en', 'ie' => 'UTF-8', 'text' => $text));
     if (!preg_match('#<span id=result_box .+?>(.+?)</div>#', $html, $arr)) {
         return false;
     }
     $translation = html_entity_decode(strip_tags($arr[1]), ENT_QUOTES);
     if ($return_source_lang) {
         if (!preg_match('#<div id=autotrans.+?<h3.+?>(.+?) to .+? translation</h3>#', $html, $arr)) {
             return false;
         }
         return array('translation' => $translation, 'source_lang' => $arr[1]);
     } else {
         return $translation;
     }
 }
Ejemplo n.º 2
0
 /**
  * Used to minify URLs
  *
  * @param string $url The URL you want to be minified by http://jbot.de
  * @return array An Array containing a Title(1) and an URL(0)
  */
 function jbot_minify($url)
 {
     // Magic Values
     $SERVICE = 'http://jbot.de/create.php';
     $PREFIX = '<p class="redirect">';
     $POSTFIX = '</p>';
     $response = GWF_HTTP::post($SERVICE, array('url' => $url));
     // 1:1 html leech umgesetzt wie in Ralfs js example http://jbot.de/js/jbotcreate.js
     if (false === ($posStart = strpos($response, $PREFIX))) {
         return false;
     } else {
         $posStart += strlen($PREFIX);
         if (false === ($posEnd = strpos($response, $POSTFIX, $posStart))) {
             return false;
         }
         $minified = substr($response, $posStart, $posEnd - $posStart);
     }
     return $minified;
 }