|
|
05-22-2009
, 05:01 AM
|
|
Posts: 10 |
Thanked: 1 time |
Joined on Nov 2005
|
#2
|
|
|
05-22-2009
, 09:47 AM
|
|
Posts: 152 |
Thanked: 102 times |
Joined on Aug 2007
|
#3
|
|
|
05-25-2009
, 07:28 AM
|
|
|
Posts: 381 |
Thanked: 846 times |
Joined on Jan 2007
@ Helsinki
|
#4
|
Is there any practical way for maemo.org to stream Internet Tablet-related tweets along with its other NIT/mameo coverage?
|
|
06-02-2009
, 12:31 AM
|
|
|
Posts: 972 |
Thanked: 715 times |
Joined on Jul 2007
@ France
|
#5
|
<?php
// Modified by Khertan
// Example: Get a single tweet.
//$status = getTwitterStatus("manas");
//echo($status[0]['message'] . ' - ' . $status[0]['time']);
// Example: Get multiple tweets.
//$statuses = getTwitterStatus("manas", 100);
//foreach ($statuses as $status) {
// echo($status['message'] . ' - ' . $status['time']);
//}
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
function loadTwitterStatus($twitterUser,$limit){
$status = '';
$life = (time() - filectime($twitterUser.'.tweets'));
if($life < (10*60) and $life > 0)
{
$statuses = unserialize((file_get_contents($twitterUser.'.tweets')));
$index = 1;
foreach ($statuses as $tweet) {
$status = $status . '<p>'.$tweet['message'].'</p><p class="date">'. $tweet['time'] . '</p>';
$index++;
if (($limit>0) and ($limit<$index))
break;
}
}
else
{
$statuses = getTwitterStatus($twitterUser);
if (count($statuses)==0){
$statuses = unserialize((file_get_contents($twitterUser.'.tweets')));}
$index = 1;
foreach ($statuses as $tweet) {
$status = $status . '<p>'.$tweet['message'].'</p><p class="date">'. $tweet['time'] . '</p>';
$index++;
if (($limit>0) and ($limit<$index))
break;
}
//file_put_contents($twitterUser.'.tweets',$status);
if ($index>1)
{file_put_contents($twitterUser.'.tweets',serialize($statuses));}
}
return $status;
}
/**
* A simple Twitter status display script.
* Useful as a status badge for JavaScript non-compliant browsers, where the
* insertion of the status message must be performed on the server.
*
* @author Manas Tungare, manas@tungare.name
* @version 1.1
* @copyright Manas Tungare, 2007 - 2009 and onwards.
* @license Creative Commons Attribution ShareAlike 3.0.
*/
function getTwitterStatus($twitterUser) {
$url = sprintf("http://twitter.com/statuses/user_timeline/%s.xml", $twitterUser);
$tweets = array();
if (true == ($str=curl_get_file_contents($url)))
{try{
$parsed = new SimpleXMLElement($str);
foreach($parsed->status as $status) {
$message = preg_replace("/http:\/\/(.*?)\/[^ ]*/", '<a href="\\0">\\0</a>',$status->text);
$time = niceTime(strtotime(str_replace("+0000", "", $status->created_at)));
$tweets[] = array('message' => $message, 'time' => $time);
}
}catch (Exception $e){;}}
return $tweets;
}
/**
* Formats a timestamp nicely with an adaptive "x units of time ago" message.
* Based on the original Twitter JavaScript badge. Only handles past dates.
* @return string Nicely-formatted message for the timestamp.
* @param $time Output of strtotime() on your choice of timestamp.
*/
function niceTime($time) {
$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.';
}
}
?>
<? $statuses = loadTwitterStatus("khertan",-1);
echo $statuses;?>
![]() |
| Thread Tools | Search this Thread |
|
Last edited by RogerS; 05-21-2009 at 12:59 PM. Reason: Added paragraphing