Store time and not the time since string in the cached data file.
This commit is contained in:
parent
7708493ebb
commit
db6a24cb96
2 changed files with 35 additions and 40 deletions
|
@ -53,16 +53,14 @@ function twitter() {
|
|||
if(empty($tweetInfo)) {
|
||||
return array(
|
||||
'text' => 'Last post was a retweet and cannot be listed.',
|
||||
'timeSince' => 0,
|
||||
'time' => 0,
|
||||
);
|
||||
} else {
|
||||
$tweet = urlify($tweetInfo->text);
|
||||
$timeSince = ($tweetInfo->created_at != 0) ?
|
||||
time_since(strtotime($tweetInfo->created_at)) : 0;
|
||||
|
||||
return array(
|
||||
'text' => $tweet,
|
||||
'timeSince' => $timeSince,
|
||||
'time' => strtotime($tweetInfo->created_at),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +80,7 @@ function github() {
|
|||
return array(
|
||||
'commit' => $commits[0]->commit->message,
|
||||
'repo' => $repos[0]->name,
|
||||
'url' => $commits[0]->commit->url,
|
||||
'url' => $repos[0]->html_url,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -91,15 +89,13 @@ function lastfm() {
|
|||
$xml = simplexml_load_file($url);
|
||||
$latestSong = $xml->recenttracks->track[0];
|
||||
|
||||
$timeSince = ((bool)$latestSong->attributes()->nowplaying) ?
|
||||
'Listening now' : time_since(strtotime($latestSong->date . ' UTC')) . ' ago';
|
||||
$cover = (is_array($latestSong->image)) ?
|
||||
'img/lastfm/blank_album64.png' : (string)$latestSong->image[1];
|
||||
|
||||
return array(
|
||||
'song' => (string)$latestSong->name,
|
||||
'artist' => (string)$latestSong->artist,
|
||||
'timeSince' => $timeSince,
|
||||
'time' => strtotime($latestSong->date . ' UTC'),
|
||||
'url' => (string)$latestSong->url,
|
||||
'cover' => $cover,
|
||||
);
|
||||
|
@ -130,14 +126,13 @@ function hulu() {
|
|||
// data for last show
|
||||
$lastShow = $xml->channel->item[0];
|
||||
|
||||
$timeSince = time_since(strtotime($lastShow->pubDate));
|
||||
$title = explode(' - ', $lastShow->title);
|
||||
preg_match('/<img src="(.*)" align="right"/',(string)$lastShow->description,$thumb);
|
||||
|
||||
return array(
|
||||
'title' => $title[2],
|
||||
'series' => $title[0],
|
||||
'timeSince' => $timeSince,
|
||||
'time' => strtotime($lastShow->pubDate),
|
||||
'url' => (string)$lastShow->link,
|
||||
'thumb' => $thumb[1],
|
||||
);
|
||||
|
@ -182,31 +177,6 @@ function curl_request($url) {
|
|||
return $contents;
|
||||
}
|
||||
|
||||
function time_since($time) {
|
||||
$periods = array(
|
||||
'minute' => 60,
|
||||
'hour' => 60 * 60,
|
||||
'day' => 60 * 60 * 24,
|
||||
'week' => 60 * 60 * 24 * 7,
|
||||
'month' => 60 * 60 * 24 * 30,
|
||||
'year' => 60 * 60 * 24 * 365,
|
||||
);
|
||||
|
||||
$now = time();
|
||||
$since = $now - $time;
|
||||
|
||||
$formatted_since = array($since,'seconds');
|
||||
foreach($periods as $period => $seconds) {
|
||||
$quotient = floor($since / $seconds);
|
||||
|
||||
if($quotient >= 1) $formatted_since = array($quotient,$period);
|
||||
else break;
|
||||
}
|
||||
|
||||
if($formatted_since[0] > 1) $formatted_since[1] .= 's';
|
||||
return implode(' ',$formatted_since);
|
||||
}
|
||||
|
||||
function urlify($string) {
|
||||
$pattern ="{\\b((https?|telnet|gopher|file|wais|ftp) : [\\w/\\#~:.?+=&%@!\\-]+?) (?= [.:?\\-]* (?:[^\\w/\\#~:.?+=&%@!\\-] |$) ) }x";
|
||||
return preg_replace($pattern,"<a href=\"$1\">$1</a>", $string);
|
||||
|
|
|
@ -38,7 +38,7 @@ $links = $db->query("SELECT id,url,text,status,released_date FROM wia_links WHER
|
|||
<div id="twitter" class="box">
|
||||
<span class="right"><a href="http://www.twitter.com/atomaka"><img src="img/badges/twitter.png" class="icon" alt="Follow me on Twitter"/></a></span>
|
||||
<span class="tweet"><?php echo $data->twitter->text ?></span><br/>
|
||||
<?php if($data->twitter->timeSince != 0) { echo $data->twitter->timeSince ?> ago <?php } ?>
|
||||
<?php if($data->twitter->time != 0) { echo time_since($data->twitter->time) ?> ago <?php } ?>
|
||||
</div>
|
||||
<br/>
|
||||
<h2>github</h2>
|
||||
|
@ -96,7 +96,7 @@ $links = $db->query("SELECT id,url,text,status,released_date FROM wia_links WHER
|
|||
<span class="right"><a href="http://last.fm/user/atomaka"><img src="img/badges/lastfm.png" class="icon" alt="Last.fm" /></a></span>
|
||||
<a href="<?php echo $data->lastfm->url ?>"><?php echo $data->lastfm->song ?></a><br/>
|
||||
by <?php echo $data->lastfm->artist ?><br/><br/>
|
||||
<?php echo $data->lastfm->timeSince ?><br/>
|
||||
<?php echo time_since($data->lastfm->time) ?><br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -111,7 +111,7 @@ $links = $db->query("SELECT id,url,text,status,released_date FROM wia_links WHER
|
|||
<span class="right"><a href="http://www.hulu.com/profiles/atomaka"><img src="img/badges/hulu.png" class="icon" alt="Hulu" /></a></span>
|
||||
<a href="<?php echo $data->hulu->url ?>"><?php echo $data->hulu->series ?></a><br/>
|
||||
from <?php echo $data->hulu->title ?><br/><br/>
|
||||
<?php echo $data->hulu->timeSince ?> ago<br/>
|
||||
<?php echo time_since($data->hulu->time) ?> ago<br/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -207,4 +207,29 @@ $(document).ready(function() {
|
|||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html><?php
|
||||
function time_since($time) {
|
||||
$periods = array(
|
||||
'minute' => 60,
|
||||
'hour' => 60 * 60,
|
||||
'day' => 60 * 60 * 24,
|
||||
'week' => 60 * 60 * 24 * 7,
|
||||
'month' => 60 * 60 * 24 * 30,
|
||||
'year' => 60 * 60 * 24 * 365,
|
||||
);
|
||||
|
||||
$now = time();
|
||||
$since = $now - $time;
|
||||
|
||||
$formatted_since = array($since,'seconds');
|
||||
foreach($periods as $period => $seconds) {
|
||||
$quotient = floor($since / $seconds);
|
||||
|
||||
if($quotient >= 1) $formatted_since = array($quotient,$period);
|
||||
else break;
|
||||
}
|
||||
|
||||
if($formatted_since[0] > 1) $formatted_since[1] .= 's';
|
||||
return implode(' ',$formatted_since);
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue