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)); } }
private function map_data($rawData, $type = "posts") { $data = array(); $tags = array(); foreach ($rawData as $entry) { if (!$entry["public"]) { continue; } if ($entry["type"] != "PushEvent") { continue; } $post_format = 'status'; $content = self::construct_content($entry); $tags = self::get_hashtags($entry); $post_meta["_" . $this->shortname . "_link_id"] = $entry["id"]; $post_meta["_post_generator"] = $this->shortname; $post_meta["_reclaim_post_type"] = $type; // http://codex.wordpress.org/Function_Reference/wp_insert_post $data[] = array('post_author' => get_option($this->shortname . '_author'), 'post_category' => array(get_option($this->shortname . '_category')), 'post_date' => get_date_from_gmt(date('Y-m-d H:i:s', strtotime($entry["created_at"]))), 'post_format' => $post_format, 'post_content' => $content['content'], 'post_title' => strip_tags($content['title']), 'post_type' => 'post', 'post_status' => 'publish', 'tags_input' => $tags, 'ext_permalink' => $content['url'], 'ext_guid' => $entry["id"], 'post_meta' => $post_meta); parent::log(sprintf(__('%s posted new status: %s on %s', 'reclaim'), $this->shortname, $content["title"], $data[count($data) - 1]["post_date"])); } return $data; }
private function vineTimeline($userId, $key, $page = 1) { // Additional endpoints available from https://github.com/starlock/vino/wiki/API-Reference // old setting // $url = 'https://api.vineapp.com/timelines/users/'.$userId.'?size='.self::$count; // new setting from vine.co/username -> if x-vine-client: vinewww/1.0, response // includes revines $url = 'https://vine.co/api/timelines/users/' . $userId . '?page=' . $page . '&size=' . self::$count; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, 'https://vine.co/felix.schwenzel'); //curl_setopt($ch, CURLOPT_USERAGENT, "iphone/110 (iPhone; iOS 7.0.4; Scale/2.00)"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('vine-session-id: ' . $key, "x-vine-client: vinewww/1.0", "X-Requested-With: XMLHttpRequest", "Cache-Control: max-age=0", "DNT: 1")); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = json_decode(curl_exec($ch), true); curl_close($ch); if (!$result) { parent::log('curl error: ' . curl_error($ch)); } else { return $result['data']; } }
public function import($forceResync) { if (get_option('youtube_username')) { $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('youtube_username'), self::$count), self::$timeout); $rawData = json_decode($rawData, true); if (is_array($rawData)) { $data = self::map_data($rawData, 'posts'); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_videos_last_update', current_time('timestamp')); } else { parent::log(sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname)); } if (get_option('youtube_import_favs')) { $rawData = parent::import_via_curl(sprintf(self::$fav_apiurl, get_option('youtube_username'), self::$count), self::$timeout); $rawData = json_decode($rawData, true); if (is_array($rawData)) { $data = self::map_data($rawData, 'favs'); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_favs_last_update', current_time('timestamp')); } else { parent::log(sprintf(__('%s favs returned no data. No import was done', 'reclaim'), $this->shortname)); } } if (get_option('youtube_import_activity') && get_option('google_api_key')) { $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, 'activity'); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_activity_last_update', current_time('timestamp')); } else { parent::log(sprintf(__('%s activity returned no data. No import was done', 'reclaim'), $this->shortname)); } } } else { parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname)); } }
public function import($forceResync) { if (!get_option('facebook_oauth_token') && get_option('facebook_app_id') && get_option('facebook_app_secret')) { parent::log(sprintf(__('getting FB token', 'reclaim'), $this->shortname)); } if (get_option('facebook_username') && get_option('facebook_user_id') && get_option('facebook_oauth_token')) { $lastupdate = get_option('reclaim_' . $this->shortname . '_last_update'); $urlNext = sprintf(self::$apiurl, get_option('facebook_user_id'), self::$count, substr(get_bloginfo('language'), 0, 2), get_option('facebook_oauth_token')); if (strlen($lastupdate) > 0 && !$forceResync) { $urlNext .= "&since=" . $lastupdate; } // get GMT time. thats what we need, not local time $newlastupdate = current_time('timestamp', 1); $errors = 0; $i = 0; while (strlen($urlNext) > 0) { $rawData = parent::import_via_curl($urlNext, self::$timeout); if ($rawData) { $errors = 0; $rawData = json_decode($rawData, true); if (isset($rawData["paging"]["next"])) { $urlNext = $rawData["paging"]["next"]; } else { $urlNext = ""; } $data = self::map_data($rawData); parent::insert_posts($data); if (!$forceResync && count($data) > 0 && intval($rawData['data'][count($rawData['data']) - 1]["created_time"]) < intval($lastupdate) || $i > self::$max_import_loops) { // abort requests if we've already seen these events $urlNext = ""; } } else { // throw exception or end? if (++$errors == 3) { parent::log(sprintf(__('%s ended with an error. Aborted getting %s', 'reclaim'), $this->shortname, $urlNext)); return; } parent::log(sprintf(__('%s ended with an error. Continue anyway with %s', 'reclaim'), $this->shortname, $urlNext)); } $i++; } update_option('reclaim_' . $this->shortname . '_last_update', $newlastupdate); } 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() . ' ' . $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 import($forceResync) { $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::$feedurl, get_option('flickr_user_id'), self::$lang), self::$timeout); // http://stackoverflow.com/questions/2752439/decode-json-string-returned-from-flickr-api-using-php-curl $rawData = str_replace('jsonFlickrFeed(', '', $rawData); $rawData = substr($rawData, 0, strlen($rawData) - 1); //strip out last paren $rawData = json_decode($rawData, true); if (is_array($rawData)) { $data = self::map_data($rawData); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); } else { parent::log(sprintf(__('no %s data', 'reclaim'), $this->shortname)); } } elseif (isset($user_id) && isset($app_key)) { $i = 0; // todo: loop through pages to get all images... $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('flickr_user_id'), self::$count, $i + 1, get_option('flickr_api_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 (is_array($rawData)) { $data = self::map_api_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 import($forceResync) { if (get_option('instagram_user_id') && get_option('instagram_access_token')) { //get instagrams $rawData = parent::import_via_curl(sprintf(self::$apiurl, get_option('instagram_user_id'), get_option('instagram_access_token'), self::$count), self::$timeout); $rawData = json_decode($rawData, true); if ($rawData) { $data = self::map_data($rawData, 'posts'); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_posts_last_update', current_time('timestamp')); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); parent::log(sprintf(__('END %s posts import', 'reclaim'), $this->shortname)); } else { parent::log(sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname)); } if (get_option('instagram_import_favs')) { //get favs $rawData = parent::import_via_curl(sprintf(self::$fav_apiurl, 'user', get_option('instagram_access_token'), self::$count), self::$timeout); $rawData = json_decode($rawData, true); if ($rawData) { $data = self::map_data($rawData, 'favs'); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_favs_last_update', current_time('timestamp')); update_option('reclaim_' . $this->shortname . '_last_update', current_time('timestamp')); parent::log(sprintf(__('END %s favs import', 'reclaim'), $this->shortname)); } else { parent::log(sprintf(__('%s favs returned no data. No import was done', 'reclaim'), $this->shortname)); } } } else { parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname)); } }
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() { $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; }
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); // todo: synchronize secondary blogs $return = array('success' => false, 'error' => '', 'result' => null); if (get_option('tumblr_user_id') && get_option('tumblr_access_token')) { $apiurl_ = $type == 'posts' ? self::$apiurl : self::$fav_apiurl; if ($next_url != '') { $rawData = parent::import_via_curl($next_url, self::$timeout); } else { $rawData = parent::import_via_curl(sprintf($apiurl_, get_option('tumblr_user_name') . '.tumblr.com', get_option('tumblr_client_id'), self::$count), self::$timeout); } $rawData = json_decode($rawData, true); parent::log(print_r($rawData, true)); if ($rawData['meta']['status'] == 200) { $data = self::map_data($rawData['response'], $type); parent::insert_posts($data); update_option('reclaim_' . $this->shortname . '_' . $type . '_last_update', current_time('timestamp')); $next_url = sprintf($apiurl_, get_option('tumblr_user_name') . '.tumblr.com', get_option('tumblr_client_id'), self::$count) . '&offset=' . ($offset + sizeof($data)); $return['result'] = array('offset' => $offset + sizeof($data), 'next_url' => $next_url); $return['success'] = true; } elseif (isset($rawdata['meta']['status']) != 200) { $return['error'] = $rawData['meta']['msg'] . " (Error code " . $rawData['meta']['status'] . ")"; } 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 filter_item($entry) { // first, lets get an array of all actice mods $needles = reclaim_core::modNameList(); // we don't want twitter to filter itself if (($key = array_search('twitter', $needles)) !== false) { unset($needles[$key]); } // and now lets check if the tweet source matches any of the mod names // this should filter out instagram, yelp, youtube, etc. if (parent::strpos_array($entry['source'], $needles)) { parent::log('filtered a tweet because of this source: ' . $entry['source']); return true; } else { return false; } }
public function import() { if (get_option('foursquare_user_id') && get_option('foursquare_access_token')) { $rawData = parent::import_via_curl(sprintf(self::$apiurl, 0, self::$count, 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')); } else { parent::log(sprintf(__('%s returned no data. No import was done', 'reclaim'), $this->shortname)); } } else { parent::log(sprintf(__('%s user data missing. No import was done', 'reclaim'), $this->shortname)); } }
private function get_yelp_description($url, $id) { $args = array('timeout' => $timeout, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . get_bloginfo('version') . '; ' . get_bloginfo('url'), 'blocking' => true, 'headers' => array('Accept-Language' => 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4'), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'stream' => false, 'filename' => null); $response = wp_remote_get($url, $args); if (is_wp_error($response)) { parent::log('error while loading ' . $url . ': ' . $response->get_error_message()); return false; } $body = trim($response['body']); $html = new simple_html_dom(); $html->load($body); // http://www.yelp.com/biz/salon-graf-frisiersalon-berlin#hrid:C2JflaCF8jja2a5PHr7iHQ // this won't show us the review with our hrid, so lets only get the biz id // // <meta name="yelp-biz-id" content="KP_8I0zN9s50fWWf-S6mgg"> $bizID = $html->find('meta[name="yelp-biz-id"]', 0)->content; // on this page will get our review for sure // so lets construct the url $sendToFriendPage = 'http://www.yelp.com/biz_share?bizid=' . $bizID . '&return_url=foo&reviewid=' . $id; // and get the page $response = wp_remote_get($sendToFriendPage, $args); if (is_wp_error($response)) { parent::log('error while loading ' . $sendToFriendPage . ': ' . $response->get_error_message()); return false; } $body = trim($response['body']); $html = new simple_html_dom(); $html->load($body); // fix relative yelp urls // (<a href="/redir?url=http%3A%2F%2Flandbrot.de&s=3bfa424ca015c75831beb8ebe85fadd0eb9f19ff676338045a36d1fd9a8399e7" target="_blank" rel="nofollow">landbrot.de</a>) // http://stackoverflow.com/questions/4784243/how-do-i-extract-query-parameters-from-an-url-string-in-php foreach ($html->find('a') as $link) { $query = parse_url('http://www.yelp.com' . $link->href, PHP_URL_QUERY); parse_str($query, $params); $link->href = urldecode($params['url']); //$link->href = 'http://www.yelp.com' . $link->href; } // now get our review $ret = $html->find('div[id=biz_review]', 0)->innertext; return $ret; }