Awh... Twitter is broken/down/not working/unhappy... go figure! :(\n"; /**************************************************/ function twitterCache($USERNAME, $CACHEDIR) { /* twitterCache() reads/updates/returns twitter values * Twitter now only allows 100 requests from the same IP address at a time * as a result I just added a little cache setup that only allows one hit * eveyr 60 seconds. Thus, resulting in only 60 requests an hour. * * be sure your system time is set correctly or the cache update * will not work. */ global $ERRORMSG; if (time() - @filemtime($CACHEDIR . "twitter.txt") > 60 ) { /* I like to call curl (yes I know it's sloppy) and NEVER * use this if you're allowing an external person to change $USERNAME. * * However, curl deals with the Twitter error codes much better than something * basic like file_get_contents() which fals on a 403 error. * * We'll do a quick search order ot make life easy then default to file_get_contents(); */ if (file_exists("/usr/local/bin/curl")) { $my_tweets_str=shell_exec("/usr/local/bin/curl --location --max-time 2 http://twitter.com/statuses/user_timeline/" . $USERNAME . ".xml 2>&1"); } elseif (file_exists("/usr/bin/curl")) { $my_tweets_str=shell_exec("/usr/local/bin/curl --location --max-time 2 http://twitter.com/statuses/user_timeline/" . $USERNAME . ".xml 2>&1"); } else { /* we can't find curl so we'll default to file_get_contents() * which does poorly with twitter error messages */ $my_tweets_str=file_get_contents("http://twitter.com/statuses/user_timeline/" . $USERNAME . ".xml"); } if (trim($my_tweets_str) != NULL && !strstr($my_tweets_str, "Rate limit exceeded") && !strstr($my_tweets_str, "timed out")) { file_put_contents($CACHEDIR . "twitter.txt", $my_tweets_str); } else { $my_tweets_str=$ERRORMSG; file_put_contents($CACHEDIR . "twitter.txt", $ERRORMSG); } } else { $my_tweets_str=file_get_contents($CACHEDIR . "twitter.txt"); } return($my_tweets_str); } function twitterPrint() { global $CACHEDIR, $USERNAME, $MAXTWEETS; $my_tweets_str=twitterCache($USERNAME, $CACHEDIR); /* make sure we did not get an empty my_tweets_str */ if (trim($my_tweets_str) == NULL && strstr($my_tweets_str, "Rate limit exceeded") && strstr($my_tweets_str, "timed out")) { printf("%s", $ERRORMSG); } $my_tweets=explode("\n", $my_tweets_str); if ( !is_array($my_tweets)) { printf("%s", $ERRORMSG); } else { /* Let's cleanup the output for links and what not */ $cnt=0; while(list($n, $txt)=each($my_tweets)) { if ( $cnt < $MAXTWEETS ) { if(strstr($txt, "created_at")) { $date=explode("+", $txt); $date="$date[0]
"; } if(strstr($txt, "")) { @$cnt++; if (strstr($txt, "http://")) { $http_ex=explode("http://", $txt); $end=explode(" ", $http_ex[1]); $link=$end[0]; } printf("%s

", trim(str_replace("
", "", str_replace("", "", str_replace("http://$link", "$link", $txt))))); } if(strstr($txt, "")) { $str=explode("", $txt); printf("%s", $str[1]); } } unset($date); } } } /* call twitterPrint() */ twitterPrint(); ?>