From 0e92e864ca66e676701d5c0934d86a37420cc993 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Sun, 14 Nov 2010 01:22:09 +0000 Subject: [PATCH] Inclusão do aplicativo twitter2geo.php para conversão de mensagens no Twitter em arquivos KML --- twitter2geo.php | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+), 0 deletions(-) create mode 100644 twitter2geo.php diff --git a/twitter2geo.php b/twitter2geo.php new file mode 100644 index 0000000..8e2a14a --- /dev/null +++ b/twitter2geo.php @@ -0,0 +1,162 @@ +Title: twitter2geo.php + Converte mensagens registradas no twitter, para um determinado TAG, em um arquivo georreferenciado + As mensagens são consideradas apenas qd possuírem as TAGs #x ou #y, ou então, #lat ou #long + São aceitos todos os parâmetros de busca da API do Twitter, como definidos em http://search.twitter.com/ + + Parametros: + + ajuda - se for definida na URL, mostra uma ajuda ao usuário + tipo - tipo de arquivo que será retornado + + Valores: + + twitter - retona os resultados originais encontrados + kml - retorna os dados no formato kml + + Exemplos: + + twitter2geo.php?ajuda + twitter2geo.php?tipo=kml&q=twit2kml"; + exit; +} +$query = array(); +foreach($chaves as $chave) +{$query[] = $chave."=".$par[$chave];} +$query = implode("&",$query); +$s = PHP_SHLIB_SUFFIX; +if(!function_exists('curl_init')) +{@dl( 'php_curl'.'.'.$s );} +if(!function_exists('curl_init')) +{echo "curl não instalado";} +$curl = curl_init(); +curl_setopt ($curl, CURLOPT_URL, "http://search.twitter.com/search.json?".($query)); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); +$result = curl_exec ($curl); +curl_close ($curl); +$result = fixEncoding($result); +if(strtolower($par["tipo"]) == "twitter"){ + //echo header("Content-type: application/json"); + echo $result; + exit; +} +$result = json_decode( $result, true ); +$kml = 'twitter'; +$kml .= ''.$q.''.$q.'1'; +$icon = array(); +if(!$result["results"]) +{exit;} +foreach($result["results"] as $r) +{ + if(!in_array($r["from_user"],$icon)) + { + $kml .= ''; + } + $icon[] = $r["from_user"]; +} +$id = 0; +foreach($result["results"] as $r) +{ + $xy = retornaXY($r["text"]); + if($xy != "") + { + $html = ""; + $html .= ""; + $html .= "
".$r["from_user"]."
"; + $html .= $r["created_at"]."

"; + $html .= $r["text"]."
"; + $kml .=''.$id.''; + $kml .= ''; + $kml .= ''.$r["from_user"].''; + $kml .= ''.$xy.''; + $id++; + } +} +$kml .= '
'; +echo header("Content-type: application/xml"); +echo $kml; +function retornaXY($s) +{ + $x = preg_replace("/(.*#x)|(\s.*)/i","",$s); + if($x == "") + {$x = preg_replace("/(.*#long)|(\s.*)/i","",$s);} + if($x == "") + {$x = preg_replace("/(.*#lon)|(\s.*)/i","",$s);} + $y = preg_replace("/(.*#y)|(\s.*)/i","",$s); + if($y == "") + {$y = preg_replace("/(.*#lat)|(\s.*)/i","",$s);} + $x = str_replace(",",".",$x); + $y = str_replace(",",".",$y); + if(!is_numeric($x) || !is_numeric($y)) + {return "";} + else + {return $x.",".$y;} +} +function fixEncoding($in_str) +{ + $cur_encoding = mb_detect_encoding($in_str) ; + if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) + {return $in_str;} + else + {return utf8_encode($in_str);} +} +?> \ No newline at end of file -- libgit2 0.21.2