@coast Thank you but I swear actually reading the manual, Googling and being more persistant than a bad stain makes up 99% of it.
@firemax Oh dear, oh dear, oh dear:
@all
http://www.axllent.org/projects/mytwit
Folks, look at his class, then look at the original and think how very, very similar they are.
It is one thing to write something and take credit for it, it is another altogether different thing to take the code that was writen by someone else, bung it in a mobile template and take credit for it. In fact it's a scummy practice and you're out of order for taking the original authors work and making out it's your own creation.
This is original, I put it together and where it uses functions that I found elsewhere I have given the original author the due respect and credit they deserve, just like a certain someone should have done.
PHP Code:
<?php
date_default_timezone_set('Europe/London'); // list of time zones - required to not puke when handling time calculations
$user = 'detectmobiles'; // set the username you want to get the feed for
$limit = '10'; // how many items do you want to return
$data = 'http://twitter.com/statuses/user_timeline/'.$user.'.xml'; // build the endpoint
// this function takes two arguments, the url of the endpoint and the duration in minutes to cache the data for
// inspired by the cache article on http://www.addedbytes.com/articles/caching-output-in-php/
function cached_simplexml_load_file($file,$minutes='5'){
if(isset($_GET['cache'])){$minutes = '0';} // bypass the cache by adding ?cache to the url
$remote = $file; // set the remote address in case we need it
$file = 'cache/'.md5($file).'.xml'; // make up a file name to store the data in
if(!(file_exists($file)&&(60*$minutes)>(time()-filemtime($file)))){ // if the file exists and is older than the cache expiration time get the data and write it to a file
$fp = fopen($file, 'wb');
fwrite($fp, file_get_contents($remote));
fclose($fp);
}
return simplexml_load_file($file); // now return the data with simple xml
}
function make_clickable($text){ // 85% taken from http://snippets.dzone.com/posts/show/6156
$ret = ' ' . $text;
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" target=\"_blank\">\\2</a>'", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>'", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret); // http://www.snipe.net/2009/09/php-twitter-clickable-links/
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\[email protected]\\3\">\\[email protected]\\3</a>", $ret);
$ret = substr($ret, 1);
return($ret);
}
function niceTime($time) { // taken from http://manas.tungare.name/software/twitter-php-script/
$delta = time() - $time;
if ($delta < 60) {
return 'less than a minute ago.';
} else if ($delta < 120) {
return 'about a minute ago.';
} else if ($delta < (45 * 60)) {
return floor($delta / 60) . ' minutes ago.';
} else if ($delta < (90 * 60)) {
return 'about an hour ago.';
} else if ($delta < (24 * 60 * 60)) {
return 'about ' . floor($delta / 3600) . ' hours ago.';
} else if ($delta < (48 * 60 * 60)) {
return '1 day ago.';
} else {
return floor($delta / 86400) . ' days ago.';
}
}
$xml = cached_simplexml_load_file($data); // get the data either fresh or from the cache
// now run through each status update in the xml
foreach($xml->status as $status){
if(++$cntr<=$limit){ // increment the counter and make sure that's less than or equal to the limit
$tweet = make_clickable($status->text);
$time = niceTime(strtotime(str_replace("+0000", "", $status->created_at)));
$tweets .= '<p>'.$tweet.'<br />'.$time.'</p>'; // build up the tweets as paragraphd
// $tweets .= '<li>'.$tweet.'<br />'.$time.'</li>'; // build up the tweets as list elements
if($cntr=='1'){ // if this is the first tweet we are processing get the followers and friends counts
$followers = $status->user->followers_count;
$following = $status->user->friends_count;
}
}
}
// show what we have
echo $tweets.'<p>Following '.$following.' people<br />Followed by '.$followers.' people</p>';
// this entire file could be stashed away in an include, when it's called it will return three values:
// $tweets = the full list of tweets upto the limit you set
// $following = how many people you are following
// $followers = how many people are folling you
?>
http://andymoore.info/tweets.phps
@firemax Giving away copyrighted material on your site and passing off other people's code are both bad practices which make me think you're scum.
Bookmarks