Beispiel #1
0
 public function fetch($api, $count = 60)
 {
     $q = array('appid' => MBLApplication::getAppId(), 'format' => 'json', 'count' => $count);
     $url = 'http://mybloglog.yahooapis.com/v1/user/' . $this->user . '/' . $api . '?' . http_build_query($q);
     $json = MBLWebServiceClient::request($url);
     if (!$json) {
         return false;
     }
     return json_decode($json, true);
 }
 public static function request($url)
 {
     if (!self::$cache_dir) {
         self::$cache_dir = dirname(__FILE__) . '/cache';
     }
     $file = self::$cache_dir . '/' . md5($url);
     if (!file_exists($file) || filemtime($file) < time() - self::$cache_duration) {
         $data = @file_get_contents($url);
         if (!self::validate($data)) {
             // fetch failed, use cached data
             touch($file);
             return file_get_contents($file);
         }
         $tmp = tempnam($cache_dir, 'MBL');
         file_put_contents($tmp, $data);
         rename($tmp, $file);
         return $data;
     } else {
         return file_get_contents($file);
     }
 }