public function import($forceResync)
 {
     if (get_option('github_username')) {
         $lastseenid = get_option('reclaim_' . $this->shortname . '_last_seen_id');
         $page = 0;
         do {
             $req = sprintf(self::$apiurl, get_option('github_username'), $page);
             $feed = parent::import_via_curl($req, self::$timeout);
             $data = self::map_data(json_decode($feed, true));
             parent::insert_posts($data);
             $reqOk = count($data) > 0;
             if ($reqOk && (!isset($newlastseenid) || intval($newlastseenid) < intval($data[0]["ext_guid"]))) {
                 // store the last-seen-id, which is the first message of the first request
                 $newlastseenid = $data[0]["ext_guid"];
             }
             if (!$forceResync && $reqOk && intval($data[count($data) - 1]["ext_guid"]) < intval($lastseenid)) {
                 // abort requests if we've already seen these events
                 $reqOk = false;
             }
             parent::log(sprintf(__('Retrieved set of GitHub events: %d, last seen id: %s, new last seen id: %s, req-ok: %d', 'reclaim'), count($data), $lastseenid, $newlastseenid, $reqOk));
             $page++;
         } while ($reqOk);
         update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp'));
         if (isset($newlastseenid)) {
             update_option('reclaim_' . $this->shortname . '_last_seen_id', $newlastseenid);
         }
     } else {
         parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname));
     }
 }
 public function count_items($type = 'posts')
 {
     if (get_option('youtube_username')) {
         // when it is called from a ajax-resync, post could be set...
         // this name 'type' should be better choosen not to break other things
         // in wordpress maybe mod_instagram_type
         $type = isset($_POST['type']) && $_POST['type'] != '' ? $_POST['type'] : $type;
         if (!isset($type) || $type == 'posts') {
             $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('youtube_username'), self::$count), self::$timeout);
         }
         if ($type == 'favs') {
             $rawData = parent::import_via_curl(sprintf(self::$fav_apiurl, get_option('youtube_username'), self::$count), self::$timeout);
         }
         if ($type == 'activity') {
             $rawData = parent::import_via_curl(sprintf(self::$activity_apiurl, get_option('youtube_username'), get_option('google_api_key'), 50) . '&start-index=100', self::$timeout);
         }
         // max-results = 50 gets more accurate count, don't ask me why
         $rawData = json_decode($rawData, true);
         return $rawData['feed']['openSearch$totalResults']['$t'];
     } else {
         return false;
     }
 }
 public function ajax_resync_items()
 {
     $type = isset($_POST['type']) ? $_POST['type'] : 'posts';
     $offset = intval($_POST['offset']);
     $limit = intval($_POST['limit']);
     $count = intval($_POST['count']);
     $next_url = isset($_POST['next_url']) ? $_POST['next_url'] : null;
     self::log($this->shortName() . ' ' . $type . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count);
     $return = array('success' => false, 'error' => '', 'result' => null);
     if (get_option('facebook_username') && get_option('facebook_user_id') && get_option('facebook_oauth_token')) {
         if ($next_url != '') {
             $rawData = parent::import_via_curl($next_url, self::$timeout);
         } else {
             $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('facebook_user_id'), self::$count, substr(get_bloginfo('language'), 0, 2), get_option('facebook_oauth_token')), self::$timeout);
         }
         $rawData = json_decode($rawData, true);
         if (!$rawData['error']['code']) {
             $data = self::map_data($rawData, $type);
             parent::insert_posts($data);
             update_option('reclaim_' . $this->shortname . '_' . $type . '_last_update', current_time('timestamp'));
             if (!isset($rawData['paging']['next'])) {
                 //$return['error'] = sprintf(__('%s %s import done.', 'reclaim'), $type, $this->shortname);
                 $return['result'] = array('offset' => $offset + sizeof($data), 'count' => $offset + sizeof($data), 'next_url' => null);
             } else {
                 $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $rawData['paging']['next']);
             }
             $return['success'] = true;
         } elseif (isset($rawdata['error']['code']) != 200) {
             $return['error'] = $rawData['error']['message'] . " (Error code " . $rawData['error']['code'] . ")";
         } else {
             $return['error'] = sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname);
         }
     } else {
         $return['error'] = sprintf(__('%s %s user data missing. No import was done', 'reclaim'), $this->shortname, $type);
     }
     echo json_encode($return);
     die;
 }
 public function count_items()
 {
     $user_name = get_option('twitpic_user_name');
     if (isset($user_name)) {
         $rawData = parent::import_via_curl(sprintf(self::$apiurl, $user_name, 1), self::$timeout);
         $rawData = json_decode($rawData, true);
         //parent::log(print_r($rawdata, true));
         return $rawData['photo_count'];
     } else {
         return false;
     }
 }
 public function count_items()
 {
     $user_id = get_option('flickr_user_id');
     $app_key = get_option('flickr_api_key');
     if (isset($user_id) && isset($app_key)) {
         $rawData = parent::import_via_curl(sprintf(self::$apiurl, $user_id, 1, 1, $app_key), self::$timeout);
         $rawData = str_replace('jsonFlickrApi(', '', $rawData);
         $rawData = substr($rawData, 0, strlen($rawData) - 1);
         //strip out last paren
         $rawData = json_decode($rawData, true);
         //parent::log(print_r($rawData, true));
         return $rawData['photos']['total'];
     } else {
         return false;
     }
 }
 public function import($forceResync)
 {
     if (get_option('google_api_key') && get_option('google_plus_user_id')) {
         $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('google_plus_user_id'), get_option('google_api_key'), self::$count, ""), self::$timeout);
         //parent::log(print_r($rawData,true));
         $rawData = json_decode($rawData, true);
         if (is_array($rawData) && !isset($rawdata['code'])) {
             $data = self::map_data($rawData);
             parent::insert_posts($data);
             update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp'));
         }
     } else {
         parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname));
     }
 }
 public function count_items($type = "posts")
 {
     if (get_option('instagram_user_id') && get_option('instagram_access_token')) {
         // when it is called from a ajax-resync, post could be set...
         // this name 'type' should be better choosen not to break other things
         // in wordpress maybe mod_instagram_type
         $type = isset($_POST['type']) ? $_POST['type'] : $type;
         if ($type == "favs") {
             return 999999;
         }
         $rawData = parent::import_via_curl(sprintf(self::$apiurl_count, get_option('instagram_user_id'), get_option('instagram_access_token')), self::$timeout);
         $rawData = json_decode($rawData, true);
         return $rawData['data']['counts']['media'];
     } else {
         return false;
     }
 }
 public function count_items()
 {
     if (get_option('moves_user_id') && get_option('moves_access_token')) {
         $rawData = parent::import_via_curl(sprintf(self::$apiurl_profile, get_option('moves_access_token')), self::$timeout);
         $rawData = json_decode($rawData, true);
         $firstdate = strtotime($rawData['profile']['firstDate']);
         $second = 1;
         $minute = $second * 60;
         $hour = $minute * 60;
         $day = $hour * 24;
         $week = $day * 7;
         $delta = time() - $firstdate;
         //29584979
         $days = round($delta / $day);
         return $days;
     } else {
         return false;
     }
 }
 public function count_items($type = "posts")
 {
     if (get_option('tumblr_user_id') && get_option('tumblr_access_token')) {
         // todo: get count for secondary blogs
         // right now, only the count for the primary blog is fetched
         $type = isset($_POST['type']) ? $_POST['type'] : $type;
         if ($type == "favs") {
             return 999999;
         }
         $rawData = parent::import_via_curl(sprintf(self::$apiurl_count, get_option('tumblr_user_name') . '.tumblr.com', get_option('tumblr_client_id'), self::$count), self::$timeout);
         $rawData = json_decode($rawData, true);
         return $rawData['response']['blog']['posts'];
     } else {
         return false;
     }
 }
 public function count_items()
 {
     if (get_option('foursquare_user_id') && get_option('foursquare_access_token')) {
         $rawData = parent::import_via_curl(sprintf(self::$apiurl_count, get_option('foursquare_access_token')), self::$timeout);
         $rawData = json_decode($rawData, true);
         return $rawData['response']['checkins']['count'];
     } else {
         return false;
     }
 }