function privatesquare_export_massage_checkin(&$row, $more = array()) { $status_map = privatesquare_checkins_status_map(); $row['status_name'] = $status_map[$row['status_id']]; # prefix keys with machinetag namespaces? if (isset($row['venue'])) { $row['venue_name'] = $row['venue']['name']; unset($row['venue']); } if ($row['locality']) { $loc = reverse_geoplanet_get_by_woeid($row['locality'], 'locality'); $row['locality_name'] = $loc['name']; } if (isset($row['weather']) && isset($more['inflate_weather'])) { if ($data = json_decode($row['weather'], 'as hash')) { foreach ($data as $k => $v) { $row["weather_{$k}"] = $v; } } unset($row['weather']); } # note the pass-by-ref }
if ($page = get_int32("page")) { $more['page'] = $page; } if ($when = get_str("when")) { $more['when'] = $when; $history_url .= urlencode($when) . "/"; # TO DO: find some better heuristic for this number # besides "pull it out of my ass" (20120206/straup) $more['per_page'] = 100; } $more['inflate_locality'] = 1; $rsp = privatesquare_checkins_for_user($owner, $more); # TO DO: oh god...timezones :-( if ($when) { list($start, $stop) = datetime_when_parse($more['when']); $GLOBALS['smarty']->assign("when", $when); $GLOBALS['smarty']->assign("start", $start); $GLOBALS['smarty']->assign("stop", $stop); } $status_map = privatesquare_checkins_status_map(); $GLOBALS['smarty']->assign_by_ref("status_map", $status_map); $GLOBALS['smarty']->assign("pagination_url", $GLOBALS['cfg']['abs_root_url'] . $history_url); $GLOBALS['smarty']->assign_by_ref("owner", $owner); $GLOBALS['smarty']->assign_by_ref("is_own", $is_own); $export_formats = privatesquare_export_valid_formats(); $GLOBALS['smarty']->assign("export_formats", array_keys($export_formats)); $geo_stats = privatesquare_checkins_utils_geo_stats($rsp['rows']); $GLOBALS['smarty']->assign_by_ref("geo_stats", $geo_stats); $GLOBALS['smarty']->assign_by_ref("checkins", $rsp['rows']); $GLOBALS['smarty']->display("page_user_history.txt"); exit;
function sync_user($fsq_user, $more = array()) { $user = users_get_by_id($fsq_user['user_id']); if (!$user['sync_foursquare']) { echo "'{$user['username']}' has not opted in to foursquare syncing, skipping...\n"; return; } echo "sync checkins for '{$user['username']}' : {$user['sync_foursquare']}\n"; $status_map = privatesquare_checkins_status_map("string keys"); $method = 'users/self/checkins'; $count = null; $offset = 0; $limit = 250; while (!isset($count) || $offset < $count) { $args = array('oauth_token' => $fsq_user['oauth_token'], 'limit' => $limit, 'offset' => $offset); # only sync updates since the user signed up for privatesquare # > 1 (or "2") would mean pull in all a users' checkins. # see also: account_foursquare_sync.php if ($user['sync_foursquare'] == 1) { $args['afterTimestamp'] = $user['created']; } $rsp = foursquare_api_call($method, $args); if (!isset($count)) { $count = $rsp['rsp']['checkins']['count']; } $count_items = count($rsp['rsp']['checkins']['items']); # As of 20120218 if you pass a date filter to the API it # still returns the count for the total number of checkins # without the date filter. I love that... (20120218/straup) if (!$count_items) { break; } foreach ($rsp['rsp']['checkins']['items'] as $fsq_checkin) { if (privatesquare_checkins_get_by_foursquare_id($user, $fsq_checkin['id'])) { continue; } $checkin = array('user_id' => $user['id'], 'checkin_id' => $fsq_checkin['id'], 'venue_id' => $fsq_checkin['venue']['id'], 'created' => $fsq_checkin['createdAt'], 'status_id' => $status_map['i am here'], 'latitude' => $fsq_checkin['location']['lat'], 'longitude' => $fsq_checkin['location']['lng']); $venue = foursquare_venues_get_by_venue_id($checkin['venue_id']); if (!$venue) { $rsp = foursquare_venues_archive_venue($checkin['venue_id']); if (!$rsp['ok']) { echo "failed to archive venue '{$checkin['venue_id']}' : {$rsp['error']}\n"; echo "skipping...\n"; continue; } $venue = $rsp['venue']; } if ($venue) { $checkin['locality'] = $venue['locality']; $checkin['latitude'] = $venue['latitude']; $checkin['longitude'] = $venue['longitude']; } $rsp = privatesquare_checkins_create($checkin); if (!$rsp['ok']) { echo "failed to archive checkin: {$rsp['error']}\n"; continue; } echo "archived 4sq checkin {$checkin['checkin_id']} with privatesquare ID: {$rsp['checkin']['id']}\n"; } # do stuff here... $offset += $limit; } }