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 import($forceResync) { if (get_option('goodreads_user_id')) { if (!class_exists('SimplePie')) { require_once ABSPATH . WPINC . '/class-feed.php'; } $rss_source = sprintf(self::$apiurl, get_option('goodreads_user_id')); /* Create the SimplePie object */ $feed = new SimplePie(); /* Set the URL of the feed you're retrieving */ $feed->set_feed_url($rss_source); /* Tell SimplePie to cache the feed using WordPress' cache class */ $feed->set_cache_class('WP_Feed_Cache'); /* Tell SimplePie to use the WordPress class for retrieving feed files */ $feed->set_file_class('WP_SimplePie_File'); /* Tell SimplePie how long to cache the feed data in the WordPress database */ $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', get_option('reclaim_update_interval'), $rss_source)); /* Run any other functions or filters that WordPress normally runs on feeds */ do_action_ref_array('wp_feed_options', array(&$feed, $rss_source)); /* Initiate the SimplePie instance */ $feed->init(); /* Tell SimplePie to send the feed MIME headers */ $feed->handle_content_type(); if ($feed->error()) { parent::log(sprintf(__('no %s data', 'reclaim'), $this->shortname)); parent::log($feed->error()); } else { $data = self::map_data($feed); 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 ajax_resync_items() { $offset = intval($_POST['offset']); $limit = intval($_POST['limit']); $count = intval($_POST['count']); $next_url = isset($_POST['next_url']) ? $_POST['next_url'] : ''; self::log($this->shortName() . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); if (get_option('vine_user_id')) { $page = $offset / self::$count + 1; $key = self::vineAuth(get_option('vine_user_id'), get_option('vine_password')); $userId = strtok($key, '-'); $rawData = self::vineTimeline($userId, $key, $page); //parent::log(print_r($rawData,1)); if (is_array($rawData)) { $data = self::map_data($rawData); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $next_url); $return['success'] = true; } else { $return['error'] = sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname); } } else { $return['error'] = sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname); } echo json_encode($return); die; }
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('youtube_username')) { if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { if ($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'), self::$count), self::$timeout); } } $rawData = json_decode($rawData, true); if (is_array($rawData)) { $data = self::map_data($rawData, $type); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_' . $type . '_last_update', current_time('timestamp')); $new_next_url = null; foreach ($rawData['feed']['link'] as $link) { if ($link['rel'] == 'next') { $new_next_url = $link['href']; } } if (!isset($new_next_url)) { //$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 { // youtube returns next_url without the api key - which we need to get // activity. so lets add it, if we have it $google_api_key = get_option('google_api_key'); $new_next_url .= isset($google_api_key) ? '&key=' . $google_api_key : ''; $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $new_next_url); } $return['success'] = true; } 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 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 ajax_resync_items() { $offset = intval($_POST['offset']); $limit = intval($_POST['limit']); $count = intval($_POST['count']); $next_url = isset($_POST['next_url']) ? $_POST['next_url'] : ''; self::log($this->shortName() . ' ' . $type . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); $user_name = get_option('twitpic_user_name'); if (isset($user_name)) { if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { $rawData = parent::import_via_curl(sprintf(self::$apiurl, $user_name, 1), self::$timeout); } $rawData = json_decode($rawData, true); if ($rawData) { $data = self::map_data($rawData); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); parent::log(sprintf(__('END %s posts import', 'reclaim'), $this->shortname)); $newoffset = $offset + sizeof($data); $page = floor($newoffset / self::$count) + 1; $next_url = sprintf(self::$apiurl, $user_name, $page); $return['result'] = array('offset' => $newoffset, 'next_url' => $next_url); $return['success'] = true; } else { $return['error'] = sprintf(__('%s %s returned no data. No import was done', 'reclaim'), $this->shortname, $type); } } else { $return['error'] = sprintf(__('%s %s user data missing. No import was done', 'reclaim'), $this->shortname, $type); } echo json_encode($return); die; }
public function ajax_resync_items() { // the type comes magically back from the // data-resync="{type:'favs'}" - attribute of the submit-button. // favs not implemented yet $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'] : ''; $user_id = get_option('flickr_user_id'); $app_key = get_option('flickr_api_key'); self::log($this->shortName() . ' ' . $type . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); if (isset($user_id) && isset($app_key)) { if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { //$apiurl_ = ($type == 'posts' ? self::$apiurl : self::$fav_apiurl); $rawData = parent::import_via_curl(sprintf(self::$apiurl, $user_id, self::$count, 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); if ($rawData['stat'] == "ok" && is_array($rawData)) { // xxx $data = self::map_api_data($rawData); //$data = self::map_data($rawData, $type); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); //update_option('reclaim_'.$this->shortname.'_'.$type.'_last_update', current_time('timestamp')); $newoffset = $offset + sizeof($data); $page = floor($newoffset / self::$count) + 1; $next_url = sprintf(self::$apiurl, $user_id, self::$count, $page, $app_key); $return['result'] = array('offset' => $newoffset, 'next_url' => $next_url); $return['success'] = true; } elseif ($rawdata['stat'] != "ok") { $return['error'] = $rawData['message'] . " (Error code " . $rawData['code'] . ")"; } else { $return['error'] = sprintf(__('%s %s returned no data. No import was done', 'reclaim'), $this->shortname, $type); } } else { $return['error'] = sprintf(__('%s %s user data missing. No import was done', 'reclaim'), $this->shortname, $type); } echo json_encode($return); die; }
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 ajax_resync_items() { // the type comes magically back from the // data-resync="{type:'favs'}" - attribute of the submit-button. $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'] : ''; self::log($this->shortName() . ' ' . $type . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); if (get_option('instagram_user_id') && get_option('instagram_access_token')) { if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { $apiurl_ = $type == 'posts' ? self::$apiurl : self::$fav_apiurl; $rawData = parent::import_via_curl(sprintf($apiurl_, get_option('instagram_user_id'), get_option('instagram_access_token'), self::$count), self::$timeout); } $rawData = json_decode($rawData, true); if ($rawData['meta']['code'] == 200) { $data = self::map_data($rawData, $type); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_' . $type . '_last_update', current_time('timestamp')); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); if (!isset($rawData['pagination']['next_url'])) { //$return['error'] = sprintf(__('%s %s import done.', 'reclaim'), $type, $this->shortname); $return['result'] = array('offset' => $offset + sizeof($data), 'count' => $offset + sizeof($data), 'next_url' => $rawData['pagination']['next_url']); } else { $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $rawData['pagination']['next_url']); } $return['success'] = true; } elseif (isset($rawdata['meta']['code']) != 200) { $return['error'] = $rawData['meta']['error_message'] . " (Error code " . $rawData['meta']['code'] . ")"; } else { $return['error'] = sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname); } } else { $return['error'] = sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname); } echo json_encode($return); die; }
public function ajax_resync_items() { $offset = intval($_POST['offset']); $limit = intval($_POST['limit']); $count = intval($_POST['count']); $next_url = isset($_POST['next_url']) ? $_POST['next_url'] : ''; self::log($this->shortName() . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); if (get_option('moves_user_id') && get_option('moves_access_token')) { $month = date("Ym", round(time() - $offset * (60 * 60 * 24))); if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { // offset = days synced, substracting that point to month to be synced // at first run: 0 parent::log("month: " . $month); $rawData = parent::import_via_curl(sprintf(self::$apiurl_month, $month, get_option('moves_access_token')), self::$timeout); } $rawData = json_decode($rawData, true); if ($rawData) { $data = self::map_data($rawData); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); // calculate next url $new_offset = $offset + sizeof($data); $month = date("Ym", round(strtotime($month) - $new_offset * (60 * 60 * 24))); parent::log("strtotime(month): " . strtotime($month) . " month: " . $month . " new_offset: " . $new_offset); $next_url = sprintf(self::$apiurl_month, $month, get_option('moves_access_token')); $return['result'] = array('offset' => $new_offset, 'next_url' => $next_url); $return['success'] = true; } else { $return['error'] = sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname); } } else { $return['error'] = sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname); } echo json_encode($return); die; }
private function import_tweets($apiurl_, $reqOptions, $type = "posts", $offset = 0) { if (!isset($reqOptions)) { } // set standard $tmhOAuth = new tmhOAuth(array('consumer_key' => get_option('twitter_consumer_key'), 'consumer_secret' => get_option('twitter_consumer_secret'), 'user_token' => get_option('twitter_user_token'), 'user_secret' => get_option('twitter_user_secret'))); $tmhOAuth->request('GET', $apiurl_, $reqOptions, true); if ($tmhOAuth->response['code'] == 200) { $data = self::map_data(json_decode($tmhOAuth->response['response'], true), $type); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_' . $type . '_last_update', current_time('timestamp')); if ($offset == 0) { // store the last-seen-id, which is the first message of the first request update_option('reclaim_' . $this->shortname . '_' . $type . '_last_seen_id', $data[0]["ext_guid"]); } $reqOk = count($data) > 0 && $data[count($data) - 1]["ext_guid"] != $reqOptions['max_id']; $lastid = $data[count($data) - 1]["ext_guid"]; $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $lastid, 'reqOk' => $reqOk); $return['success'] = $reqOk; } elseif ($tmhOAuth->response['code'] != 200) { //&& $offset != 0 /* $return['result'] = array( // when we're done, tell ajax script the number of imported items // and that we're done (offset == count) 'offset' => $offset, 'count' => $offset , 'next_url' => $lastid, ); */ $errors = json_decode($tmhOAuth->response['response'], true); $return['error'] = $errors['errors'][0]['message'] . " (Error code " . $errors['errors'][0]['code'] . ")"; } else { $return['error'] = sprintf(__('%s %s returned no data. No import was done', 'reclaim'), $this->shortname, $type); } return $return; }
public function ajax_resync_items() { $offset = intval($_POST['offset']); $limit = intval($_POST['limit']); $count = intval($_POST['count']); self::log($this->shortName() . ' resync ' . $offset . '-' . ($offset + $limit) . ':' . $count); $return = array('success' => false, 'error' => '', 'result' => null); if (get_option('foursquare_user_id') && get_option('foursquare_access_token')) { $rawData = parent::import_via_curl(sprintf(self::$apiurl, $offset, $limit, get_option('foursquare_access_token')), self::$timeout); $rawData = json_decode($rawData, true); if ($rawData) { $data = $this->map_data($rawData); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); $return['result'] = array('offset' => $offset + sizeof($data)); $return['success'] = true; } else { $return['error'] = sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname); } } else { $return['error'] = sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname); } echo json_encode($return); die; }