26 de julho de 2010
SimpleTwitter – Exibir apenas tweets direcionados à todos
Enquanto preparava a cara nova daqui, reparei que o plugin SimpleTwitter que veio com o tema mostrava o último tweet da conta.
Não achei interessante mostrar qualquer um pois o último pode ser um reply à alguém.
Alterei o plugin para que ele não exiba um tweet começado com @.
Ainda não entrei em contato com o autor pois assim que tiver um tempo pretendo colocar isso como opcional nas configurações. Se você, leitor, se interessar por isso, vá em frente.
Abaixo segue o diff:
--- velha.php 2010-07-28 20:21:10.068090123 -0300
+++ nova.php 2010-07-28 20:21:28.778089294 -0300
@@ -164,9 +164,8 @@
$twitterId = get_option($_opt_twitter_id);
if ($twitterId != '') {
$url = 'http://twitter.com/statuses/user_timeline/'.$twitterId.'.rss';
- $title = get_message_from_url($url);
- if ($title != '') {
- $msg = extract_message_from_twitter_title($title);
+ $msg = get_message_from_url($url);
+ if ($msg != '') {
update_option($_opt_twitter_msg, $msg);
update_option($_opt_last_cache_time, time());
}
@@ -179,7 +178,7 @@
return $msg;
}
-// Gets the RSS feed and reads the title of the first item
+// Gets the RSS feed and reads the title of the first item to all followers
function get_message_from_url($url, $tag = 'title', $item = 'item') {
$msg = '';
@@ -206,8 +205,8 @@
$inItem = false;
foreach ($lines as $s) {
- $s = rtrim($s);
- if (strpos($s, $itemTag)) {
+ $s = trim($s);
+ if (substr_count($s, $itemTag)) {
$inItem = true;
}
if ($inItem) {
@@ -216,9 +215,13 @@
if ($inItem && strpos($s, $endTag)) {
$msg = substr_replace($msg, '', strpos($msg, $endTag));
$msg = substr($msg, strpos($msg, $startTag) + strlen($startTag));
- break;
+ $msg = substr($msg, strpos($msg, ':') + 2);
+ if(strpos($msg, '@')!==0) {
+ return $msg;
}
+ $inItem = false;
}
- return $msg;
+ }
+ return '';
}
?>








