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 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 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 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()
 {
     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;
     }
 }
 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 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;
     }
 }
Пример #14
0
 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&amp;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;
 }