Advertisement
Guest User

Untitled

a guest
Feb 8th, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. function getTwitter() {
  2.         $filename = "tweets";
  3.         $useCache = false;
  4.         $cache = "";
  5.  
  6.         if (file_exists('_temp/' . $filename . '.json')) {
  7.             $time = file_get_contents('_temp/' . $filename . '.time');
  8.             if (time() - $time > 15 * 60) {
  9.                 $useCache = false;
  10.             }
  11.             else {
  12.                 $cache = file_get_contents('_temp/' . $filename . '.json');
  13.                 $useCache = true;
  14.             }
  15.         }
  16.  
  17.         if ($useCache) {
  18.             $data = $cache;
  19.         }
  20.         else {
  21.             $data = getTimeline();
  22.             file_put_contents('_temp/' . $filename . '.json', $data);
  23.             file_put_contents('_temp/' . $filename . '.time', time());
  24.         }
  25.  
  26.         $tweets = json_decode($data);
  27.         $tarray = array();
  28.  
  29.         $i = 0;
  30.         foreach($tweets as $t) {
  31.             $tarray[$i]['text'] = parseTweet($t->text);
  32.             $tarray[$i]['daysago'] = daysAgo(strtotime($t->created_at));
  33.             $i++;
  34.         }
  35.  
  36.         return $tarray;
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement